diff --git a/schema.json b/schema.json index c200f7bd..0155cfc0 100644 --- a/schema.json +++ b/schema.json @@ -12,6 +12,103 @@ "type": "string" }, "AssetProfile": { + "additionalProperties": false, + "properties": { + "address1": { + "type": "string" + }, + "address2": { + "type": "string" + }, + "auditRisk": { + "type": "number" + }, + "boardRisk": { + "type": "number" + }, + "city": { + "type": "string" + }, + "companyOfficers": { + "items": { + "$ref": "#/definitions/CompanyOfficer" + }, + "type": "array" + }, + "compensationAsOfEpochDate": { + "format": "date-time", + "type": "string" + }, + "compensationRisk": { + "type": "number" + }, + "country": { + "type": "string" + }, + "fax": { + "type": "string" + }, + "fullTimeEmployees": { + "type": "number" + }, + "governanceEpochDate": { + "format": "date-time", + "type": "string" + }, + "industry": { + "type": "string" + }, + "longBusinessSummary": { + "type": "string" + }, + "maxAge": { + "type": "number" + }, + "overallRisk": { + "type": "number" + }, + "phone": { + "type": "string" + }, + "sector": { + "type": "string" + }, + "shareHolderRightsRisk": { + "type": "number" + }, + "state": { + "type": "string" + }, + "website": { + "type": "string" + }, + "zip": { + "type": "string" + } + }, + "required": [ + "address1", + "auditRisk", + "boardRisk", + "city", + "companyOfficers", + "compensationRisk", + "country", + "fullTimeEmployees", + "governanceEpochDate", + "industry", + "longBusinessSummary", + "maxAge", + "overallRisk", + "phone", + "sector", + "shareHolderRightsRisk", + "website", + "zip" + ], + "type": "object" + }, + "AssetProfileJson": { "additionalProperties": false, "properties": { "address1": { @@ -192,97 +289,97 @@ "additionalProperties": false, "properties": { "accountsPayable": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "capitalSurplus": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "cash": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "commonStock": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "deferredLongTermAssetCharges": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "deferredLongTermLiab": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "endDate": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "goodWill": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "intangibleAssets": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "inventory": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "longTermDebt": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "longTermInvestments": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "maxAge": { "type": "number" }, "minorityInterest": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "netReceivables": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "netTangibleAssets": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "otherAssets": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "otherCurrentAssets": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "otherCurrentLiab": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "otherLiab": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "otherStockholderEquity": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "propertyPlantEquipment": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "retainedEarnings": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "shortLongTermDebt": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "shortTermInvestments": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "totalAssets": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "totalCurrentAssets": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "totalCurrentLiabilities": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "totalLiab": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "totalStockholderEquity": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "treasuryStock": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" } }, "required": [ @@ -370,70 +467,70 @@ "additionalProperties": false, "properties": { "capitalExpenditures": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "changeInCash": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "changeToAccountReceivables": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "changeToInventory": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "changeToLiabilities": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "changeToNetincome": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "changeToOperatingActivities": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "depreciation": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "dividendsPaid": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "effectOfExchangeRate": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "endDate": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "investments": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "issuanceOfStock": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "maxAge": { "type": "number" }, "netBorrowings": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "netIncome": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "otherCashflowsFromFinancingActivities": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "otherCashflowsFromInvestingActivities": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "repurchaseOfStock": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "totalCashFromFinancingActivities": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "totalCashFromOperatingActivities": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "totalCashflowsFromInvestingActivities": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" } }, "required": [ @@ -480,7 +577,7 @@ "type": "number" }, "exercisedValue": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "fiscalYear": { "type": "number" @@ -495,10 +592,10 @@ "type": "string" }, "totalPay": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "unexercisedValue": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "yearBorn": { "type": "number" @@ -507,25 +604,7 @@ "required": [ "maxAge", "name", - "title", - "exercisedValue", - "unexercisedValue" - ], - "type": "object" - }, - "DateObj": { - "additionalProperties": false, - "properties": { - "fmt": { - "type": "string" - }, - "raw": { - "type": "number" - } - }, - "required": [ - "raw", - "fmt" + "title" ], "type": "object" }, @@ -734,22 +813,22 @@ "additionalProperties": false, "properties": { "avg": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "growth": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "high": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "low": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "numberOfAnalysts": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "yearAgoEps": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" } }, "required": [ @@ -785,13 +864,13 @@ "additionalProperties": false, "properties": { "epsActual": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "epsDifference": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "epsEstimate": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "maxAge": { "type": "number" @@ -800,10 +879,10 @@ "type": "string" }, "quarter": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "surprisePercent": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" } }, "required": [ @@ -830,6 +909,25 @@ "type": "array" } }, + "required": [ + "maxAge", + "trend" + ], + "type": "object" + }, + "EarningsTrendJson": { + "additionalProperties": false, + "properties": { + "maxAge": { + "type": "number" + }, + "trend": { + "items": { + "$ref": "#/definitions/EarningsTrendTrendJson" + }, + "type": "array" + } + }, "required": [ "trend", "maxAge" @@ -843,14 +941,50 @@ "$ref": "#/definitions/EarningsEstimate" }, "endDate": { - "anyOf": [ - { - "format": "date-time", - "type": "string" - }, - { - "type": "null" - } + "format": "date-time", + "type": "string" + }, + "epsRevisions": { + "$ref": "#/definitions/EpsRevisions" + }, + "epsTrend": { + "$ref": "#/definitions/EpsTrend" + }, + "growth": { + "$ref": "#/definitions/RawNumberObj" + }, + "maxAge": { + "type": "number" + }, + "period": { + "type": "string" + }, + "revenueEstimate": { + "$ref": "#/definitions/RevenueEstimate" + } + }, + "required": [ + "earningsEstimate", + "endDate", + "epsRevisions", + "epsTrend", + "growth", + "maxAge", + "period", + "revenueEstimate" + ], + "type": "object" + }, + "EarningsTrendTrendJson": { + "additionalProperties": false, + "properties": { + "earningsEstimate": { + "$ref": "#/definitions/EarningsEstimate" + }, + "endDate": { + "type": [ + "string", + "null" ] }, "epsRevisions": { @@ -860,7 +994,7 @@ "$ref": "#/definitions/EpsTrend" }, "growth": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "maxAge": { "type": "number" @@ -888,16 +1022,16 @@ "additionalProperties": false, "properties": { "downLast30days": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "downLast90days": { "$ref": "#/definitions/DiscontinuedOperations" }, "upLast30days": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "upLast7days": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" } }, "required": [ @@ -912,19 +1046,19 @@ "additionalProperties": false, "properties": { "30daysAgo": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "60daysAgo": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "7daysAgo": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "90daysAgo": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "current": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" } }, "required": [ @@ -951,29 +1085,54 @@ ], "type": "object" }, - "ExercisedValue": { + "Filing": { "additionalProperties": false, "properties": { - "fmt": { - "type": [ - "null", - "string" - ] + "date": { + "additionalProperties": { + "type": "string" + }, + "properties": { + "length": { + "type": "number" + } + }, + "required": [ + "length" + ], + "type": "object" }, - "longFmt": { + "edgarUrl": { "type": "string" }, - "raw": { + "epochDate": { + "format": "date-time", + "type": "string" + }, + "maxAge": { "type": "number" + }, + "title": { + "type": "string" + }, + "type": { + "$ref": "#/definitions/Type" } }, + "required": [ + "date", + "edgarUrl", + "epochDate", + "maxAge", + "title", + "type" + ], "type": "object" }, - "Filing": { + "FilingJson": { "additionalProperties": false, "properties": { "date": { - "format": "date-time", "type": "string" }, "edgarUrl": { @@ -1288,7 +1447,7 @@ "additionalProperties": false, "properties": { "latestTransDate": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "maxAge": { "type": "number" @@ -1297,16 +1456,16 @@ "type": "string" }, "positionDirect": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "positionDirectDate": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "positionIndirect": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "positionIndirectDate": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "relation": { "$ref": "#/definitions/Relation" @@ -1370,76 +1529,76 @@ "additionalProperties": false, "properties": { "costOfRevenue": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "discontinuedOperations": { "$ref": "#/definitions/DiscontinuedOperations" }, "ebit": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "effectOfAccountingCharges": { "$ref": "#/definitions/DiscontinuedOperations" }, "endDate": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "extraordinaryItems": { "$ref": "#/definitions/DiscontinuedOperations" }, "grossProfit": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "incomeBeforeTax": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "incomeTaxExpense": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "interestExpense": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "maxAge": { "type": "number" }, "minorityInterest": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "netIncome": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "netIncomeApplicableToCommonShares": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "netIncomeFromContinuingOps": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "nonRecurring": { "$ref": "#/definitions/DiscontinuedOperations" }, "operatingIncome": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "otherItems": { "$ref": "#/definitions/DiscontinuedOperations" }, "otherOperatingExpenses": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "researchDevelopment": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "sellingGeneralAdministrative": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "totalOperatingExpenses": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "totalOtherIncomeExpenseNet": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "totalRevenue": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" } }, "required": [ @@ -1637,16 +1796,16 @@ "type": "string" }, "pctHeld": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "position": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "reportDate": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "value": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" } }, "required": [ @@ -2047,7 +2206,7 @@ "additionalProperties": false, "properties": { "assetProfile": { - "$ref": "#/definitions/AssetProfile" + "$ref": "#/definitions/AssetProfileJson" }, "balanceSheetHistory": { "$ref": "#/definitions/BalanceSheetHistory" @@ -2147,7 +2306,7 @@ "additionalProperties": false, "properties": { "assetProfile": { - "$ref": "#/definitions/AssetProfile" + "$ref": "#/definitions/AssetProfileJson" }, "balanceSheetHistory": { "$ref": "#/definitions/BalanceSheetHistory" @@ -2174,7 +2333,7 @@ "$ref": "#/definitions/EarningsHistory" }, "earningsTrend": { - "$ref": "#/definitions/EarningsTrend" + "$ref": "#/definitions/EarningsTrendJson" }, "financialData": { "$ref": "#/definitions/FinancialData" @@ -2222,7 +2381,7 @@ "$ref": "#/definitions/RecommendationTrend" }, "secFilings": { - "$ref": "#/definitions/SECFilings" + "$ref": "#/definitions/SECFilingsJson" }, "sectorTrend": { "$ref": "#/definitions/Trend" @@ -2302,6 +2461,24 @@ ], "type": "object" }, + "RawNumberObj": { + "additionalProperties": false, + "properties": { + "fmt": { + "type": [ + "null", + "string" + ] + }, + "longFmt": { + "type": "string" + }, + "raw": { + "type": "number" + } + }, + "type": "object" + }, "RecommendationTrend": { "additionalProperties": false, "properties": { @@ -2374,22 +2551,22 @@ "additionalProperties": false, "properties": { "avg": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "growth": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "high": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "low": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "numberOfAnalysts": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "yearAgoRevenue": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" } }, "required": [ @@ -2421,6 +2598,25 @@ ], "type": "object" }, + "SECFilingsJson": { + "additionalProperties": false, + "properties": { + "filings": { + "items": { + "$ref": "#/definitions/FilingJson" + }, + "type": "array" + }, + "maxAge": { + "type": "number" + } + }, + "required": [ + "filings", + "maxAge" + ], + "type": "object" + }, "SearchNews": { "additionalProperties": false, "properties": { @@ -3183,16 +3379,16 @@ "$ref": "#/definitions/OwnershipEnum" }, "shares": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" }, "startDate": { - "$ref": "#/definitions/DateObj" + "$ref": "#/definitions/RawNumberObj" }, "transactionText": { "type": "string" }, "value": { - "$ref": "#/definitions/ExercisedValue" + "$ref": "#/definitions/RawNumberObj" } }, "required": [ diff --git a/src/lib/mutateJson.spec.ts b/src/lib/mutateJson.spec.ts index 005869f1..92f803d1 100644 --- a/src/lib/mutateJson.spec.ts +++ b/src/lib/mutateJson.spec.ts @@ -1,6 +1,6 @@ import mutateJson from './mutateJson'; import transformField from './transformField'; -import { quoteSummary_dateFields } from '../modules/quoteSummary'; +import { fieldTransformMap } from '../modules/quoteSummary'; describe('mutateJson', () => { @@ -9,7 +9,7 @@ describe('mutateJson', () => { earnings: { earningsDate: [ 1619568000, 1620000000 ] } }; - mutateJson(obj, quoteSummary_dateFields, transformField); + mutateJson(obj, fieldTransformMap, transformField); expect(obj.earnings.earningsDate[0]).toBeInstanceOf(Date); expect(obj.earnings.earningsDate[1]).toBeInstanceOf(Date); @@ -30,7 +30,7 @@ describe('mutateJson', () => { } }; - mutateJson(obj, quoteSummary_dateFields, transformField); + mutateJson(obj, fieldTransformMap, transformField); const array = obj.cashflowStatementHistoryQuarterly.cashflowStatements; expect(array[0].endDate).toBeInstanceOf(Date); diff --git a/src/lib/transformField.ts b/src/lib/transformField.ts index c6b367f4..abf9120c 100644 --- a/src/lib/transformField.ts +++ b/src/lib/transformField.ts @@ -27,7 +27,7 @@ const formats: {[key:string]:Function} = { ISODate(input: string) { // 2021-02-05T00:00:00.000Z if (typeof input !== 'string') - throw new Error("transformField(input, format), format=ISODate but typeof input !== 'string'"); + throw new Error("transformField(input, format), format=ISODate but typeof input !== 'string', got: " + JSON.stringify(input)); if (!input.match(/^\d{4,4}-\d{2,2}-\d{2,2}T\d{2,2}:\d{2,2}:\d{2,2}\.\d{3,3}Z/)) throw new Error("transformField(input, format), format=ISODate but got input " + input); return new Date(input); diff --git a/src/modules/quoteSummary.d.ts b/src/modules/quoteSummary.d.ts index 6c1785ae..ecf8322e 100644 --- a/src/modules/quoteSummary.d.ts +++ b/src/modules/quoteSummary.d.ts @@ -11,7 +11,7 @@ */ export interface QuoteSummaryResultJson { - assetProfile?: AssetProfile; + assetProfile?: AssetProfileJson; balanceSheetHistory?: BalanceSheetHistory; balanceSheetHistoryQuarterly?: BalanceSheetHistory; calendarEvents?: CalendarEvents; @@ -20,7 +20,7 @@ export interface QuoteSummaryResultJson { defaultKeyStatistics?: DefaultKeyStatistics; earnings?: QuoteSummaryEarnings; earningsHistory?: EarningsHistory; - earningsTrend?: EarningsTrend; + earningsTrend?: EarningsTrendJson; financialData?: FinancialData; fundOwnership?: Ownership; incomeStatementHistory?: IncomeStatementHistory; @@ -36,20 +36,23 @@ export interface QuoteSummaryResultJson { price?: PriceJson; quoteType?: QuoteType; recommendationTrend?: RecommendationTrend; - secFilings?: SECFilings; + secFilings?: SECFilingsJson; sectorTrend?: Trend; summaryDetail?: SummaryDetailJson; summaryProfile?: SummaryProfile; upgradeDowngradeHistory?: UpgradeDowngradeHistory; } -export interface QuoteSummaryResult extends Omit { +export interface QuoteSummaryResult extends Omit { + assetProfile?: AssetProfileJson; + earningsTrend?: EarningsTrend; price: Price; + secFilings?: SECFilings; summaryDetail: SummaryDetail; } -export interface AssetProfile { +export interface AssetProfileJson { address1: string; city: string; state?: string; @@ -73,23 +76,21 @@ export interface AssetProfile { address2?: string; fax?: string; } - -export interface CompanyOfficer { - maxAge: number; - name: string; - age?: number; - title: string; - yearBorn?: number; - fiscalYear?: number; - totalPay?: ExercisedValue; - exercisedValue: ExercisedValue; - unexercisedValue: ExercisedValue; +export interface AssetProfile extends Omit { + governanceEpochDate: Date; + compensationAsOfEpochDate?: Date; } -export interface ExercisedValue { - raw?: number; - fmt?: null | string; - longFmt?: string; +export interface CompanyOfficer { + maxAge: number; + name: string; + age?: number; + title: string; + yearBorn?: number; + fiscalYear?: number; + totalPay?: RawNumberObj; + exercisedValue?: RawNumberObj; + unexercisedValue?: RawNumberObj; } export interface BalanceSheetHistory { @@ -99,41 +100,42 @@ export interface BalanceSheetHistory { export interface BalanceSheetStatement { maxAge: number; - endDate: DateObj; - cash: ExercisedValue; - shortTermInvestments?: ExercisedValue; - netReceivables: ExercisedValue; - inventory: ExercisedValue; - otherCurrentAssets: ExercisedValue; - totalCurrentAssets: ExercisedValue; - longTermInvestments: ExercisedValue; - propertyPlantEquipment: ExercisedValue; - otherAssets: ExercisedValue; - totalAssets: ExercisedValue; - accountsPayable: ExercisedValue; - shortLongTermDebt?: ExercisedValue; - otherCurrentLiab: ExercisedValue; - longTermDebt: ExercisedValue; - otherLiab: ExercisedValue; - totalCurrentLiabilities: ExercisedValue; - totalLiab: ExercisedValue; - commonStock?: ExercisedValue; - retainedEarnings: ExercisedValue; - treasuryStock: ExercisedValue; - otherStockholderEquity: ExercisedValue; - totalStockholderEquity: ExercisedValue; - netTangibleAssets: ExercisedValue; - goodWill?: ExercisedValue; - intangibleAssets?: ExercisedValue; - deferredLongTermAssetCharges?: ExercisedValue; - deferredLongTermLiab?: ExercisedValue; - minorityInterest?: ExercisedValue; - capitalSurplus?: ExercisedValue; -} - -export interface DateObj { - raw: number; - fmt: string; + endDate: RawNumberObj; + cash: RawNumberObj; + shortTermInvestments?: RawNumberObj; + netReceivables: RawNumberObj; + inventory: RawNumberObj; + otherCurrentAssets: RawNumberObj; + totalCurrentAssets: RawNumberObj; + longTermInvestments: RawNumberObj; + propertyPlantEquipment: RawNumberObj; + otherAssets: RawNumberObj; + totalAssets: RawNumberObj; + accountsPayable: RawNumberObj; + shortLongTermDebt?: RawNumberObj; + otherCurrentLiab: RawNumberObj; + longTermDebt: RawNumberObj; + otherLiab: RawNumberObj; + totalCurrentLiabilities: RawNumberObj; + totalLiab: RawNumberObj; + commonStock?: RawNumberObj; + retainedEarnings: RawNumberObj; + treasuryStock: RawNumberObj; + otherStockholderEquity: RawNumberObj; + totalStockholderEquity: RawNumberObj; + netTangibleAssets: RawNumberObj; + goodWill?: RawNumberObj; + intangibleAssets?: RawNumberObj; + deferredLongTermAssetCharges?: RawNumberObj; + deferredLongTermLiab?: RawNumberObj; + minorityInterest?: RawNumberObj; + capitalSurplus?: RawNumberObj; +} + +export interface RawNumberObj { + raw?: number; + fmt?: null | string; + longFmt?: string; } export interface CalendarEvents { @@ -160,27 +162,27 @@ export interface CashflowStatementHistory { export interface CashflowStatement { maxAge: number; - endDate: DateObj; - netIncome: ExercisedValue; - depreciation: ExercisedValue; - changeToNetincome: ExercisedValue; - changeToAccountReceivables?: ExercisedValue; - changeToLiabilities: ExercisedValue; - changeToInventory?: ExercisedValue; - changeToOperatingActivities?: ExercisedValue; - totalCashFromOperatingActivities: ExercisedValue; - capitalExpenditures: ExercisedValue; - investments?: ExercisedValue; - otherCashflowsFromInvestingActivities: ExercisedValue; - totalCashflowsFromInvestingActivities: ExercisedValue; - dividendsPaid?: ExercisedValue; - netBorrowings: ExercisedValue; - otherCashflowsFromFinancingActivities: ExercisedValue; - totalCashFromFinancingActivities: ExercisedValue; - changeInCash: ExercisedValue; - repurchaseOfStock?: ExercisedValue; - issuanceOfStock?: ExercisedValue; - effectOfExchangeRate?: ExercisedValue; + endDate: RawNumberObj; + netIncome: RawNumberObj; + depreciation: RawNumberObj; + changeToNetincome: RawNumberObj; + changeToAccountReceivables?: RawNumberObj; + changeToLiabilities: RawNumberObj; + changeToInventory?: RawNumberObj; + changeToOperatingActivities?: RawNumberObj; + totalCashFromOperatingActivities: RawNumberObj; + capitalExpenditures: RawNumberObj; + investments?: RawNumberObj; + otherCashflowsFromInvestingActivities: RawNumberObj; + totalCashflowsFromInvestingActivities: RawNumberObj; + dividendsPaid?: RawNumberObj; + netBorrowings: RawNumberObj; + otherCashflowsFromFinancingActivities: RawNumberObj; + totalCashFromFinancingActivities: RawNumberObj; + changeInCash: RawNumberObj; + repurchaseOfStock?: RawNumberObj; + issuanceOfStock?: RawNumberObj; + effectOfExchangeRate?: RawNumberObj; } export interface DefaultKeyStatistics { @@ -269,43 +271,50 @@ export interface EarningsHistory { export interface EarningsHistoryHistory { maxAge: number; - epsActual: DateObj; - epsEstimate: DateObj; - epsDifference: DateObj; - surprisePercent: DateObj; - quarter: DateObj; + epsActual: RawNumberObj; + epsEstimate: RawNumberObj; + epsDifference: RawNumberObj; + surprisePercent: RawNumberObj; + quarter: RawNumberObj; period: string; } -export interface EarningsTrend { +export interface EarningsTrendJson { + trend: EarningsTrendTrendJson[]; + maxAge: number; +} +export interface EarningsTrend extends Omit { trend: EarningsTrendTrend[]; maxAge: number; } -export interface EarningsTrendTrend { +export interface EarningsTrendTrendJson { maxAge: number; period: string; - endDate: Date | null; - growth: DateObj; + endDate: string | null; + growth: RawNumberObj; earningsEstimate: EarningsEstimate; revenueEstimate: RevenueEstimate; epsTrend: EpsTrend; epsRevisions: EpsRevisions; } +export interface EarningsTrendTrend extends Omit { + endDate: Date; +} export interface EarningsEstimate { - avg: DateObj; - low: DateObj; - high: DateObj; - yearAgoEps: DateObj; - numberOfAnalysts: ExercisedValue; - growth: DateObj; + avg: RawNumberObj; + low: RawNumberObj; + high: RawNumberObj; + yearAgoEps: RawNumberObj; + numberOfAnalysts: RawNumberObj; + growth: RawNumberObj; } export interface EpsRevisions { - upLast7days: ExercisedValue; - upLast30days: ExercisedValue; - downLast30days: ExercisedValue; + upLast7days: RawNumberObj; + upLast30days: RawNumberObj; + downLast30days: RawNumberObj; downLast90days: DiscontinuedOperations; } @@ -313,20 +322,20 @@ export interface DiscontinuedOperations { } export interface EpsTrend { - current: DateObj; - "7daysAgo": DateObj; - "30daysAgo": DateObj; - "60daysAgo": DateObj; - "90daysAgo": DateObj; + current: RawNumberObj; + "7daysAgo": RawNumberObj; + "30daysAgo": RawNumberObj; + "60daysAgo": RawNumberObj; + "90daysAgo": RawNumberObj; } export interface RevenueEstimate { - avg: ExercisedValue; - low: ExercisedValue; - high: ExercisedValue; - numberOfAnalysts: ExercisedValue; - yearAgoRevenue: ExercisedValue; - growth: DateObj; + avg: RawNumberObj; + low: RawNumberObj; + high: RawNumberObj; + numberOfAnalysts: RawNumberObj; + yearAgoRevenue: RawNumberObj; + growth: RawNumberObj; } export interface FinancialData { @@ -369,11 +378,11 @@ export interface Ownership { export interface OwnershipList { maxAge: number; - reportDate: DateObj; + reportDate: RawNumberObj; organization: string; - pctHeld: DateObj; - position: ExercisedValue; - value: ExercisedValue; + pctHeld: RawNumberObj; + position: RawNumberObj; + value: RawNumberObj; } export interface IncomeStatementHistory { @@ -383,29 +392,29 @@ export interface IncomeStatementHistory { export interface IncomeStatementHistoryElement { maxAge: number; - endDate: DateObj; - totalRevenue: ExercisedValue; - costOfRevenue: ExercisedValue; - grossProfit: ExercisedValue; - researchDevelopment: ExercisedValue; - sellingGeneralAdministrative: ExercisedValue; + endDate: RawNumberObj; + totalRevenue: RawNumberObj; + costOfRevenue: RawNumberObj; + grossProfit: RawNumberObj; + researchDevelopment: RawNumberObj; + sellingGeneralAdministrative: RawNumberObj; nonRecurring: DiscontinuedOperations; - otherOperatingExpenses: ExercisedValue; - totalOperatingExpenses: ExercisedValue; - operatingIncome: ExercisedValue; - totalOtherIncomeExpenseNet: ExercisedValue; - ebit: ExercisedValue; - interestExpense: ExercisedValue; - incomeBeforeTax: ExercisedValue; - incomeTaxExpense: ExercisedValue; - minorityInterest: ExercisedValue; - netIncomeFromContinuingOps: ExercisedValue; + otherOperatingExpenses: RawNumberObj; + totalOperatingExpenses: RawNumberObj; + operatingIncome: RawNumberObj; + totalOtherIncomeExpenseNet: RawNumberObj; + ebit: RawNumberObj; + interestExpense: RawNumberObj; + incomeBeforeTax: RawNumberObj; + incomeTaxExpense: RawNumberObj; + minorityInterest: RawNumberObj; + netIncomeFromContinuingOps: RawNumberObj; discontinuedOperations: DiscontinuedOperations; extraordinaryItems: DiscontinuedOperations; effectOfAccountingCharges: DiscontinuedOperations; otherItems: DiscontinuedOperations; - netIncome: ExercisedValue; - netIncomeApplicableToCommonShares: ExercisedValue; + netIncome: RawNumberObj; + netIncomeApplicableToCommonShares: RawNumberObj; } export interface IndexTrend { @@ -438,11 +447,11 @@ export interface Holder { relation: Relation; url: string; transactionDescription: string; - latestTransDate: DateObj; - positionDirect?: ExercisedValue; - positionDirectDate?: DateObj; - positionIndirect?: ExercisedValue; - positionIndirectDate?: DateObj; + latestTransDate: RawNumberObj; + positionDirect?: RawNumberObj; + positionDirectDate?: RawNumberObj; + positionIndirect?: RawNumberObj; + positionIndirectDate?: RawNumberObj; } export enum Relation { @@ -467,15 +476,15 @@ export interface InsiderTransactions { export interface Transaction { maxAge: number; - shares: ExercisedValue; + shares: RawNumberObj; filerUrl: string; transactionText: string; filerName: string; filerRelation: Relation; moneyText: string; - startDate: DateObj; + startDate: RawNumberObj; ownership: OwnershipEnum; - value?: ExercisedValue; + value?: RawNumberObj; } export enum OwnershipEnum { @@ -585,19 +594,29 @@ export interface RecommendationTrendTrend { strongSell: number; } -export interface SECFilings { +export interface SECFilingsJson { + filings: FilingJson[]; + maxAge: number; +} +export interface SECFilings extends Omit { filings: Filing[]; maxAge: number; } -export interface Filing { - date: Date; +export interface FilingJson { + date: string; epochDate: number; type: Type; title: string; edgarUrl: string; maxAge: number; } +export interface Filing extends Omit { +// date: Date; +// epochDate: number; + date: String; // TODO + epochDate: Date; +} export enum Type { The10K = "10-K", diff --git a/src/modules/quoteSummary.spec.ts b/src/modules/quoteSummary.spec.ts index 8f8682b9..13c727ce 100644 --- a/src/modules/quoteSummary.spec.ts +++ b/src/modules/quoteSummary.spec.ts @@ -95,7 +95,6 @@ describe('quoteSummary', () => { }); - /* describe('earningsTrend', () => { it('validates', async () => { @@ -104,7 +103,6 @@ describe('quoteSummary', () => { }); }); - */ describe('financialData', () => { @@ -241,7 +239,6 @@ describe('quoteSummary', () => { }); - /* describe('secFilings', () => { it('validates', async () => { @@ -250,7 +247,6 @@ describe('quoteSummary', () => { }); }); - */ describe('summaryDetail', () => { diff --git a/src/modules/quoteSummary.ts b/src/modules/quoteSummary.ts index 6212b1ac..d63a5a7e 100644 --- a/src/modules/quoteSummary.ts +++ b/src/modules/quoteSummary.ts @@ -1,7 +1,7 @@ -import dotProp = require('dot-prop'); - import yahooFinanceFetch = require('../lib/yahooFinanceFetch'); import validate from '../lib/validate'; +import transformField from '../lib/transformField'; +import mutateJson from '../lib/mutateJson'; //import { SummaryDetail, SummaryDetailJson } from './quoteSummary/summaryDetail'; //import { Price, PriceJson } from './quoteSummary/price'; @@ -88,7 +88,7 @@ type QuoteSummaryModules = "upgradeDowngradeHistory" ; -export const quoteSummary_dateFields = { +export const fieldTransformMap = { assetProfile: { governanceEpochDate: 'epoch', compensationAsOfEpochDate: 'epoch', @@ -161,7 +161,7 @@ export const quoteSummary_dateFields = { firstTradeDateEpochUtc: 'epoch', }, summaryDetail: { - exDividendDate: 'ISODate' // not epoch like calendarEvents.exDividendDate + exDividendDate: 'epoch|ISODate' // not epoch like calendarEvents.exDividendDate }, upgradeDowngradeHistory: { history: { @@ -169,14 +169,14 @@ export const quoteSummary_dateFields = { } }, price: { - // these were num?? auto detecgt?? XXX TODO postMarketTime: 'epoch|ISODate', preMarketTime: 'epoch|ISODate', regularMarketTime: 'epoch|ISODate', }, secFilings: { // "date": "2021-01-28", "epochDate": 1611831743 - filings: [ 'objWithEpochDate' ] + // TODO filings: [ 'objWithEpochDate' ], + filings: [ { epochDate: 'epoch' } ], }, }; @@ -243,5 +243,7 @@ export default async function quoteSummary( // useful to comment this out when working on new modules validate(actualResult, QUERY_RESULT_SCHEMA_KEY); + mutateJson(actualResult, fieldTransformMap, transformField); + return actualResult; }