From bd1e002a55f962e2081c1506de3b32dcddda6f70 Mon Sep 17 00:00:00 2001 From: Jan Loewe <jan.loewe@ptb.de> Date: Tue, 14 Feb 2023 13:31:39 +0100 Subject: [PATCH] feat(administrativeData): add refTypeDefinitions and fix naming collision --- src/BaseTypes/INamespaced.ts | 2 +- src/DCC.ts | 46 ++++++++++++++++++++++++++++++++---- src/DCCDocument.ts | 2 +- src/DSI.ts | 10 ++++---- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/BaseTypes/INamespaced.ts b/src/BaseTypes/INamespaced.ts index 86fff83..595830e 100644 --- a/src/BaseTypes/INamespaced.ts +++ b/src/BaseTypes/INamespaced.ts @@ -1,3 +1,3 @@ export interface INamespaced { - get namespace(): string; + get ns(): string; } diff --git a/src/DCC.ts b/src/DCC.ts index f7bb65b..c2cdab9 100644 --- a/src/DCC.ts +++ b/src/DCC.ts @@ -15,31 +15,31 @@ export const DCC: ISchemaInformation = { }; export class DCCXMLElement extends XMLElement implements INamespaced { - get namespace() { + get ns() { return DCC.namespace; } } export class DCCXMLBoolean extends XMLBoolean implements INamespaced { - get namespace() { + get ns() { return DCC.namespace; } } export class DCCXMLNumber extends XMLNumber implements INamespaced { - get namespace() { + get ns() { return DCC.namespace; } } export class DCCXMLDate extends XMLDate implements INamespaced { - get namespace() { + get ns() { return DCC.namespace; } } export class DCCXMLList extends XMLList implements INamespaced { - get namespace() { + get ns() { return DCC.namespace; } } @@ -89,6 +89,7 @@ export class DigitalCalibrationCertificateType extends DCCXMLElement { * The entries in this area are basically the same and regulated in all DCCs. */ export class AdministrativeDataType extends DCCXMLElement { dccSoftware: SoftwareListType; + refTypeDefinitions?: RefTypeDefinitionListType; coreData: CoreDataType; items: ItemListType; calibrationLaboratory: CalibrationLaboratoryType; @@ -99,6 +100,7 @@ export class AdministrativeDataType extends DCCXMLElement { constructor(el: Partial<AdministrativeDataType> = {}) { super(el); this.dccSoftware = new SoftwareListType(el.dccSoftware); + if (el.refTypeDefinitions) this.refTypeDefinitions = new RefTypeDefinitionListType(el.refTypeDefinitions); this.coreData = new CoreDataType(el.coreData); this.items = new ItemListType(el.items); this.calibrationLaboratory = new CalibrationLaboratoryType(el.calibrationLaboratory); @@ -108,6 +110,40 @@ export class AdministrativeDataType extends DCCXMLElement { } } +/* This type allows the give information about the used refTypes in a DCC. */ +export class RefTypeDefinitionListType extends DCCXMLElement { + refTypeDefinition: RefTypeDefinitionType[]; + + constructor(el: Partial<RefTypeDefinitionListType> = {}) { + super(el); + this.refTypeDefinition = ensureArray(el.refTypeDefinition).map((x) => new RefTypeDefinitionType(x)); + } +} + +/* This type contains the information about the wording of the refTypes used in a DCC. */ +export class RefTypeDefinitionType extends DCCXMLElement { + _attr: IIdAndRefTypeAttributes; + + name: TextType; + description?: RichContentType; + namespace: DCCXMLElement; + link: DCCXMLElement; + release?: DCCXMLElement; + value?: DCCXMLElement; + procedure?: DCCXMLElement; + + constructor(el: Partial<RefTypeDefinitionType> = {}) { + super(el); + this.name = new TextType(el.name); + if (el.description) this.description = new RichContentType(el.description); + this.namespace = new DCCXMLElement(el.namespace); + this.link = new DCCXMLElement(el.link); + if (el.release) this.release = new DCCXMLElement(el.release); + if (el.value) this.value = new DCCXMLElement(el.value); + if (el.procedure) this.procedure = new DCCXMLElement(el.procedure); + } +} + /** List of measurement results that are part of a DCC. */ export class MeasurementResultListType extends DCCXMLElement { measurementResult: MeasurementResultType[]; diff --git a/src/DCCDocument.ts b/src/DCCDocument.ts index 4cb7278..04592c1 100644 --- a/src/DCCDocument.ts +++ b/src/DCCDocument.ts @@ -66,7 +66,7 @@ export class DCCDocument { elementNameFn: function (val, currentElementObj) { // eslint-disable-next-line @typescript-eslint/no-explicit-any const currentElement = <any>currentElementObj; - return `${currentElement?.namespace ? `${currentElement.namespace}:` : ""}${val}`; + return `${currentElement?.ns ? `${currentElement.ns}:` : ""}${val}`; }, }); } diff --git a/src/DSI.ts b/src/DSI.ts index 0a992cc..a17c2a6 100644 --- a/src/DSI.ts +++ b/src/DSI.ts @@ -13,31 +13,31 @@ export const DSI: ISchemaInformation = { }; export class SIXMLElement extends XMLElement implements INamespaced { - get namespace() { + get ns() { return DSI.namespace; } } export class SIXMLBoolean extends XMLBoolean implements INamespaced { - get namespace() { + get ns() { return DSI.namespace; } } export class SIXMLDate extends XMLDate implements INamespaced { - get namespace() { + get ns() { return DSI.namespace; } } export class SIXMLNumber extends XMLNumber implements INamespaced { - get namespace() { + get ns() { return DSI.namespace; } } export class SIXMLList extends XMLList implements INamespaced { - get namespace() { + get ns() { return DSI.namespace; } } -- GitLab