sec-edgar-api 0.2.4 → 0.3.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.
Files changed (35) hide show
  1. package/README.md +1 -0
  2. package/build/services/ReportParser/ReportParser.d.ts +6 -13
  3. package/build/services/ReportParser/ReportParser.js +15 -22
  4. package/build/services/ReportRawBuilder/FactGrouper.d.ts +27 -0
  5. package/build/services/ReportRawBuilder/FactGrouper.js +206 -0
  6. package/build/services/{ReportBuilder → ReportRawBuilder}/FactPeriodResolver.d.ts +46 -2
  7. package/build/services/{ReportBuilder → ReportRawBuilder}/FactPeriodResolver.js +81 -20
  8. package/build/services/ReportRawBuilder/FactRecordBuilder.d.ts +9 -0
  9. package/build/services/{ReportBuilder → ReportRawBuilder}/FactRecordBuilder.js +6 -24
  10. package/build/services/ReportRawBuilder/FactSplitAdjuster.d.ts +43 -0
  11. package/build/services/ReportRawBuilder/FactSplitAdjuster.js +242 -0
  12. package/build/services/ReportRawBuilder/ReportRawBuilder.d.ts +39 -0
  13. package/build/services/ReportRawBuilder/ReportRawBuilder.js +158 -0
  14. package/build/services/ReportRawBuilder/index.d.ts +2 -0
  15. package/build/services/ReportRawBuilder/index.js +4 -0
  16. package/build/services/SecEdgarApi/SecEdgarApi.d.ts +10 -2
  17. package/build/services/SecEdgarApi/SecEdgarApi.js +29 -11
  18. package/build/types/common.type.d.ts +41 -0
  19. package/build/types/company-facts.type.d.ts +29 -2
  20. package/package.json +1 -1
  21. package/build/services/ReportBuilder/FactRecordBuilder.d.ts +0 -10
  22. package/build/services/ReportBuilder/FactSplitAdjuster.d.ts +0 -50
  23. package/build/services/ReportBuilder/FactSplitAdjuster.js +0 -214
  24. package/build/services/ReportBuilder/ReportBuilder.d.ts +0 -40
  25. package/build/services/ReportBuilder/ReportBuilder.js +0 -200
  26. package/build/services/ReportBuilder/ReportRawResolvable.d.ts +0 -17
  27. package/build/services/ReportBuilder/ReportRawResolvable.js +0 -114
  28. package/build/services/ReportBuilder/index.d.ts +0 -2
  29. package/build/services/ReportBuilder/index.js +0 -4
  30. package/build/services/ReportParser/ReportRawParser.d.ts +0 -5
  31. package/build/services/ReportParser/ReportRawParser.js +0 -14
  32. package/build/util/calculation-map-by-ns.d.ts +0 -6
  33. package/build/util/calculation-map-by-ns.js +0 -9
  34. /package/build/services/{ReportBuilder → ReportRawBuilder}/FactFiscalCalculator.d.ts +0 -0
  35. /package/build/services/{ReportBuilder → ReportRawBuilder}/FactFiscalCalculator.js +0 -0
@@ -1,3 +1,4 @@
1
+ import { FactItem } from './company-facts.type';
1
2
  export interface XMLParams {
2
3
  xml: string;
3
4
  }
@@ -10,3 +11,43 @@ export interface FieldDataResponse<Field extends string = string> {
10
11
  fields: Field[];
11
12
  data: (string | number)[][];
12
13
  }
