{"version":3,"sources":["jsdelivr-header.js","/npm/graphql-bookshelfjs@1.0.8/src/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,aAEA,MAAM,QAAU,QAAQ,aASxB,SAAS,iBAAiB,GACtB,SAAS,EAAsB,GAE3B,OAAO,OAAO,OAAO,EAAM,EAAK,UAAU,CAAE,SAAS,IACzD,CACA,OAAI,EACI,EAAW,eAAe,UACnB,EAAW,KAAK,GAAkB,EAAsB,KAE5D,EAAsB,GAE1B,CACX,CAEA,OAAO,QAAU,CAMb,WAAU,IACC,QAQX,gBAAgB,GACL,SAAkB,EAAe,EAAM,EAAS,EAAM,GACzD,MAAM,EAA4D,mBAApC,EAAM,UAAU,EAAK,WAC7C,EAAQ,EAAgB,EAAc,QAAQ,EAAK,WAAa,IAAI,EAC1E,IAAK,MAAM,KAAO,EACd,EAAM,MAAM,GAAG,EAAM,aAAa,IAAO,EAAK,IAElD,GAAI,EACA,cAAe,GACX,IAAK,WACD,EAAM,GACN,MAEJ,IAAK,SACD,IAAK,MAAM,KAAO,EACd,EAAM,MAAQ,EAAM,WACb,EAAM,GAEjB,MAEJ,QACI,OAAO,QAAQ,OAAO,8DAGlC,GAAI,EAEA,OADA,GAAW,EAAQ,SAAW,EAAQ,QAAQ,GACvC,EAAM,QAAQ,MAAM,GAAe,iBAAiB,KAG/D,OAAO,EAD0C,gBAArC,EAAK,WAAW,YAAY,KAA0B,WAAa,WAC5D,MAAM,GAAe,iBAAiB,IAC7D","file":"/npm/graphql-bookshelfjs@1.0.8/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/graphql-bookshelfjs@1.0.8/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nconst loaders = require('./loaders');\n\n/**\n * Quick workaround allowing GraphQL to access model attributes directly\n * (to access a bookshelf model attribute (like model.name), we have to use the .get() method)\n *\n * @param {object} collection\n * @returns {*}\n */\nfunction exposeAttributes(collection) {\n    function exposeModelAttributes(item) {\n        // Make sure that relations are excluded\n        return Object.assign(item, item.serialize({ shallow: true }));\n    }\n    if (collection) {\n        if (collection.hasOwnProperty('length')) {\n            return collection.map((item) => { return exposeModelAttributes(item); });\n        }\n        return exposeModelAttributes(collection);\n    }\n    return collection;\n}\n\nmodule.exports = {\n\n    /**\n     *\n     * @returns {function}\n     */\n    getLoaders() {\n        return loaders;\n    },\n\n    /**\n     *\n     * @param {function} Model\n     * @returns {function}\n     */\n    resolverFactory(Model) {\n        return function resolver(modelInstance, args, context, info, extra) {\n            const isAssociation = (typeof Model.prototype[info.fieldName] === 'function');\n            const model = isAssociation ? modelInstance.related(info.fieldName) : new Model();\n            for (const key in args) {\n                model.where(`${model.tableName}.${key}`, args[key]);\n            }\n            if (extra) {\n                switch (typeof extra) {\n                    case 'function':\n                        extra(model);\n                        break;\n\n                    case 'object':\n                        for (const key in extra) {\n                            model[key](...extra[key]);\n                            delete extra[key];\n                        }\n                        break;\n\n                    default:\n                        return Promise.reject('Parameter [extra] should be either a function or an object');\n                }\n            }\n            if (isAssociation) {\n                context && context.loaders && context.loaders(model);\n                return model.fetch().then((c) => { return exposeAttributes(c); });\n            }\n            const fn = (info.returnType.constructor.name === 'GraphQLList') ? 'fetchAll' : 'fetch';\n            return model[fn]().then((c) => { return exposeAttributes(c); });\n        };\n    },\n\n};\n"]}