UNPKG

jspurefix

Version:
142 lines 5.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContainedSetBuilder = void 0; const contained_field_type_1 = require("./contained-field-type"); const tag_type_1 = require("../../buffer/tag/tag-type"); class ContainedSetBuilder { constructor(set) { this.set = set; } add(field) { this.set.fields.push(field); this.set.localNameToField.set(field.name, field); this.addUpdate(field); this.addContained(this.set, field); } addUpdate(field) { switch (field.type) { case contained_field_type_1.ContainedFieldType.Simple: { this.addLocalSimple(field); break; } case contained_field_type_1.ContainedFieldType.Component: { const cf = field; const definition = cf.definition; if (definition.abbreviation && definition.abbreviation !== field.name) { this.set.localNameToField.set(definition.abbreviation, field); } break; } case contained_field_type_1.ContainedFieldType.Group: { const gf = field; const definition = gf.definition; if (definition.abbreviation && definition.abbreviation !== field.name) { this.set.localNameToField.set(definition.abbreviation, field); } break; } default: throw new Error(`unknown field type ${field.type}`); } } addLocalSimple(field) { const definition = field.definition; if (definition.abbreviation && definition.abbreviation !== definition.name) { this.set.localNameToField.set(definition.abbreviation, field); } if (definition.baseCategoryAbbreviation && definition.baseCategory === this.set.category) { this.set.localNameToField.set(definition.baseCategoryAbbreviation, field); } if (field.attribute) { this.set.nameToLocalAttribute.set(definition.abbreviation, field); this.set.localAttribute.push(field); this.set.fields.pop(); } const tag = definition.tag; this.set.localTag[tag] = field; if (field.required) { this.set.localRequired[tag] = field; } } addContained(parent, field) { switch (field.type) { case contained_field_type_1.ContainedFieldType.Group: { this.addGroupFieldDef(field); break; } case contained_field_type_1.ContainedFieldType.Component: { this.addComponentFieldDef(field); break; } case contained_field_type_1.ContainedFieldType.Simple: { this.addSimpleFieldDef(parent, field); break; } default: throw new Error(`unknown field type ${field.type}`); } } addGroupFieldDef(groupField) { if (this.set.groups.has(groupField.name)) { return; } const definition = groupField.definition; this.set.groups.set(groupField.name, definition); const nof = definition.noOfField; if (nof) { const tag = nof.tag; this.set.containedTag[tag] = true; this.set.flattenedTag.push(tag); } this.addAllFields(definition); this.mapAllBelow(definition, groupField); } addComponentFieldDef(componentField) { const components = this.set.components; if (components.has(componentField.name)) { return; } const definition = componentField.definition; components.set(componentField.name, definition); this.addAllFields(definition); this.mapAllBelow(definition, componentField); } mapAllBelow(set, field) { const tagsBelow = set.keys(); for (const t of tagsBelow) { this.set.tagToField[t] = field; } } addSimpleFieldDef(parent, field) { if (this.set.simple.has(field.name)) { return; } if (!this.set.firstSimple) { this.set.firstSimple = field; } switch (field.definition.tagType) { case tag_type_1.TagType.RawData: { const dataLengthField = parent.fields[field.position - 1]; if (dataLengthField && dataLengthField.definition.tagType === tag_type_1.TagType.Length) { this.set.containedLength[dataLengthField.definition.tag] = true; this.set.containsRaw = true; } break; } default: break; } const tag = field.definition.tag; this.set.simple.set(field.name, field); this.set.containedTag[tag] = true; this.set.flattenedTag.push(tag); this.set.tagToSimple[tag] = field; } addAllFields(containedField) { containedField.fields.forEach((f) => { this.addContained(containedField, f); }); } } exports.ContainedSetBuilder = ContainedSetBuilder; //# sourceMappingURL=contained-set-builder.js.map