From 40b3654ca4d3aec749026bc182a2057c3b107084 Mon Sep 17 00:00:00 2001 From: Jan Loewe <jan.loewe@ptb.de> Date: Wed, 23 Feb 2022 09:48:44 +0100 Subject: [PATCH] feat(attributes): add typings for attributes --- package.json | 2 +- src/BaseTypes/XMLElement.ts | 15 ++---- src/DCC.ts | 103 ++++++++++++++++++++++++++++++++++-- src/DCCDocument.ts | 9 +++- 4 files changed, 113 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 4d9536a..57f9f8e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@d-ptb/dcc-js", "version": "1.2.3", - "author": "Jan Henry Loewe <kontakt@jloewe.net>", + "author": "Jan Loewe <jan.loewe@ptb.de>", "main": "lib/index.js", "typings": "lib/index.d.ts", "scripts": { diff --git a/src/BaseTypes/XMLElement.ts b/src/BaseTypes/XMLElement.ts index ed09433..2452dc3 100644 --- a/src/BaseTypes/XMLElement.ts +++ b/src/BaseTypes/XMLElement.ts @@ -1,17 +1,10 @@ -export type AttributeType = { - "xmlns:xsi"?: string; - "xsi:schemaLocation"?: string; - "xmlns:dcc"?: string; - "xmlns:si"?: string; - schemaVersion?: string; - - lang?: string; - id?: string; -}; +export interface IAttributes { + [key: string]: string; +} export class XMLElement { _text?: string; - _attr?: AttributeType; + _attr?: IAttributes; constructor(element?: Partial<XMLElement>) { this._text = (element && element._text) || ""; diff --git a/src/DCC.ts b/src/DCC.ts index e5f3b2f..f2f48ee 100644 --- a/src/DCC.ts +++ b/src/DCC.ts @@ -1,11 +1,21 @@ import * as si from "./DSI"; -import { XMLDate, XMLElement, XMLNumber, XMLBoolean, XMLList, INamespaced, ISchemaInformation } from "./BaseTypes"; +import { + XMLDate, + XMLElement, + XMLNumber, + XMLBoolean, + XMLList, + INamespaced, + ISchemaInformation, + IAttributes, +} from "./BaseTypes"; import { ensureArray } from "./Util"; const schemaVersion = "3.1.1"; const namespace = "dcc"; const namespaceUrl = `https://ptb.de/${namespace}`; const schemaLocation = `${namespaceUrl}/v${schemaVersion}/dcc.xsd`; + export const DCC: ISchemaInformation = { schemaVersion, namespace, @@ -43,8 +53,33 @@ export class DCCXMLList extends XMLList implements INamespaced { } } +export interface IIdAttributes extends IAttributes { + id?: string; +} + +export interface IIdAndRefTypeAttributes extends IAttributes { + id?: string; + refType?: string; +} + +export interface IIdAndRefIdAndRefTypeAttributes extends IAttributes { + id?: string; + refId?: string; + refType?: string; +} + +export interface IDigitalCalibrationCertificateAttributes extends IAttributes { + "xmlns:xsi"?: string; + "xsi:schemaLocation"?: string; + "xmlns:dcc"?: string; + "xmlns:si"?: string; + schemaVersion?: string; +} + /** The root element that contains the four rings of the DCC. */ export class DigitalCalibrationCertificateType extends DCCXMLElement { + _attr: IDigitalCalibrationCertificateAttributes; + administrativeData: AdministrativeDataType; measurementResults: MeasurementResultListType; comment?: DCCXMLElement; @@ -95,6 +130,8 @@ export class MeasurementResultListType extends DCCXMLElement { /** The byteDataType defines a type which allows to add binary encoded files to the measurement result * section. */ export class ByteDataType extends DCCXMLElement { + _attr: IIdAttributes; + name?: TextType; description?: RichContentType; fileName: DCCXMLElement; @@ -131,7 +168,7 @@ export class CoreDataType extends DCCXMLElement { receiptDate?: DCCXMLDate; beginPerformanceDate: DCCXMLDate; endPerformanceDate: DCCXMLDate; - performanceLocation: DCCXMLElement; + performanceLocation: PerformanceLocationType; previousReport?: HashType; constructor(el: Partial<CoreDataType> = {}) { @@ -144,11 +181,19 @@ export class CoreDataType extends DCCXMLElement { if (el.receiptDate) this.receiptDate = new DCCXMLDate(el.receiptDate); this.beginPerformanceDate = new DCCXMLDate(el.beginPerformanceDate); this.endPerformanceDate = new DCCXMLDate(el.endPerformanceDate); - this.performanceLocation = new DCCXMLElement(el.performanceLocation); + this.performanceLocation = new PerformanceLocationType(el.performanceLocation); if (el.previousReport) this.previousReport = new HashType(el.previousReport); } } +export class PerformanceLocationType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + + constructor(el: Partial<PerformanceLocationType> = {}) { + super(el); + } +} + /** This element is a set of calibrated items. * Contains one or more item elements. */ export class ItemListType extends DCCXMLElement { @@ -193,6 +238,8 @@ export class RespPersonListType extends DCCXMLElement { } export class ContactType extends DCCXMLElement { + _attr: IIdAttributes; + name: TextType; eMail: DCCXMLElement; phone?: DCCXMLElement; @@ -223,6 +270,8 @@ export class StatementListType extends DCCXMLElement { /** Information about a software including its name, version and a description. */ export class SoftwareType extends DCCXMLElement { + _attr: IIdAndRefTypeAttributes; + name: TextType; release: DCCXMLElement; type?: DCCXMLElement; @@ -248,6 +297,8 @@ export class RefTypesType extends DCCXMLElement { * In this Type, the element content can be used many times with different language definition (attribute * lang). */ export class TextType extends DCCXMLElement { + _attr: IIdAttributes; + content: StringWithLangType[]; constructor(el: Partial<TextType> = {}) { @@ -284,6 +335,8 @@ export class TextType extends DCCXMLElement { /** Rich content Type can contain files and formulas beside the normal text content. */ export class RichContentType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + name?: TextType; content?: StringWithLangType[]; file?: ByteDataType[]; @@ -348,6 +401,8 @@ export class MeasuringEquipmentListType extends DCCXMLElement { /** Clear name(s) of the item(s) and identifier(s). */ export class EquipmentClassType extends DCCXMLElement { + _attr: IIdAttributes; + reference: DCCXMLElement; classID: DCCXMLElement; @@ -370,6 +425,8 @@ export class IdentificationListType extends DCCXMLElement { /** Information about a measuring equipment or instrument used in the calibration */ export class MeasuringEquipmentType extends DCCXMLElement { + _attr: IIdAndRefTypeAttributes; + name: TextType; equipmentClass?: EquipmentClassType; description?: RichContentType; @@ -393,6 +450,8 @@ export class MeasuringEquipmentType extends DCCXMLElement { } export class HashType extends DCCXMLElement { + _attr: IIdAttributes; + referral: TextType; referralID: DCCXMLElement; procedure: DCCXMLElement; @@ -410,6 +469,8 @@ export class HashType extends DCCXMLElement { } export class ContactNotStrictType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + name: TextType; eMail?: DCCXMLElement; phone?: DCCXMLElement; @@ -440,6 +501,8 @@ export class MeasuringEquipmentQuantityListType extends DCCXMLElement { /** Value which describes the measuringEquipment */ export class MeasuringEquipmentQuantityType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + name?: TextType; description?: RichContentType; @@ -597,6 +660,8 @@ export class MeasuringEquipmentQuantityType extends DCCXMLElement { /** A item that is calibrated in this DCC. */ export class ItemType extends DCCXMLElement { + _attr: IIdAttributes; + name: TextType; equipmentClass?: EquipmentClassType; description?: RichContentType; @@ -619,6 +684,8 @@ export class ItemType extends DCCXMLElement { /** An additional identification (eg. reference no., serial number, etc.). */ export class IdentificationType extends DCCXMLElement { + _attr: IIdAndRefTypeAttributes; + issuer: DCCXMLElement; value: DCCXMLElement; name?: TextType; @@ -633,6 +700,8 @@ export class IdentificationType extends DCCXMLElement { /** A person responsible for a DCC. */ export class RespPersonType extends DCCXMLElement { + _attr: IIdAttributes; + person: ContactNotStrictType; description?: RichContentType; role?: DCCXMLElement; @@ -654,6 +723,8 @@ export class RespPersonType extends DCCXMLElement { } export class StatementMetaDataType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + countryCodeISO3166_1?: DCCXMLElement[]; convention?: DCCXMLElement; traceable?: DCCXMLBoolean; @@ -700,6 +771,8 @@ export class StatementMetaDataType extends DCCXMLElement { /** A measurement results with the methods, software and equipments used for the calibration. * Also contains influence conditions and a list of the actual results. */ export class MeasurementResultType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + name: TextType; description?: RichContentType; usedMethods?: UsedMethodListType; @@ -764,6 +837,8 @@ export class MeasurementMetaDataListType extends DCCXMLElement { /** A method used in the calibration. */ export class UsedMethodType extends DCCXMLElement { + _attr: IIdAndRefTypeAttributes; + name: TextType; description?: RichContentType; norm?: DCCXMLElement[]; @@ -781,6 +856,8 @@ export class UsedMethodType extends DCCXMLElement { /** Condition (e.g. environmental) under which the calibrations were performed which have an influence on * the measurement results. */ export class ConditionType extends DCCXMLElement { + _attr: IIdAndRefTypeAttributes; + name: TextType; description?: RichContentType; status?: DCCXMLElement; @@ -798,6 +875,8 @@ export class ConditionType extends DCCXMLElement { } export class DataType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + // region choice text?: RichContentType[]; formula?: FormulaType[]; @@ -823,6 +902,8 @@ export class DataType extends DCCXMLElement { /** The actual result of the calibration. */ export class ResultType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + name: TextType; description?: RichContentType; data: DataType; @@ -837,6 +918,8 @@ export class ResultType extends DCCXMLElement { /** This data block is used to add formulas and equations to the measurement result section of the DCC. */ export class FormulaType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + // region choice latex?: DCCXMLElement; mathml?: XmlType; @@ -854,6 +937,8 @@ export class FormulaType extends DCCXMLElement { /** This data block is used to add user or application specific XML content. */ export class XmlType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + constructor(el: Partial<XmlType> = {}) { super(el); } @@ -864,6 +949,8 @@ export class XmlType extends DCCXMLElement { * added. * Measurement metadata can also be added. */ export class QuantityType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + name?: TextType; description?: RichContentType; @@ -1048,6 +1135,8 @@ export class QuantityType extends DCCXMLElement { * may also be used to give measurement results in combination with some * ambient conditions at the measurement. */ export class ListType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + name?: TextType; description?: RichContentType; usedMethods?: UsedMethodListType; @@ -1104,8 +1193,14 @@ export class RelativeUncertaintyType extends DCCXMLElement { } } +export interface IStringWithLangTypeAttributes extends IIdAndRefIdAndRefTypeAttributes { + lang?: string; +} + /** A string element with an additional lang attribute for localization. */ export class StringWithLangType extends DCCXMLElement { + _attr: IStringWithLangTypeAttributes; + constructor(el: Partial<StringWithLangType> = {}) { super(el); } @@ -1137,6 +1232,8 @@ export class LocationType extends DCCXMLElement { } export class PositionCoordinatesType extends DCCXMLElement { + _attr: IIdAndRefIdAndRefTypeAttributes; + positionCoordinateSystem: DCCXMLElement; reference?: DCCXMLElement; declaration?: RichContentType; diff --git a/src/DCCDocument.ts b/src/DCCDocument.ts index 481a153..4cb7278 100644 --- a/src/DCCDocument.ts +++ b/src/DCCDocument.ts @@ -3,8 +3,15 @@ import { Element, js2xml, xml2js } from "xml-js"; import { DigitalCalibrationCertificateType, DCC } from "./DCC"; import { DSI } from "./DSI"; +export interface IDeclaration { + _attr: { + version: string; + encoding: string; + }; +} + export class DCCDocument { - _declaration: unknown; + _declaration: IDeclaration; digitalCalibrationCertificate: DigitalCalibrationCertificateType; constructor(el?: Partial<DCCDocument>) { -- GitLab