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AAG;AACrG,cAAc;AACd,MAAM,OAAO,iBAAqD,SAAQ,YAAsB;IAI5F,YAAY,OAAsC;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAiB,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,cAAc;IACP,QAAQ,CAAC,KAAa,EAAE,KAAkB,EAAE,WAAoB;QACnE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,WAAY,CAAC,CAAC;QAC9D,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAE,CAAC,MAAM,CAAC,CAAC;QAC9D,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IACrD,CAAC;CACJ","file":"union.js","sourcesContent":["// Licensed to the Apache Software Foundation (ASF) under one\n// or more contributor license agreements. See the NOTICE file\n// distributed with this work for additional information\n// regarding copyright ownership. The ASF licenses this file\n// to you under the Apache License, Version 2.0 (the\n// \"License\"); you may not use this file except in compliance\n// with the License. You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing,\n// software distributed under the License is distributed on an\n// \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n// KIND, either express or implied. See the License for the\n// specific language governing permissions and limitations\n// under the License.\n\nimport { Field } from '../schema';\nimport { DataBufferBuilder } from './buffer';\nimport { Builder, BuilderOptions } from '../builder';\nimport { Union, SparseUnion, DenseUnion } from '../type';\n\nexport interface UnionBuilderOptions<T extends Union = any, TNull = any> extends BuilderOptions<T, TNull> {\n valueToChildTypeId?: (builder: UnionBuilder<T, TNull>, value: any, offset: number) => number;\n}\n\n/** @ignore */\nexport abstract class UnionBuilder<T extends Union, TNull = any> extends Builder<T, TNull> {\n\n protected _typeIds: DataBufferBuilder<Int8Array>;\n\n constructor(options: UnionBuilderOptions<T, TNull>) {\n super(options);\n this._typeIds = new DataBufferBuilder(new Int8Array(0), 1);\n if (typeof options['valueToChildTypeId'] === 'function') {\n this._valueToChildTypeId = options['valueToChildTypeId'];\n }\n }\n\n public get typeIdToChildIndex() { return this.type.typeIdToChildIndex; }\n\n public append(value: T['TValue'] | TNull, childTypeId?: number) {\n return this.set(this.length, value, childTypeId);\n }\n\n public set(index: number, value: T['TValue'] | TNull, childTypeId?: number) {\n if (childTypeId === undefined) {\n childTypeId = this._valueToChildTypeId(this, value, index);\n }\n if (this.setValid(index, this.isValid(value))) {\n this.setValue(index, value, childTypeId);\n }\n return this;\n }\n\n // @ts-ignore\n public setValue(index: number, value: T['TValue'], childTypeId?: number) {\n this._typeIds.set(index, childTypeId!);\n super.setValue(index, value);\n }\n\n // @ts-ignore\n public addChild(child: Builder, name = `${this.children.length}`) {\n const childTypeId = this.children.push(child);\n const { type: { children, mode, typeIds } } = this;\n const fields = [...children, new Field(name, child.type)];\n this.type = <T> new Union(mode, [...typeIds, childTypeId], fields);\n return childTypeId;\n }\n\n /** @ignore */\n // @ts-ignore\n protected _valueToChildTypeId(builder: UnionBuilder<T, TNull>, value: any, offset: number): number {\n throw new Error(`Cannot map UnionBuilder value to child typeId. \\\nPass the \\`childTypeId\\` as the second argument to unionBuilder.append(), \\\nor supply a \\`valueToChildTypeId\\` function as part of the UnionBuilder constructor options.`);\n }\n}\n\n/** @ignore */\nexport class SparseUnionBuilder<T extends SparseUnion, TNull = any> extends UnionBuilder<T, TNull> {}\n/** @ignore */\nexport class DenseUnionBuilder<T extends DenseUnion, TNull = any> extends UnionBuilder<T, TNull> {\n\n protected _offsets: DataBufferBuilder<Int32Array>;\n\n constructor(options: UnionBuilderOptions<T, TNull>) {\n super(options);\n this._offsets = new DataBufferBuilder(new Int32Array(0));\n }\n\n /** @ignore */\n public setValue(index: number, value: T['TValue'], childTypeId?: number) {\n const childIndex = this.type.typeIdToChildIndex[childTypeId!];\n this._offsets.set(index, this.getChildAt(childIndex)!.length);\n return super.setValue(index, value, childTypeId);\n }\n}\n"]}