hackernews-node/node_modules/prisma-datamodel/dist/datamodel/model.js
/**
 * Deep-copies a datamodel and re-connects all types correctly.
 * @param schema The datamodel to clone.
 */
Deep-copies a datamodel and re-connects all types correctly.
@param schema The datamodel to clone.
Deep - copies a datamodel and re - connects all types correctly . @param schema The datamodel to clone .
function cloneSchema(schema) {
    var copy = __assign({}, schema);
    cloneComments(copy, schema);
    copy.types = [];
    for (var _i = 0, _a = schema.types; _i < _a.length; _i++) {
        var type = _a[_i];
        copy.types.push(cloneType(type));
    }
    for (var _b = 0, _c = copy.types; _b < _c.length; _b++) {
        var type = _c[_b];
        var _loop_1 = function (field) {
            if (typeof field.type !== 'string') {
                var typeName_1 = field.type.name;
                var fieldType = copy.types.filter(function (x) { return x.name === typeName_1; })[0];
                console.assert(fieldType !== undefined); 
                field.type = fieldType;
            }
        };
        for (var _d = 0, _e = type.fields; _d < _e.length; _d++) {
            var field = _e[_d];
            _loop_1(field);
        }
    }
    for (var _f = 0, _g = copy.types; _f < _g.length; _f++) {
        var type = _g[_f];
        if (type.indices !== undefined) {
            for (var _h = 0, _j = type.indices; _h < _j.length; _h++) {
                var index = _j[_h];
                var _loop_2 = function (i) {
                    var fieldName = index.fields[i].name;
                    var field = type.fields.filter(function (x) { return x.name === fieldName; })[0];
                    console.assert(field !== undefined); 
                    index.fields[i] = field;
                };
                for (var i = 0; i < index.fields.length; i++) {
                    _loop_2(i);
                }
            }
        }
    }
    return copy;
}
function cloneSchema ( schema ) { var copy = __assign ( { } , schema ) ; cloneComments ( copy , schema ) ; copy . types = [ ] ; for ( var _i = 0 , _a = schema . types ; _i < _a . length ; _i ++ ) { var type = _a [ _i ] ; copy . types . push ( cloneType ( type ) ) ; } for ( var _b = 0 , _c = copy . types ; _b < _c . length ; _b ++ ) { var type = _c [ _b ] ; var _loop_1 = function ( field ) { if ( typeof field . type !== 'string' ) { var typeName_1 = field . type . name ; var fieldType = copy . types . filter ( function ( x ) { return x . name === typeName_1 ; } ) [ 0 ] ; console . assert ( fieldType !== undefined ) ; field . type = fieldType ; } } ; for ( var _d = 0 , _e = type . fields ; _d < _e . length ; _d ++ ) { var field = _e [ _d ] ; _loop_1 ( field ) ; } } for ( var _f = 0 , _g = copy . types ; _f < _g . length ; _f ++ ) { var type = _g [ _f ] ; if ( type . indices !== undefined ) { for ( var _h = 0 , _j = type . indices ; _h < _j . length ; _h ++ ) { var index = _j [ _h ] ; var _loop_2 = function ( i ) { var fieldName = index . fields [ i ] . name ; var field = type . fields . filter ( function ( x ) { return x . name === fieldName ; } ) [ 0 ] ; console . assert ( field !== undefined ) ; index . fields [ i ] = field ; } ; for ( var i = 0 ; i < index . fields . length ; i ++ ) { _loop_2 ( i ) ; } } } } return copy ; }
Deep-copies a datamodel and re-connects all types correctly.
Deep - copies a datamodel and re - connects all types correctly .
// TODO(ejoebstl): It would be better to have a concrete implementation for // each SDL object and require a clone method on interface level. // Re-Assign type pointer for relations // This case should never happen // Re-Assign field pointer for indices // This case should never happen // We need an index for setting the element // tslint:disable-next-line:prefer-for-of