sec-edgar-api 0.5.1 → 0.5.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.
@@ -2,6 +2,7 @@ import { XMLParams } from '../../types';
2
2
  import { GetDocumentXbrlParams } from '../SecEdgarApi';
3
3
  import XMLParser from './XMLParserLegacy';
4
4
  import parsers from './parsers';
5
+ import { DocumentXbrlResult } from './parsers/parse-xbrl';
5
6
  interface DocumentParserArgs {
6
7
  parser?: XMLParser;
7
8
  parsersByName?: typeof parsers;
@@ -36,10 +37,6 @@ export default class DocumentParser {
36
37
  };
37
38
  parseCurrentFilings(params: XMLParams): import("../../types").CurrentFilingsList;
38
39
  parseCurrentFilingsXbrl(params: XMLParams): import("../../types").CurrentFilingsXBRL;
39
- parseXbrl(params: XMLParams & GetDocumentXbrlParams): import("./XBRLParser/XBRLParser").XbrlParseResult & {
40
- report: import("../../types").ReportRaw | null;
41
- facts: import("../../types").FactItemExtended[];
42
- xml: string;
43
- };
40
+ parseXbrl(params: XMLParams & GetDocumentXbrlParams): DocumentXbrlResult;
44
41
  }
45
42
  export {};
@@ -1,8 +1,9 @@
1
1
  import type { FactItemExtended, ReportRaw, XMLParams } from '../../../types';
2
2
  import { GetDocumentXbrlParams } from '../../SecEdgarApi';
3
3
  import { XbrlParseResult } from '../XBRLParser/XBRLParser';
