export class PropertyDataMemberAccessor {
    constructor(propertyName) {
        this.propertyName = propertyName;
    }
    get(fromValue) {
        if (Array.isArray(fromValue)) {
            let output = [];
            for (let v of fromValue) {
                let vv = Reflect.get(v, this.propertyName);
                if (Array.isArray(vv)) {
                    // combine arrays
                    for (let vvVal of vv) {
                        output.push(vvVal);
                    }
                }
                else {
                    output.push(vv);
                }
            }
            return output;
        }
        return Reflect.get(fromValue, this.propertyName);
    }
    set(onValue, value) {
        Reflect.set(onValue, this.propertyName, value);
    }
}
export class ArrayItemDataMemberAccessor {
    constructor(index) {
        this.index = index;
    }
    get(fromValue) {
        if (Array.isArray(fromValue)) {
            if (fromValue.length <= this.index)
                throw new Error("fetching invalid array item");
            return fromValue[this.index];
        }
        else {
            throw new Error("value is not an array");
        }
    }
    set(onValue, value) {
        if (Array.isArray(onValue)) {
            if (onValue.length <= this.index)
                throw new Error("index is out of range");
            onValue[this.index] = value;
        }
        else {
            throw new Error("value is not an array");
        }
    }
}
export class ArrayFirstDataMemberAccessor {
    get(fromValue) {
        if (Array.isArray(fromValue)) {
            if (fromValue.length === 0)
                return null;
            return fromValue[0];
        }
        else {
            throw new Error("value is not an array");
        }
    }
    set(onValue, value) {
        if (Array.isArray(onValue)) {
            if (onValue.length === 0)
                throw new Error("index is out of range");
            onValue[0] = value;
        }
        else {
            throw new Error("value is not an array");
        }
    }
}
export class ArrayLastDataMemberAccessor {
    get(fromValue) {
        if (Array.isArray(fromValue)) {
            if (fromValue.length === 0)
                return null;
            return fromValue[fromValue.length - 1];
        }
        else {
            throw new Error("value is not an array");
        }
    }
    set(onValue, value) {
        if (Array.isArray(onValue)) {
            if (onValue.length === 0)
                throw new Error("index is out of range");
            onValue[onValue.length - 1] = value;
        }
        else {
            throw new Error("value is not an array");
        }
    }
}
export class ArrayAddDataMemberAccessor {
    get(fromValue) {
        if (Array.isArray(fromValue)) {
            if (fromValue.length === 0)
                return null;
            return fromValue[fromValue.length - 1];
        }
        else {
            throw new Error("value is not an array");
        }
    }
    set(onValue, value) {
        if (Array.isArray(onValue)) {
            onValue.push(value);
        }
        else {
            throw new Error("value is not an array");
        }
    }
}
export class ArrayAddFirstDataMemberAccessor {
    get(fromValue) {
        if (Array.isArray(fromValue)) {
            if (fromValue.length === 0)
                return null;
            return fromValue[0];
        }
        else {
            throw new Error("value is not an array");
        }
    }
    set(onValue, value) {
        if (Array.isArray(onValue)) {
            onValue.unshift(value);
        }
        else {
            throw new Error("value is not an array");
        }
    }
}
//# sourceMappingURL=DataMemberAccessor.js.map