UNPKG

@makakwastaken/ts-edifact

Version:
56 lines 2.33 kB
/** * @author Stefan Partheymüller * @copyright 2021 Stefan Partheymüller * @license Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { UNECEMessageStructureParser, } from './messageStructureParser'; import { UNECEMetaDataPageParser } from './uneceMetaDataPageParser'; import { UNECEStructurePageParser } from './uneceStructurePageParser'; export class UNECELegacyMessageStructureParser extends UNECEMessageStructureParser { parseMetaDataPage(page) { const parser = new UNECEMetaDataPageParser(); parser.parse(page); return parser.spec; } parseStructurePage(page, spec) { const parser = new UNECEStructurePageParser(spec); parser.parse(page); return parser.segmentNames; } loadTypeSpec() { const url = `./${this.type}_c.htm`; return this.loadPage(url) .then(async (metaDataPage) => { const spec = this.parseMetaDataPage(metaDataPage); const structurePage = await this.loadPage(`./${this.type}_s.htm`); const segmentNames = this.parseStructurePage(structurePage, spec); const promises = segmentNames.map(async (name) => { const page = await this.loadPage(`../trsd/trsd${name.toLowerCase()}.htm`); return this.parseSegmentDefinitionPage(name, page, spec); }); return { specObj: spec, promises, }; }) .then((result) => Promise.all(result.promises) .then(() => result.specObj) .catch((error) => { console.warn(`Error while processing segment definition promises: Reason ${error.message}`); return result.specObj; })); } } //# sourceMappingURL=legacyMessageStructureParser.js.map