UNPKG

isoxml

Version:

JavaScript library to parse and generate ISOXML (ISO11783-10) files

112 lines (111 loc) 2.67 kB
import { TAGS } from './constants'; import { registerEntityClass } from '../classRegistry'; import { fromXML, toXML } from '../utils'; const ATTRIBUTES = { A: { name: 'CustomerId', type: 'xs:ID', isPrimaryId: true, isOptional: false, isOnlyV4: false, }, B: { name: 'CustomerLastName', type: 'xs:string', isPrimaryId: false, isOptional: false, isOnlyV4: false, }, C: { name: 'CustomerFirstName', type: 'xs:string', isPrimaryId: false, isOptional: true, isOnlyV4: false, }, D: { name: 'CustomerStreet', type: 'xs:string', isPrimaryId: false, isOptional: true, isOnlyV4: false, }, E: { name: 'CustomerPOBox', type: 'xs:string', isPrimaryId: false, isOptional: true, isOnlyV4: false, }, F: { name: 'CustomerPostalCode', type: 'xs:string', isPrimaryId: false, isOptional: true, isOnlyV4: false, }, G: { name: 'CustomerCity', type: 'xs:string', isPrimaryId: false, isOptional: true, isOnlyV4: false, }, H: { name: 'CustomerState', type: 'xs:string', isPrimaryId: false, isOptional: true, isOnlyV4: false, }, I: { name: 'CustomerCountry', type: 'xs:string', isPrimaryId: false, isOptional: true, isOnlyV4: false, }, J: { name: 'CustomerPhone', type: 'xs:string', isPrimaryId: false, isOptional: true, isOnlyV4: false, }, K: { name: 'CustomerMobile', type: 'xs:string', isPrimaryId: false, isOptional: true, isOnlyV4: false, }, L: { name: 'CustomerFax', type: 'xs:string', isPrimaryId: false, isOptional: true, isOnlyV4: false, }, M: { name: 'CustomerEMail', type: 'xs:string', isPrimaryId: false, isOptional: true, isOnlyV4: false, }, }; const CHILD_TAGS = {}; export class Customer { constructor(attributes, isoxmlManager) { this.attributes = attributes; this.isoxmlManager = isoxmlManager; this.tag = TAGS.Customer; } static fromXML(xml, isoxmlManager, internalId, targetClass = Customer) { return fromXML(xml, isoxmlManager, targetClass, ATTRIBUTES, CHILD_TAGS, internalId); } toXML() { return toXML(this, ATTRIBUTES, CHILD_TAGS); } } registerEntityClass('main', TAGS.Customer, Customer);