14
+ export interface SplitData {
15
+ filedFirst: string;
16
+ filedLast: string;
17
+ endFirst: string;
18
+ endLast: string;
19
+ splitRatio: number;
20
+ }
21
+ export interface FactGroup {
22
+ name: string;
23
+ unit: string;
24
+ accn: string;
25
+ reportEnd: string;
26
+ reportFiled: string;
27
+ isResolverGenerated: boolean;
28
+ filedFirst: string;
29
+ filedLast: string;
30
+ endFirst: string;
31
+ endLast: string;
32
+ values: number[];
33
+ fiscalYear: number;
34
+ quarter: number;
35
+ facts: FactItem[];
36
+ valueSplitAdjustedPeriod: number | null;
37
+ valueSplitAdjustedTrailing: number | null;
38
+ valuePeriodResolved: number | null;
39
+ valueTrailingResolved: number | null;
40
+ valuePeriodFirst: number | null;
41
+ valuePeriodLast: number | null;
42
+ valueTrailingFirst: number | null;
43
+ valueTrailingLast: number | null;
44
+ }
45
+ export interface FactItemExtended extends FactItem {
46
+ period: number;
47
+ year: number;
48
+ quarter: number;
49
+ periodValue: number | null;
50
+ trailingValue: number | null;
51
+ splitValue: number | null;
52
+ splitsApplied: number[];
53
+ }
@@ -1,3 +1,4 @@
1
+ import { FiscalPeriod } from './report-raw.type';
1
2
  export interface CompanyFactListData {
2
3
  cik: number;
3
4
  entityName: string;
@@ -6,11 +7,12 @@ export interface CompanyFactListData {
6
7
  export interface CompanyFactList {
7
8
  dei: Record<string, CompanyFact>;
8
9
  invest?: Record<string, CompanyFact>;
10
+ srt?: Record<string, CompanyFact>;
9
11
  'us-gaap'?: Record<string, CompanyFact>;
10
12
  }
11
13
  export interface CompanyFact {
12
- label: string;
13
- description: string;
14
+ label: string | null;
15
+ description: string | null;
14
16
  units: Record<string, FactValue[]>;
15
17
  }
16
18
  export interface FactValue {
@@ -51,3 +53,28 @@ export interface MultiCompanyFactFrame {
51
53
  pts: number;
52
54
  data: MultiCompanyFactFrameItem[];
53
55
  }
56
+ export interface FactItem {
57
+ cik: number | string;
58
+ end: string;
59
+ filed: string;
60
+ name: string;
61
+ unit: string;
62
+ value: number | string;
63
+ start?: string;
64
+ hasSegments?: boolean;
65
+ accn?: string;
66
+ form?: string;
67
+ fp?: string;
68
+ frame?: string;
69
+ fy?: number;
70
+ /** For XBRL reports only */
71
+ segments?: {
72
+ value: string;
73
+ dimension: string;
74
+ }[];
75
+ uuid?: string;
76
+ }
77
+ export interface FactItemWithFiscals extends FactItem {
78
+ fiscalPeriod: FiscalPeriod;
79
+ year: number;
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sec-edgar-api",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "Fetch and parse SEC earnings reports and other filings. Useful for financial analysis.",
5
5
  "main": "build/index.js",
6
6
  "author": "Andrew Evers (https://github.com/andyevers)",
@@ -1,10 +0,0 @@
1
- import { FactItem } from './ReportBuilder';
2
- import { CompanyFactListData } from '../../types';
3
- /**
4
- * Builds an array of fact records.
5
- */
6
- export default class FactRecordBuilder {
7
- createFacts(data: CompanyFactListData, filterDuplicates?: boolean): {
8
- facts: FactItem[];
9
- };
10
- }
@@ -1,50 +0,0 @@
1
- import { FiscalPeriod } from '../../types/report-raw.type';
2
- import { FactItemWithFiscals } from './ReportBuilder';
3
- interface SplitData {
4
- end: string;
5
- filed: string;
6
- value: number;
7
- firstFiled: string;
8
- fiscalYear: number;
9
- fiscalPeriod: FiscalPeriod;
10
- }
11
- type FactItemWithFiscalsNumeric = Omit<FactItemWithFiscals, 'cik' | 'value'> & {
12
- value: number;
13
- };
14
- /**
15
- * Adjust share-based property values for splits. Checks where the split was applied,
16
- * and adjusts all previously filed share facts accordingly.
17
- */
18
- export default class FactSplitAdjuster {
19
- private readonly splitKey;
20
- private readonly splitByFiscalYearAmount;
21
- private readonly factsByYearQuarterByPropertyName;
22
- private readonly factsAnnaulByYearByPropertyName;
23
- private readonly resolvedProperties;
24
- private sortedSplits;
25
- private getMap;
26
- private filedFirstLastBySplitKey;
27
- add(fact: FactItemWithFiscalsNumeric & {
28
- filedLast?: string;
29
- }): void;
30
- getSplitsAsc(): SplitData[];
31
- isSplitProperty(propertyName: string): boolean;
32
- addSplitData(data: Omit<SplitData, 'firstFiled'>): void;
33
- /**
34
- * TODO: Find a more reliable way of checking if the split has already been applied.
35
- */
36
- private didApplySplit;
37
- isSplitAdjustableUnit(unit: string): boolean;
38
- isShareRatioUnit(unit: string): boolean;
39
- private getSortedFacts;
40
- resolveProperty(propertyName: string): void;
41
- get(propertyName: string, year: number, fiscalPeriod: FiscalPeriod): number | undefined;
42
- forEach(callback: (params: {
43
- propertyName: string;
44
- year: number;
45
- fiscalPeriod: FiscalPeriod;
46
- value: number;
47
- }) => void): void;
48
- private adjustValuesForSplits;
49
- }
50
- export {};
@@ -1,214 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
14
- /**
15
- * Adjust share-based property values for splits. Checks where the split was applied,
16
- * and adjusts all previously filed share facts accordingly.
17
- */
18
- var FactSplitAdjuster = /** @class */ (function () {
19
- function FactSplitAdjuster() {
20
- this.splitKey = 'StockholdersEquityNoteStockSplitConversionRatio1';
21
- this.splitByFiscalYearAmount = new Map();
22
- this.factsByYearQuarterByPropertyName = new Map();
23
- this.factsAnnaulByYearByPropertyName = new Map();
24
- this.resolvedProperties = new Set();
25
- this.sortedSplits = null;
26
- this.filedFirstLastBySplitKey = new Map();
27
- }
28
- FactSplitAdjuster.prototype.getMap = function (map, propertyName) {
29
- var _a;
30
- return (_a = map.get(propertyName)) !== null && _a !== void 0 ? _a : map.set(propertyName, new Map()).get(propertyName);
31
- };
32
- FactSplitAdjuster.prototype.add = function (fact) {
33
- var _a;
34
- var propertyName = fact.name, year = fact.year, fiscalPeriod = fact.fiscalPeriod, unit = fact.unit, filed = fact.filed, value = fact.value, end = fact.end;
35
- if (this.isSplitProperty(propertyName)) {
36
- this.addSplitData({ end: end, filed: filed, fiscalYear: year, value: Number(value), fiscalPeriod: fiscalPeriod });
37
- return;
38
- }
39
- if (!this.isSplitAdjustableUnit(unit))
40
- return;
41
- if (this.resolvedProperties.has(propertyName)) {
42
- throw new Error("Property ".concat(propertyName, " has already been resolved"));
43
- }
44
- var isAnnual = fiscalPeriod === 'FY';
45
- var map = isAnnual
46
- ? this.getMap(this.factsAnnaulByYearByPropertyName, propertyName)
47
- : this.getMap(this.factsByYearQuarterByPropertyName, propertyName);
48
- var key = "".concat(year, "_").concat(fiscalPeriod);
49
- this.filedFirstLastBySplitKey.set(key, {
50
- firstFiled: filed,
51
- lastFiled: (_a = fact.filedLast) !== null && _a !== void 0 ? _a : filed,
52
- });
53
- map.set(key, fact);
54
- };
55
- FactSplitAdjuster.prototype.getSplitsAsc = function () {
56
- if (this.sortedSplits)
57
- return this.sortedSplits;
58
- var sortedSplits = Array.from(this.splitByFiscalYearAmount.values()).sort(function (a, b) {
59
- return a.filed < b.filed ? -1 : 1;
60
- });
61
- this.sortedSplits = sortedSplits;
62
- return sortedSplits;
63
- };
64
- FactSplitAdjuster.prototype.isSplitProperty = function (propertyName) {
65
- return propertyName === this.splitKey;
66
- };
67
- FactSplitAdjuster.prototype.addSplitData = function (data) {
68
- var end = data.end, filed = data.filed, fiscalYear = data.fiscalYear, value = data.value;
69
- var split = value;
70
- var key = "".concat(fiscalYear, "-").concat(split);
71
- var prevSplit = this.splitByFiscalYearAmount.get(key);
72
- if (!prevSplit) {
73
- this.splitByFiscalYearAmount.set(key, __assign(__assign({}, data), { firstFiled: filed }));
74
- this.sortedSplits = null;
75
- return;
76
- }
77
- var curEnd = end;
78
- var curFiled = filed;
79
- var prevEnd = prevSplit.end;
80
- var prevFiled = prevSplit.filed;
81
- var shouldUpdateFactItem = !prevSplit || prevEnd < curEnd || (prevEnd === curEnd && prevFiled > curFiled);
82
- var shouldUpdateFirstFiled = prevFiled > curFiled;
83
- if (shouldUpdateFactItem) {
84
- var curData = this.splitByFiscalYearAmount.get(key);
85
- curData.end = end;
86
- curData.filed = filed;
87
- curData.value = value;
88
- curData.fiscalYear = fiscalYear;
89
- this.sortedSplits = null;
90
- }
91
- if (shouldUpdateFirstFiled) {
92
- var curData = this.splitByFiscalYearAmount.get(key);
93
- curData.firstFiled = curFiled;
94
- this.sortedSplits = null;
95
- }
96
- };
97
- /**
98
- * TODO: Find a more reliable way of checking if the split has already been applied.
99
- */
100
- FactSplitAdjuster.prototype.didApplySplit = function (params) {
101
- var _a;
102
- var isShareRatio = params.isShareRatio, nextFact = params.nextFact, prevFact = params.prevFact, fact = params.fact, split = params.split;
103
- var _b = (_a = this.filedFirstLastBySplitKey.get("".concat(split.fiscalYear, "_").concat(split.fiscalPeriod))) !== null && _a !== void 0 ? _a : {}, firstFiled = _b.firstFiled, lastFiled = _b.lastFiled;
104
- if (fact.filed > lastFiled) {
105
- return true;
106
- }
107
- if (fact.filed < firstFiled) {
108
- return false;
109
- }
110
- var val = fact.value;
111
- var splitVal = split.value;
112
- var valWithSplit = isShareRatio ? splitVal * val : val / splitVal;
113
- if (nextFact) {
114
- var difference = Math.abs(nextFact.value - val);
115
- var differenceSplit = Math.abs(nextFact.value - valWithSplit);
116
- return difference < differenceSplit;
117
- }
118
- if (prevFact) {
119
- var difference = Math.abs(prevFact.value - val);
120
- var differenceSplit = Math.abs(prevFact.value - valWithSplit);
121
- return difference < differenceSplit;
122
- }
123
- return false;
124
- };
125
- FactSplitAdjuster.prototype.isSplitAdjustableUnit = function (unit) {
126
- return unit.toLowerCase().includes('share');
127
- };
128
- FactSplitAdjuster.prototype.isShareRatioUnit = function (unit) {
129
- var unitLower = unit.toLowerCase();
130
- return unitLower !== 'shares' && unitLower.includes('share'); // ex: USD/shares or USD-per-share
131
- };
132
- FactSplitAdjuster.prototype.getSortedFacts = function (propertyName, isAnnual) {
133
- var _a, _b, _c;
134
- var bucket = isAnnual ? this.factsAnnaulByYearByPropertyName : this.factsByYearQuarterByPropertyName;
135
- var facts = Array.from((_b = (_a = bucket.get(propertyName)) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : []);
136
- return (_c = facts.sort(function (a, b) { return (a.filed < b.filed ? -1 : 1); })) !== null && _c !== void 0 ? _c : [];
137
- };
138
- FactSplitAdjuster.prototype.resolveProperty = function (propertyName) {
139
- if (this.resolvedProperties.has(propertyName))
140
- return;
141
- var factsAscQuarter = this.getSortedFacts(propertyName, false);
142
- var factsAscAnnual = this.getSortedFacts(propertyName, true);
143
- this.adjustValuesForSplits({ facts: factsAscQuarter });
144
- this.adjustValuesForSplits({ facts: factsAscAnnual });
145
- this.resolvedProperties.add(propertyName);
146
- };
147
- FactSplitAdjuster.prototype.get = function (propertyName, year, fiscalPeriod) {
148
- var _a;
149
- this.resolveProperty(propertyName);
150
- var key = "".concat(year, "_").concat(fiscalPeriod);
151
- var isAnnual = fiscalPeriod === 'FY';
152
- var bucket = isAnnual ? this.factsAnnaulByYearByPropertyName : this.factsByYearQuarterByPropertyName;
153
- var fact = (_a = bucket.get(propertyName)) === null || _a === void 0 ? void 0 : _a.get(key);
154
- return fact === null || fact === void 0 ? void 0 : fact.value;
155
- };
156
- FactSplitAdjuster.prototype.forEach = function (callback) {
157
- var _this = this;
158
- this.factsByYearQuarterByPropertyName.forEach(function (factsByYearQuarter, propertyName) {
159
- _this.resolveProperty(propertyName);
160
- factsByYearQuarter.forEach(function (fact, key) {
161
- var _a = key.split('_'), year = _a[0], fiscalPeriod = _a[1];
162
- callback({ propertyName: propertyName, year: Number(year), fiscalPeriod: fiscalPeriod, value: Number(fact.value) });
163
- });
164
- });
165
- this.factsAnnaulByYearByPropertyName.forEach(function (factsByYear, propertyName) {
166
- _this.resolveProperty(propertyName);
167
- factsByYear.forEach(function (fact, key) {
168
- var _a = key.split('_'), year = _a[0], fiscalPeriod = _a[1];
169
- callback({ propertyName: propertyName, year: Number(year), fiscalPeriod: fiscalPeriod, value: Number(fact.value) });
170
- });
171
- });
172
- };
173
- FactSplitAdjuster.prototype.adjustValuesForSplits = function (params) {
174
- var _a, _b;
175
- var facts = params.facts;
176
- var splits = this.getSplitsAsc();
177
- if (facts.length === 0 || splits.length === 0)
178
- return;
179
- var isShareRatio = this.isShareRatioUnit(facts[0].unit);
180
- for (var splitIndex = splits.length - 1; splitIndex >= 0; splitIndex--) {
181
- var split = splits[splitIndex];
182
- for (var factIndex = facts.length - 1; factIndex >= 0; factIndex--) {
183
- var fact = facts[factIndex];
184
- var value = fact.value, filed = fact.filed;
185
- var nextFact = (_a = facts[factIndex + 1]) !== null && _a !== void 0 ? _a : null;
186
- var prevFact = (_b = facts[factIndex - 1]) !== null && _b !== void 0 ? _b : null;
187
- // const nextValue = facts[factIndex + 1]?.value ?? null
188
- // const prevValue = facts[factIndex - 1]?.value ?? null
189
- var didApplySplit = this.didApplySplit({
190
- // filed,
191
- isShareRatio: isShareRatio,
192
- // nextValue,
193
- // prevValue,
194
- fact: fact,
195
- nextFact: nextFact,
196
- prevFact: prevFact,
197
- split: split,
198
- // value,
199
- });
200
- if (didApplySplit || !split.value) {
201
- continue;
202
- }
203
- if (isShareRatio) {
204
- fact.value /= split.value;
205
- }
206
- else {
207
- fact.value *= split.value;
208
- }
209
- }
210
- }
211
- };
212
- return FactSplitAdjuster;
213
- }());
214
- exports.default = FactSplitAdjuster;
@@ -1,40 +0,0 @@
1
- import { CompanyFactListData, FiscalPeriod, ReportRaw } from '../../types';
2
- import { SetReportDatesParams } from './FactFiscalCalculator';
3
- export interface FactItem {
4
- cik: number | string;
5
- end: string;
6
- filed: string;
7
- name: string;
8
- unit: string;
9
- value: number | string;
10
- start?: string;
11
- hasSegments?: boolean;
12
- accn?: string;
13
- form?: string;
14
- fp?: string;
15
- frame?: string;
16
- fy?: number;
17
- /** For XBRL reports only */
18
- segments?: {
19
- value: string;
20
- dimension: string;
21
- }[];
22
- uuid?: string;
23
- }
24
- export interface FactItemWithFiscals extends FactItem {
25
- fiscalPeriod: FiscalPeriod;
26
- year: number;
27
- }
28
- /**
29
- * Builds ReportRaw objects from facts. also applies splits and adjusts for fiscal periods.
30
- */
31
- export default class ReportBuilder {
32
- private readonly factRecordBuilder;
33
- createFacts(companyFacts: CompanyFactListData): {
34
- facts: FactItem[];
35
- };
36
- buildReports(params: {
37
- facts: FactItem[];
38
- reportDates?: SetReportDatesParams[];
39
- }): ReportRaw[];
40
- }
@@ -1,200 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var FactFiscalCalculator_1 = require("./FactFiscalCalculator");
4
- var FactPeriodResolver_1 = require("./FactPeriodResolver");
5
- var FactRecordBuilder_1 = require("./FactRecordBuilder");
6
- var FactSplitAdjuster_1 = require("./FactSplitAdjuster");
7
- /**
8
- * Builds ReportRaw objects from facts. also applies splits and adjusts for fiscal periods.
9
- */
10
- var ReportBuilder = /** @class */ (function () {
11
- function ReportBuilder() {
12
- this.factRecordBuilder = new FactRecordBuilder_1.default();
13
- }
14
- ReportBuilder.prototype.createFacts = function (companyFacts) {
15
- return this.factRecordBuilder.createFacts(companyFacts);
16
- };
17
- ReportBuilder.prototype.buildReports = function (params) {
18
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
19
- var facts = params.facts, reportDates = params.reportDates;
20
- if (facts.length === 0) {
21
- return [];
22
- }
23
- var accessionByYearQuarter = new Map();
24
- reportDates === null || reportDates === void 0 ? void 0 : reportDates.forEach(function (params) {
25
- var year = params.year, quarter = params.quarter, accn = params.accn;
26
- if (accn)
27
- accessionByYearQuarter.set("".concat(year, "_").concat(quarter), accn);
28
- });
29
- var reportsCik = Number(facts[0].cik);
30
- var factFiscalCalculator = new FactFiscalCalculator_1.default();
31
- var factPeriodResolver = new FactPeriodResolver_1.default({ cik: reportsCik });
32
- var factSplitAdjuster = new FactSplitAdjuster_1.default();
33
- facts.forEach(function (fact) { return factFiscalCalculator.add(fact); });
34
- reportDates === null || reportDates === void 0 ? void 0 : reportDates.forEach(function (params) { return factFiscalCalculator.setReportDates(params); });
35
- var unitByPropertyName = new Map();
36
- var splitDateDataByKey = new Map();
37
- var minYear = Infinity;
38
- var maxYear = -Infinity;
39
- var countByAccnByYearQuarter = new Map();
40
- var filedByPropertyYearQuarterValue = new Map();
41
- var filedLastByPropertyYearQuarterValue = new Map();
42
- for (var _i = 0, facts_1 = facts; _i < facts_1.length; _i++) {
43
- var fact = facts_1[_i];
44
- var end = fact.end, name_1 = fact.name, unit = fact.unit, segments = fact.segments, start = fact.start, value = fact.value, cik = fact.cik, form = fact.form, filed = fact.filed, accn = fact.accn;
45
- if (Number(fact.cik) !== Number(reportsCik)) {
46
- throw new Error("All facts must have the same cik ".concat(reportsCik, " !== ").concat(Number(cik)));
47
- }
48
- var segmentValue = segments === null || segments === void 0 ? void 0 : segments.map(function (seg) { return "".concat(seg.dimension, "_").concat(seg.value); }).join('&');
49
- var propertyName = (_a = name_1.split(':').pop()) !== null && _a !== void 0 ? _a : '';
50
- var propertyNameWithSegment = propertyName + (segmentValue ? "_".concat(segmentValue) : '');
51
- var _m = factFiscalCalculator.getFiscalYearQuarter({ dateStr: end }), quarter = _m.quarter, year = _m.year;
52
- if (year < minYear)
53
- minYear = year;
54
- if (year > maxYear)
55
- maxYear = year;
56
- var splitKey = "".concat(year, "_").concat(value);
57
- var factFiledKey = "".concat(year, "_").concat(quarter, "_").concat(propertyNameWithSegment, "_").concat(value);
58
- var isSplit = factSplitAdjuster.isSplitProperty(propertyName);
59
- unitByPropertyName.set(propertyNameWithSegment, unit);
60
- var prevFirstFiled = filedByPropertyYearQuarterValue.get(factFiledKey);
61
- var prevLastFiled = filedLastByPropertyYearQuarterValue.get(factFiledKey);
62
- if (!prevFirstFiled || prevFirstFiled > filed) {
63
- filedByPropertyYearQuarterValue.set(factFiledKey, filed);
64
- }
65
- if (!prevLastFiled || prevLastFiled < filed) {
66
- filedLastByPropertyYearQuarterValue.set(factFiledKey, filed);
67
- }
68
- if (isSplit) {
69
- var isNewLatestDate = new Date(end) > new Date((_c = (_b = splitDateDataByKey.get(splitKey)) === null || _b === void 0 ? void 0 : _b.end) !== null && _c !== void 0 ? _c : 0);
70
- splitDateDataByKey.set(splitKey, {
71
- end: isNewLatestDate ? end : (_e = (_d = splitDateDataByKey.get(splitKey)) === null || _d === void 0 ? void 0 : _d.end) !== null && _e !== void 0 ? _e : end,
72
- quarter: isNewLatestDate ? quarter : (_g = (_f = splitDateDataByKey.get(splitKey)) === null || _f === void 0 ? void 0 : _f.quarter) !== null && _g !== void 0 ? _g : quarter,
73
- firstFiled: (_h = filedByPropertyYearQuarterValue.get(factFiledKey)) !== null && _h !== void 0 ? _h : filed,
74
- lastFiled: (_j = filedLastByPropertyYearQuarterValue.get(factFiledKey)) !== null && _j !== void 0 ? _j : filed,
75
- });
76
- }
77
- var accnKey = "".concat(year, "_").concat(quarter);
78
- var accnGiven = accessionByYearQuarter.get(accnKey);
79
- var filedDistance = Math.abs(new Date(filed).getTime() - new Date(end !== null && end !== void 0 ? end : 0).getTime()) / 86400000;
80
- var isFiledRecent = filedDistance < 60;
81
- if (!accnGiven && isFiledRecent && accn && (!form || form === '10-K' || form === '10-Q')) {
82
- var countByAccn = (_k = countByAccnByYearQuarter.get(accnKey)) !== null && _k !== void 0 ? _k : new Map();
83
- countByAccn.set(accn, ((_l = countByAccn.get(accn)) !== null && _l !== void 0 ? _l : 0) + 1);
84
- countByAccnByYearQuarter.set(accnKey, countByAccn);
85
- }
86
- factPeriodResolver.add({
87
- year: year,
88
- start: start,
89
- end: end,
90
- name: propertyNameWithSegment,
91
- quarter: quarter,
92
- value: value,
93
- filed: filed,
94
- });
95
- }
96
- countByAccnByYearQuarter.forEach(function (countByAccn, yearQuarter) {
97
- if (accessionByYearQuarter.has(yearQuarter))
98
- return;
99
- var maxCount = 0;
100
- var accessionNumber = '';
101
- countByAccn.forEach(function (count, accn) {
102
- if (count > maxCount) {
103
- maxCount = count;
104
- accessionNumber = accn;
105
- }
106
- });
107
- accessionByYearQuarter.set(yearQuarter, accessionNumber);
108
- });
109
- minYear = Number.isFinite(minYear) ? minYear : new Date().getFullYear();
110
- maxYear = Number.isFinite(maxYear) ? maxYear : new Date().getFullYear();
111
- var reportsByKey = new Map();
112
- // resolves quarterly and annual properties and creates reports
113
- factPeriodResolver.forEach(function (data) {
114
- var _a, _b;
115
- var fiscalPeriod = data.fiscalPeriod, propertyName = data.propertyName, value = data.value, year = data.year;
116
- var key = "".concat(year, "_").concat(fiscalPeriod);
117
- var quarter = fiscalPeriod === 'FY' ? 4 : Number(fiscalPeriod[1]);
118
- var dates = factFiscalCalculator.getDatesByYearQuarter({ quarter: quarter, year: year });
119
- var _c = dates !== null && dates !== void 0 ? dates : { filed: '', end: '' }, filed = _c.filed, end = _c.end;
120
- var accessionNumber = accessionByYearQuarter.get("".concat(year, "_").concat(quarter));
121
- var accessionNoHyphen = accessionNumber === null || accessionNumber === void 0 ? void 0 : accessionNumber.replace(/-/g, '');
122
- var url = accessionNumber
123
- ? "https://www.sec.gov/Archives/edgar/data/".concat(reportsCik, "/").concat(accessionNoHyphen, "/").concat(accessionNumber, ".txt")
124
- : null;
125
- if (!reportsByKey.has(key)) {
126
- reportsByKey.set(key, {
127
- cik: reportsCik,
128
- url: url,
129
- dateFiled: filed,
130
- dateReport: end,
131
- fiscalPeriod: fiscalPeriod,
132
- fiscalYear: year,
133
- splitDate: null,
134
- splitRatio: null,
135
- });
136
- }
137
- var filedKey = "".concat(year, "_").concat(quarter, "_").concat(propertyName, "_").concat(value);
138
- // add facts to adjust for splits
139
- factSplitAdjuster.add({
140
- end: end,
141
- // use the original fact filed date instead of the report filed date to know if the fact has been split.
142
- filed: (_a = filedByPropertyYearQuarterValue.get(filedKey)) !== null && _a !== void 0 ? _a : filed,
143
- fiscalPeriod: fiscalPeriod,
144
- name: propertyName,
145
- unit: (_b = unitByPropertyName.get(propertyName)) !== null && _b !== void 0 ? _b : '',
146
- year: year,
147
- value: Number(value),
148
- accn: accessionNumber !== null && accessionNumber !== void 0 ? accessionNumber : '',
149
- });
150
- var report = reportsByKey.get(key);
151
- report[propertyName] = value;
152
- });
153
- // iterate through facts adjustable for splits and assign values to reports
154
- factSplitAdjuster.forEach(function (data) {
155
- var year = data.year, fiscalPeriod = data.fiscalPeriod, propertyName = data.propertyName, value = data.value;
156
- var key = "".concat(year, "_").concat(fiscalPeriod);
157
- var report = reportsByKey.get(key);
158
- if (!report)
159
- return;
160
- report[propertyName] = Math.round(value * 10000) / 10000;
161
- });
162
- // add split dates and values to reports
163
- factSplitAdjuster.getSplitsAsc().forEach(function (split) {
164
- var _a, _b, _c, _d;
165
- var _e = factFiscalCalculator.getFiscalYearQuarter({ dateStr: split.end }), quarter = _e.quarter, year = _e.year;
166
- var keySplit = "".concat(year, "_").concat(split.value);
167
- var splitDateData = (_a = splitDateDataByKey.get(keySplit)) !== null && _a !== void 0 ? _a : { end: null, quarter: null };
168
- var splitDate = (_b = splitDateData.end) !== null && _b !== void 0 ? _b : split.filed;
169
- var splitQuarter = (_c = splitDateData.quarter) !== null && _c !== void 0 ? _c : quarter;
170
- var fiscalPeriod = "Q".concat(splitQuarter);
171
- var keyReport = "".concat(year, "_").concat(fiscalPeriod);
172
- var report = reportsByKey.get(keyReport);
173
- var reportAnnual = splitQuarter === 4 ? (_d = reportsByKey.get("".concat(year, "_FY"))) !== null && _d !== void 0 ? _d : null : null;
174
- if (report) {
175
- report.splitRatio = split.value;
176
- report.splitDate = splitDate;
177
- }
178
- // also assign to annual for Q4
179
- if (reportAnnual) {
180
- reportAnnual.splitRatio = split.value;
181
- reportAnnual.splitDate = splitDate;
182
- }
183
- });
184
- // sort reports ASC by year and quarter
185
- var reportsSorted = [];
186
- for (var year = minYear; year <= maxYear; year++) {
187
- for (var i = 0; i < 5; i++) {
188
- var fiscalPeriod = i === 4 ? 'FY' : "Q".concat(i + 1);
189
- var key = "".concat(year, "_").concat(fiscalPeriod);
190
- var report = reportsByKey.get(key);
191
- if (report && report.dateReport) {
192
- reportsSorted.push(report);
193
- }
194
- }
195
- }
196
- return reportsSorted;
197
- };
198
- return ReportBuilder;
199
- }());
200
- exports.default = ReportBuilder;
@@ -1,17 +0,0 @@
1
- import { ReportRaw } from '../../types';
2
- export type TemplateCode = 'I' | 'T' | 'B' | 'M' | 'N' | 'U';
3
- export default class ReportRawResolvable {
4
- readonly report: ReportRaw;
5
- private readonly emptyKeys;
6
- private readonly addedProps;
7
- private readonly calcMap;
8
- private readonly templateCode;
9
- private readonly keyStack;
10
- constructor(report: ReportRaw, templateCode?: TemplateCode | null, calcMap?: Record<string, Record<string, string[]>>);
11
- get(key: string): string | number | boolean | undefined;
12
- getNumber(key: string): number;
13
- isAdded(key: string): boolean;
14
- private getChildKeysArr;
15
- private calculateNumericKey;
16
- toJSON(): ReportRaw;
17
- }