From aa7b6e3b15dc5f9bcde60d171619ca27d1a476eb Mon Sep 17 00:00:00 2001 From: Hexagon Date: Tue, 7 Feb 2023 22:42:23 +0100 Subject: [PATCH] Add missing exports --- mod.ts | 66 ++++++++++++++++++++++++++++++++++++++++- src/documents/common.ts | 2 +- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/mod.ts b/mod.ts index d4bf325..3128573 100644 --- a/mod.ts +++ b/mod.ts @@ -473,8 +473,72 @@ const QueryConfiguration = async (securityToken: string, params: QueryParameters return []; }; +/** + * Fetch and process Balancing_MarketDocument(s) + * + * Identifies the fetched docuement, validates key features, and returns an array of typed documents + * + * If the query yield smething other than Balancing_MarketDocument(s), an error will be thrown. + * + * @public + * + * @param securityToken - Entsoe API security token/key + * @param params - Object with all requested parameters + * + * @returns - Array of typed documents + */ +const QueryBalancing = async (securityToken: string, params: QueryParameters): Promise => { + const result = await Query(securityToken, params); + if (result && Array.isArray(result) && result.length && result[0].rootType === "balancing") return result as BalancingDocument[]; + if (result && Array.isArray(result) && result.length && result[0].rootType !== "balancing") throw new Error("Got " + result[0].rootType + " when expecting balancing document") + return []; +}; + +/** + * Fetch and process TransmissionNetwork_MarketDocument(s) + * + * Identifies the fetched docuement, validates key features, and returns an array of typed documents + * + * If the query yield smething other than TransmissionNetwork_MarketDocument(s), an error will be thrown. + * + * @public + * + * @param securityToken - Entsoe API security token/key + * @param params - Object with all requested parameters + * + * @returns - Array of typed documents + */ +const QueryTransmissionNetwork = async (securityToken: string, params: QueryParameters): Promise => { + const result = await Query(securityToken, params); + if (result && Array.isArray(result) && result.length && result[0].rootType === "transmissionnetwork") return result as TransmissionNetworkDocument[]; + if (result && Array.isArray(result) && result.length && result[0].rootType !== "transmissionnetwork") throw new Error("Got " + result[0].rootType + " when expecting transmissionnetwork document") + return []; +}; + +/** + * Fetch and process CriticalNetworkElement_MarketDocument(s) + * + * Identifies the fetched docuement, validates key features, and returns an array of typed documents + * + * If the query yield smething other than CriticalNetworkElement_MarketDocument(s), an error will be thrown. + * + * @public + * + * @param securityToken - Entsoe API security token/key + * @param params - Object with all requested parameters + * + * @returns - Array of typed documents + */ +const QueryCriticalNetworkElement = async (securityToken: string, params: QueryParameters): Promise => { + const result = await Query(securityToken, params); + if (result && Array.isArray(result) && result.length && result[0].rootType === "criticalnetworkelement") return result as CriticalNetworkElementDocument[]; + if (result && Array.isArray(result) && result.length && result[0].rootType !== "criticalnetworkelement") throw new Error("Got " + result[0].rootType + " when expecting criticalnetworkelement document") + return []; +}; + + /** Export all functions intended for public use */ -export { Query, QueryPublication, QueryGL, QueryUnavailability, QueryConfiguration }; +export { Query, QueryPublication, QueryGL, QueryUnavailability, QueryConfiguration, QueryBalancing, QueryTransmissionNetwork, QueryCriticalNetworkElement }; /** Export all types intended for public use */ export type { GLDocument, PublicationDocument, UnavailabilityDocument, ConfigurationDocument, QueryParameters, TransmissionNetworkDocument, CriticalNetworkElementDocument, BalancingDocument}; diff --git a/src/documents/common.ts b/src/documents/common.ts index f2fa0de..ea25905 100644 --- a/src/documents/common.ts +++ b/src/documents/common.ts @@ -123,7 +123,7 @@ interface Period { interface BaseDocument { mRID: string; revision?: number; - rootType?: "configuration" | "gl" | "unavailability" | "publication"; + rootType?: "configuration" | "gl" | "unavailability" | "publication" | "balancing" | "criticalnetworkelement" | "transmissionnetwork"; created?: Date; documentType: string; documentTypeDescription?: string;