UNPKG

@makakwastaken/ts-edifact

Version:
60 lines 2.62 kB
"use strict"; /** * @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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.UNECELegacyMessageStructureParser = void 0; const messageStructureParser_1 = require("./messageStructureParser"); const uneceMetaDataPageParser_1 = require("./uneceMetaDataPageParser"); const uneceStructurePageParser_1 = require("./uneceStructurePageParser"); class UNECELegacyMessageStructureParser extends messageStructureParser_1.UNECEMessageStructureParser { parseMetaDataPage(page) { const parser = new uneceMetaDataPageParser_1.UNECEMetaDataPageParser(); parser.parse(page); return parser.spec; } parseStructurePage(page, spec) { const parser = new uneceStructurePageParser_1.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; })); } } exports.UNECELegacyMessageStructureParser = UNECELegacyMessageStructureParser; //# sourceMappingURL=legacyMessageStructureParser.js.map