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AAQ,IAAI,EAAa,IAEnC,MAAK,GACK,IAEV,OAAM,IAEH,MADA,QAAQ,IAAI,GACN,CAAG,IAEZ,SAAQ,KACD,GACA,EAAG,OACP,GAEZ,CAEA,OAAO,QAAU,CACb,oCACA","file":"/npm/redmaas-dslautogen@0.3.2/dslGenerator.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/redmaas-dslautogen@0.3.2/dslGenerator.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 Promise = require('bluebird');\nconst parseSchema = Promise.promisify(require('mongodb-schema'));\nconst mongoConnect = Promise.promisify(require('mongodb').MongoClient.connect);\nconst _ = require('lodash');\nconst dslUtils = require('./dslStringify.js');\n\nfunction queryToDSL(dbCollection, options) {\n    return parseSchema(dbCollection.find())\n        .then(schema => {\n            const collectionObj = _.extend({\n                table: dbCollection.s.name,\n                label: dbCollection.s.name,\n                sortby: (_(schema.fields).size()?_(schema.fields).first().name:''),\n                order: 'asc',\n                query: '',\n                columns: [],\n                actions: [{\n                    Export: true,\n                }],\n                dsl: null,\n            }, options)\n            _(schema.fields).each((val) => {\n                collectionObj.columns.push({\n                    name: val.name,\n                    label: val.name,\n                    type: val.type,\n                });\n            });\n            collectionObj.dsl = dslUtils.getCollection(collectionObj);\n            return collectionObj;\n        })\n        .catch(err => {\n            console.log(err)\n            throw err;\n        });\n}\n\n\nfunction DbCollectionToDSL(dbConnection, collectionName, options) {\n    let db = null;\n    return mongoConnect(dbConnection)\n        .then(dbObj => {\n            db = dbObj;\n            return queryToDSL(db.collection(`${collectionName}`), options)\n        })\n        .then(dsl => {\n            return dsl;\n        })\n        .catch(err => {\n            console.log(err);\n            throw err;\n        })\n        .finally(() => {\n            if (db) {\n                db.close();\n            }\n        });\n}\n\n\nfunction DbToDSL(dbConnection, options) {\n    let db = null;\n    return mongoConnect(dbConnection)\n        .then(dbObj => {\n            db = dbObj;\n            return db.collections();\n        })\n        .then(collections => {\n            const qCollections = _(collections)\n                .filter((item) => {\n                    return !_.includes(item.s.name, 'system.index');\n                })\n                .map((item) => {\n                    return queryToDSL(item, options);\n                })\n                .value();\n            return Promise.all(qCollections);\n        })\n        .then(dslList => {\n            return dslList\n        })\n        .catch(err => {\n            console.log(err);\n            throw err;\n        })\n        .finally(() => {\n            if (db) {\n                db.close();\n            }\n        });\n}\n\nmodule.exports = {\n    DbCollectionToDSL,\n    DbToDSL,\n};"]}