4
- export declare function parseXbrl(params: XMLParams & GetDocumentXbrlParams): XbrlParseResult & {
4
+ export interface DocumentXbrlResult extends XbrlParseResult {
5
5
  report: ReportRaw | null;
6
6
  facts: FactItemExtended[];
7
7
  xml: string;
8
- };
8
+ }
9
+ export declare function parseXbrl(params: XMLParams & GetDocumentXbrlParams): DocumentXbrlResult;
@@ -31,10 +31,10 @@ export default class ReportParser {
31
31
  /**
32
32
  * Same as parseReports but accepts ReportRaw[] instead of CompanyFactListData
33
33
  */
34
- parseReportsFromRaw<T = ReportTranslated>(params: {
35
- reportsRaw: ReportRaw[];
34
+ translateReport<T = ReportTranslated>(params: {
35
+ report: ReportRaw;
36
36
  calculationMap?: CalculationMap<T>;
37
- }): (ReportRaw & T)[];
37
+ }): ReportRaw & T;
38
38
  /**
39
39
  * Parse raw reports
40
40
  *
@@ -48,6 +48,8 @@ export default class ReportParser {
48
48
  */
49
49
  buildReports(params: BuildReportsParams): ReportRaw[];
50
50
  /**
51
+ * @deprecated use translateReport
52
+ *
51
53
  * Translate ReportRaw to ReportTranslated by default, but can be used to translate to any object using both the callback and keyTranslator
52
54
  *
53
55
  * @param reportsRaw this is the output of parseReportsRaw
@@ -53,31 +53,32 @@ var ReportParser = /** @class */ (function () {
53
53
  /**
54
54
  * Same as parseReports but accepts ReportRaw[] instead of CompanyFactListData
55
55
  */
56
- ReportParser.prototype.parseReportsFromRaw = function (params) {
57
- var reportsRaw = params.reportsRaw, calculationMap = params.calculationMap;
56
+ ReportParser.prototype.translateReport = function (params) {
57
+ var _a;
58
+ var report = params.report, calculationMap = params.calculationMap;
58
59
  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;
60
+ var reportNew = {
61
+ cik: report.cik,
62
+ dateFiled: report.dateFiled,
63
+ dateReport: report.dateReport,
64
+ fiscalPeriod: report.fiscalPeriod,
65
+ url: report.url,
66
+ fiscalYear: report.fiscalYear,
67
+ splitDate: report.splitDate,
68
+ splitRatio: report.splitRatio,
69
+ };
70
+ var reportResolvable = new ReportResolvable_1.default({
71
+ report: report,
72
+ calculationMap: calcMap,
73
+ });
74
+ for (var key in calcMap) {
75
+ var value = (_a = reportResolvable.get(key)) !== null && _a !== void 0 ? _a : null;
76
+ // use first truthy value
77
+ if (!reportNew[key]) {
77
78
  reportNew[key] = value;
78
79
  }
79
- return reportNew;
80
- });
80
+ }
81
+ return reportNew;
81
82
  };
82
83
  /**
83
84
  * Parse raw reports
@@ -96,6 +97,8 @@ var ReportParser = /** @class */ (function () {
96
97
  return this.reportBuilder.buildReports(params);
97
98
  };
98
99
  /**
100
+ * @deprecated use translateReport
101
+ *
99
102
  * Translate ReportRaw to ReportTranslated by default, but can be used to translate to any object using both the callback and keyTranslator
100
103
  *
101
104
  * @param reportsRaw this is the output of parseReportsRaw
@@ -22,9 +22,7 @@ export default class FactFiscalCalculator {
22
22
  facts?: Pick<FactItem, 'end' | 'filed'>[];
23
23
  filings?: Pick<FilingListItemTranslated, 'form' | 'reportDate' | 'filingDate' | 'accessionNumber'>[];
24
24
  });
25
- useFilingsForDates(params: {
26
- filings: Pick<FilingListItemTranslated, 'form' | 'reportDate' | 'filingDate' | 'accessionNumber'>[];
27
- }): void;
25
+ private useFilingsForDates;
28
26
  add(fact: {
29
27
  end: string;
30
28
  filed: string;
@@ -15,9 +15,7 @@ var FactFiscalCalculator = /** @class */ (function () {
15
15
  this.filedDateCountByEndDate = new Map();
16
16
  this.didResolve = false;
17
17
  var _a = params !== null && params !== void 0 ? params : {}, _b = _a.facts, facts = _b === void 0 ? [] : _b, _c = _a.filings, filings = _c === void 0 ? [] : _c;
18
- if (filings.length > 0) {
19
- this.useFilingsForDates({ filings: filings });
20
- }
18
+ this.useFilingsForDates({ filings: filings });
21
19
  facts.forEach(function (fact) { return _this.add(fact); });
22
20
  }
23
21
  FactFiscalCalculator.prototype.useFilingsForDates = function (params) {
@@ -197,20 +197,9 @@ var FactPeriodResolver = /** @class */ (function () {
197
197
  var _this = this;
198
198
  this.propertiesByYear.forEach(function (properties, year) {
199
199
  properties.forEach(function (propertyName) {
200
- var _a, _b;
200
+ var _a;
201
201
  for (var i = 0; i < 4; i++) {
202
202
  var bucketSum = (_a = _this.sumByQuarterByPropertyByYear.get(year)) === null || _a === void 0 ? void 0 : _a.get(propertyName);
203
- var bucketQuarter = _this.getOrSetBucketArr(_this.valueByQuarterByPropertyByYear, year, propertyName);
204
- if (bucketSum && !bucketSum.has(i)) {
205
- var prevSum = 0;
206
- var quarterSum = 0;
207
- for (var j = 0; j < i; j++) {
208
- prevSum = quarterSum;
209
- quarterSum = (_b = bucketSum.get(j)) !== null && _b !== void 0 ? _b : quarterSum;
210
- }
211
- bucketSum.set(i, quarterSum);
212
- bucketQuarter.set(i, quarterSum - prevSum);
213
- }
214
203
  var value = bucketSum === null || bucketSum === void 0 ? void 0 : bucketSum.get(i);
215
204
  if (value === undefined)
216
205
  continue;
@@ -1,18 +1,22 @@
1
- import type { CompanyFactListData, FactGroup, FactItem, ReportRaw, SplitData } from '../../types';
2
- import FactFiscalCalculator, { SetReportDatesParams } from './FactFiscalCalculator';
1
+ import type { CompanyFactListData, FactGroup, FactItem, FilingListItemTranslated, ReportRaw, SplitData } from '../../types';
2
+ import FactFiscalCalculator from './FactFiscalCalculator';
3
3
  export interface BuildReportsParams {
4
4
  facts: FactItem[];
5
5
  /**
6
6
  * for more accurate dates, add this. Otherwise, dates will be inferred
7
7
  * using the fact periods. The filing and report dates can be found in the SubmissionList (segEdgarApi.getSubmissions)
8
8
  */
9
- reportDates?: SetReportDatesParams[];
9
+ filings?: Pick<FilingListItemTranslated, 'form' | 'reportDate' | 'filingDate' | 'accessionNumber'>[];
10
10
  /**
11
11
  * Splits will be extracted from facts if not provided.
12
12
  */
13
13
  splits?: SplitData[];
14
14
  resolvePeriodValues?: boolean;
15
15
  adjustForSplits?: boolean;
16
+ /**
17
+ * For member facts (facts with segments), the separator between the fact name and the segments.
18
+ */
19
+ pathSeparatorForMemberFacts?: string;
16
20
  }
17
21
  /**
18
22
  * Builds ReportRaw objects from company facts. Adjusts for splits and resolves period values.
@@ -22,7 +26,7 @@ export default class ReportRawBuilder {
22
26
  createFacts(companyFacts: CompanyFactListData, includeNamePrefix?: boolean): {
23
27
  facts: FactItem[];
24
28
  };
25
- private createFiscalCalculator;
29
+ private getFactKey;
26
30
  buildReports(params: BuildReportsParams): ReportRaw[];
27
31
  private createReportKey;
28
32
  private createReport;
@@ -1,5 +1,17 @@
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 constants_1 = require("../../util/constants");
3
15
  var FactFiscalCalculator_1 = require("./FactFiscalCalculator");
4
16
  var FactGrouper_1 = require("./FactGrouper");
5
17
  var FactRecordBuilder_1 = require("./FactRecordBuilder");
@@ -15,43 +27,49 @@ var ReportRawBuilder = /** @class */ (function () {
15
27
  if (includeNamePrefix === void 0) { includeNamePrefix = false; }
16
28
  return this.factRecordBuilder.createFacts(companyFacts, includeNamePrefix);
17
29
  };
18
- ReportRawBuilder.prototype.createFiscalCalculator = function (params) {
19
- var facts = params.facts;
20
- var fiscalCalculator = new FactFiscalCalculator_1.default();
21
- for (var _i = 0, facts_1 = facts; _i < facts_1.length; _i++) {
22
- var fact = facts_1[_i];
23
- fiscalCalculator.add(fact);
24
- }
25
- return fiscalCalculator;
30
+ ReportRawBuilder.prototype.getFactKey = function (fact, pathSeparator) {
31
+ var _a;
32
+ var suffix = (_a = fact.segments) === null || _a === void 0 ? void 0 : _a.map(function (_a) {
33
+ var dimension = _a.dimension, value = _a.value;
34
+ return "".concat(dimension).concat(pathSeparator).concat(value);
35
+ }).join(pathSeparator);
36
+ return suffix ? "".concat(fact.name).concat(pathSeparator).concat(suffix) : fact.name;
26
37
  };
27
38
  ReportRawBuilder.prototype.buildReports = function (params) {
28
- var facts = params.facts, reportDates = params.reportDates, splitsProp = params.splits, _a = params.resolvePeriodValues, resolvePeriodValues = _a === void 0 ? true : _a, _b = params.adjustForSplits, adjustForSplits = _b === void 0 ? true : _b;
39
+ var _this = this;
40
+ var factsProp = params.facts, filings = params.filings, splitsProp = params.splits, _a = params.resolvePeriodValues, resolvePeriodValues = _a === void 0 ? true : _a, _b = params.adjustForSplits, adjustForSplits = _b === void 0 ? true : _b, _c = params.pathSeparatorForMemberFacts, pathSeparatorForMemberFacts = _c === void 0 ? '>' : _c;
41
+ // Rename member facts to prevent overwriting parent facts.
42
+ var facts = factsProp.map(function (fact) {
43
+ var factKey = _this.getFactKey(fact, pathSeparatorForMemberFacts);
44
+ return __assign(__assign({}, fact), { name: factKey });
45
+ });
29
46
  if (facts.length === 0) {
30
47
  return [];
31
48
  }
49
+ var reportsCik = Number(facts[0].cik);
50
+ var fiscalCalculator = new FactFiscalCalculator_1.default({
51
+ filings: filings === null || filings === void 0 ? void 0 : filings.filter(function (f) { return constants_1.FORMS_EARNINGS.includes(f.form); }),
52
+ facts: facts,
53
+ });
32
54
  var accessionByYearQuarter = new Map();
33
- reportDates === null || reportDates === void 0 ? void 0 : reportDates.forEach(function (params) {
34
- var year = params.year, quarter = params.quarter, accn = params.accn;
35
- if (accn)
36
- accessionByYearQuarter.set("".concat(year, "_").concat(quarter), accn);
55
+ filings === null || filings === void 0 ? void 0 : filings.forEach(function (f) {
56
+ var _a = fiscalCalculator.getFiscalYearQuarter({ dateStr: f.reportDate }), year = _a.year, quarter = _a.quarter;
57
+ accessionByYearQuarter.set(f.accessionNumber, "".concat(year, "_").concat(quarter));
37
58
  });
38
- var reportsCik = Number(facts[0].cik);
39
- var fiscalCalculator = reportDates ? new FactFiscalCalculator_1.default() : this.createFiscalCalculator({ facts: facts });
40
- reportDates === null || reportDates === void 0 ? void 0 : reportDates.forEach(function (params) { return fiscalCalculator.setReportDates(params); });
41
59
  var factGrouper = new FactGrouper_1.default();
42
60
  var factSplitAdjuster = new FactSplitAdjuster_1.default();
43
61
  // if splits not included in params and need to adjust, extract from facts
44
62
  var splits = adjustForSplits
45
63
  ? splitsProp !== null && splitsProp !== void 0 ? splitsProp : factSplitAdjuster.getSplits({ splitFacts: factSplitAdjuster.filterSplitFacts({ facts: facts }) })
46
64
  : splitsProp;
47
- var _c = factGrouper.buildFactGroupsByReportKey({
65
+ var _d = factGrouper.buildFactGroupsByReportKey({
48
66
  facts: facts,
49
67
  cik: reportsCik,
50
68
  fiscalCalculator: fiscalCalculator,
51
69
  resolvePeriodValues: resolvePeriodValues,
52
70
  generateMissingGroups: false,
53
71
  splits: splits,
54
- }), factGroupsByReportKey = _c.factGroupsByReportKey, maxYear = _c.maxYear, minYear = _c.minYear;
72
+ }), factGroupsByReportKey = _d.factGroupsByReportKey, maxYear = _d.maxYear, minYear = _d.minYear;
55
73
  return this.buildReportsFromGroups({
56
74
  factGroupsByReportKey: factGroupsByReportKey,
57
75
  fiscalCalculator: fiscalCalculator,
@@ -231,11 +231,7 @@ export default class SecEdgarApi {
231
231
  *
232
232
  * Use "include" params to specify what to parse. If not provided, all data is parsed.
233
233
  */
234
- getDocumentXbrl(params: GetDocumentXbrlParams): Promise<import("../DocumentParser/XBRLParser/XBRLParser").XbrlParseResult & {
235
- report: ReportRaw | null;
236
- facts: import("../../types").FactItemExtended[];
237
- xml: string;
238
- }>;
234
+ getDocumentXbrl(params: GetDocumentXbrlParams): Promise<import("../DocumentParser/parsers/parse-xbrl").DocumentXbrlResult>;
239
235
  /**
240
236
  * Builds a url for a document. If fileName is not provided, it defaults to `${accessionNumber}.txt`
241
237
  *
@@ -302,17 +302,17 @@ var SecEdgarApi = /** @class */ (function () {
302
302
  */
303
303
  SecEdgarApi.prototype.getReports = function (params) {
304
304
  return __awaiter(this, void 0, void 0, function () {
305
- var calculationMap, reportsRaw;
305
+ var calculationMap, reports;
306
+ var _this = this;
306
307
  return __generator(this, function (_a) {
307
308
  switch (_a.label) {
308
309
  case 0:
309
310
  calculationMap = params.calculationMap;
310
311
  return [4 /*yield*/, this.getReportsRaw(__assign(__assign({}, params), { includeNamePrefix: true }))];
311
312
  case 1:
312
- reportsRaw = _a.sent();
313
- return [2 /*return*/, this.reportParser.parseReportsFromRaw({
314
- reportsRaw: reportsRaw,
315
- calculationMap: calculationMap,
313
+ reports = _a.sent();
314
+ return [2 /*return*/, reports.map(function (report) {
315
+ return _this.reportParser.translateReport({ report: report, calculationMap: calculationMap });
316
316
  })];
317
317
  }
318
318
  });
@@ -1,2 +1,4 @@
1
1
  declare const KEY_SPLIT = "StockholdersEquityNoteStockSplitConversionRatio1";
2
- export { KEY_SPLIT };
2
+ declare const FORMS_EARNINGS: string[];
3
+ declare const FORMS_EARNINGS_ANNUAL: string[];
4
+ export { KEY_SPLIT, FORMS_EARNINGS, FORMS_EARNINGS_ANNUAL };
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KEY_SPLIT = void 0;
3
+ exports.FORMS_EARNINGS_ANNUAL = exports.FORMS_EARNINGS = exports.KEY_SPLIT = void 0;
4
4
  var KEY_SPLIT = 'StockholdersEquityNoteStockSplitConversionRatio1';
5
5
  exports.KEY_SPLIT = KEY_SPLIT;
6
+ var FORMS_EARNINGS = ['10-Q', '10-K', '20-F', '40-F'];
7
+ exports.FORMS_EARNINGS = FORMS_EARNINGS;
8
+ var FORMS_EARNINGS_ANNUAL = ['10-K', '20-F', '40-F'];
9
+ exports.FORMS_EARNINGS_ANNUAL = FORMS_EARNINGS_ANNUAL;
@@ -1,5 +1,7 @@
1
1
  import type { ReportTranslated } from '../types/report-translated.type';
2
2
  /**
3
+ * @deprecated use calculationMap for ReportResolvable
4
+ *
3
5
  * Checks if any of the array keys exist in the object to assign to the translated key
4
6
  * These were checked against Yahoo Finance values, adding the ones that most often matched the yahoo values
5
7
  */
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /**
4
+ * @deprecated use calculationMap for ReportResolvable
5
+ *
4
6
  * Checks if any of the array keys exist in the object to assign to the translated key
5
7
  * These were checked against Yahoo Finance values, adding the ones that most often matched the yahoo values
6
8
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sec-edgar-api",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
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)",