{"_id":"@aikon/dookie","_rev":"1-3aaeddf1aaec81abbfe93d3b49ae65ab","name":"@aikon/dookie","dist-tags":{"latest":"0.4.2"},"versions":{"0.4.2":{"name":"@aikon/dookie","version":"0.4.2","description":"Stylus-inspired preprocessor for MongoDB data sets and fixtures","keywords":["mongodb","fixture","fixtures","test","data","dataset","import"],"scripts":{"test":"mocha ./test/*.test.js"},"dependencies":{"JSONStream":"1.1.1","clone":"2.1.1","co":"4.6.0","commander":"2.8.1","dot-component":"0.1.1","graceful-fs":"4.1.11","js-yaml":"3.13.x","json-stream":"1.x","lodash.get":"4.4.2","minimatch":"3.0.4","mongodb":"~3.5","mongodb-extended-json":"1.7.0","mongodb-ns":"1.0.3","thunkify":"2.1.2"},"devDependencies":{"acquit":"1.0.3","acquit-ignore":"0.1.0","acquit-markdown":"0.1.0","lodash":"4.x","mocha":"5.x"},"engines":{"node":">= 10.0.0"},"bin":{"dookie":"bin/dookie.js"},"repository":{"type":"git","url":"git://github.com/vkarpov15/dookie.git"},"gitHead":"fe9be3848a74775831619defd661f41d3e8ade78","bugs":{"url":"https://github.com/vkarpov15/dookie/issues"},"homepage":"https://github.com/vkarpov15/dookie#readme","_id":"@aikon/dookie@0.4.2","_nodeVersion":"12.12.0","_npmVersion":"6.13.6","dist":{"integrity":"sha512-7PiC33Ezb9mtjmz+mgZqgOLDDEXn6fkUnq3pYOY72lT28IezQshd/8fFaV719ObaWwtRPcAfDTamoed8cqg2zg==","shasum":"a0dfff3ae5bd9037e84f57e66199669f39bb09cd","tarball":"https://registry.npmjs.org/@aikon/dookie/-/dookie-0.4.2.tgz","fileCount":18,"unpackedSize":46954,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhJZPzCRA9TVsSAnZWagAA/IgP/RZ5cdW2Gjr7sRRKx8oZ\nr0PqwNlW3ZuT2ZcP8y2Ay8nYDrbMA4WcUN8ffnVq5Nk5ns+8McDGoFtlzhr5\nfgcmx/LFAemb53UFAs5jlaSh+EshjL8Xok+4GpVebv1pB0hG7i5f9nXsZ+z6\nPZwAsaBn6Qc7etC/XppPI0KKG2cbzSBHeoECV0sow/6qrMk0DTgg/K89ZTIH\n+2Pj/NywmA/57T/nFEfG/UnACBgeDfmn2baDu7zqiNG+mWOxyMO3ZwMqvRPS\nKKhW5cUSrP47dylU9+Gdftq1dSjp46GuADJdVGeroHpW4/vonSgI+jlOFGYE\nt99aVUjZCHcgol50GH4l85+5GxhS97iod5VFx9bMiddeMLhTIhVRxBknjIEt\nqX5tZhB7DRxC0xQVyDwoRGFXaxf2/dfUklbbApB9wp2FzRO4Z4wFBlG5+uWs\n8lXYidvhKGo0prN0zgvpl/895lYnii4mtGNJrKqUW1xyaWWj448xOkrnXIBt\n3aQ+DX8qSG3pgwAVkmMXIoqsvlvNTXih9AbfRpgi/rSZgNzTuEWrFkafvPHb\n8WaYlwhP1l6s7wzT0m4+Z22ojByx9aSODAvgH0NcJR3tBqR6/xFxIvtwQ2Ir\nO5paKhajbP6GTipqQVfkXhy/crq/eXtQars/0KPXwW855vfYalcffnabVcdN\nhUbq\r\n=wP3s\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEcBwNVnIIOZj/SFZUoR+njluIc3llP+w5jBDKouvsBxAiEA4GIXwcw6X9cQMvEfoZ1hAXPBEBkNRFvapcOA00BsIgk="}]},"_npmUser":{"name":"apimarket","email":"info@aikon.com"},"directories":{},"maintainers":[{"name":"apimarket","email":"info@aikon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dookie_0.4.2_1629852659323_0.2517577131280606"},"_hasShrinkwrap":false}},"time":{"created":"2021-08-25T00:50:59.279Z","0.4.2":"2021-08-25T00:50:59.465Z","modified":"2022-04-04T12:18:14.642Z"},"maintainers":[{"name":"apimarket","email":"info@aikon.com"}],"description":"Stylus-inspired preprocessor for MongoDB data sets and fixtures","homepage":"https://github.com/vkarpov15/dookie#readme","keywords":["mongodb","fixture","fixtures","test","data","dataset","import"],"repository":{"type":"git","url":"git://github.com/vkarpov15/dookie.git"},"bugs":{"url":"https://github.com/vkarpov15/dookie/issues"},"readme":"# dookie\n\n<img src=\"http://i.imgur.com/1scBld5.png\" width=\"250px\">\n\nDookie lets you write MongoDB test fixtures in JSON or\n[YAML](https://en.wikipedia.org/wiki/YAML) with extra syntactic sugar\n(extended JSON, variables, imports, inheritance, etc.).\n\n**Note:** Dookie requires Node >= 4.0.0. Dookie is **not** tested with nor\nexpected to work with Node 0.x or io.js.\n\n[![Circle CI](https://circleci.com/gh/vkarpov15/dookie.svg?style=svg)](https://circleci.com/gh/vkarpov15/dookie)\n\n# Examples\n\n\nDookie can be used either via `require('dookie');` in Node.js, or from the\ncommand line as an executable. Dookie's fundamental operations are:\n\n1. Push - optionally clear out a database and insert some data\n2. Pull - write the contents of a database to a file\n\nPush is more interesting, so let's start with that. You can access the\npush functionality with the `require('dookie').push()` function, or\n`./node_modules/.bin/dookie push` from the command line.\n\n\n## It can import YAML data with .push()\n\n\nSuppose you have a YAML file called `file.yml` that looks like below.\n\n```yaml\npeople:\n  - _id:\n      # MongoDB extended JSON syntax\n      $oid: 561d87b8b260cf35147998ca\n    name: Axl Rose\n  - _id:\n      $oid: 561d88f5b260cf35147998cb\n    name: Slash\n\nbands:\n  - _id: Guns N' Roses\n    members:\n      - Axl Rose\n      - Slash\n\n```\n\nDookie can push this file to MongoDB for you.\n\n\n```javascript\n\n    co(function*() {\n      const fs = require('fs');\n      const yaml = require('js-yaml');\n\n      const contents = fs.readFileSync('./example/basic/file.yml');\n      const parsed = yaml.safeLoad(contents);\n\n      const mongodbUri = 'mongodb://localhost:27017/test';\n      // Insert data into dookie\n      // Or, at the command line:\n      // `dookie push --db test --file ./example/basic/file.yml`\n      yield dookie.push(mongodbUri, parsed);\n\n      // ------------------------\n      // Now that you've pushed, you should see the data in MongoDB\n      const db = yield mongodb.MongoClient.connect(mongodbUri);\n      const collections = (yield db.listCollections().toArray()).\n        map(v => v.name).filter(v => !v.startsWith('system.')).sort();\n      assert.equal(collections.length, 2);\n      assert.equal(collections[0], 'bands');\n      assert.equal(collections[1], 'people');\n\n      const people = yield db.collection('people').find().toArray();\n      people.forEach((person) => { person._id = person._id.toString() });\n      assert.deepEqual(people, [\n        { _id: '561d87b8b260cf35147998ca', name: 'Axl Rose' },\n        { _id: '561d88f5b260cf35147998cb', name: 'Slash' }\n      ]);\n      const bands = yield db.collection('bands').find().toArray();\n      assert.deepEqual(bands, [\n        { _id: `Guns N' Roses`, members: ['Axl Rose', 'Slash'] }\n      ]);\n    })\n  \n```\n\n## It can $require external files\n\nSuppose you're a more advanced user and have some collections you want\nto re-use between data sets. For instance, you may want a common collection\nof users for your data sets. Dookie provides a `$require` keyword just\nfor that. Suppose you have a file called `parent.yml`:\n\n```yaml\n$require: ./child.yml\n\nbands:\n  - _id: Guns N' Roses\n    members:\n      - Axl Rose\n\n```\n\nThis file does a `$require` on `child.yml`, which looks like this:\n\n```yaml\npeople:\n  - _id: Axl Rose\n\n```\n\nWhen you push `parent.yml`, dookie will pull in the 'people' collection\nfrom `child.yml` as well.\n\n\n```javascript\n\n    co(function*() {\n      const filename = './example/$require/parent.yml';\n      const contents = fs.readFileSync(filename);\n      const parsed = yaml.safeLoad(contents);\n\n      const mongodbUri = 'mongodb://localhost:27017/test';\n      // Insert data into dookie\n      // Or, at the command line:\n      // `dookie push --db test --file ./example/basic/parent.yml`\n      yield dookie.push(mongodbUri, parsed, filename);\n\n      // ------------------------\n      // Now that you've pushed, you should see the data in MongoDB\n      const db = yield mongodb.MongoClient.connect(mongodbUri);\n\n      const people = yield db.collection('people').find().toArray();\n      assert.deepEqual(people, [{ _id: 'Axl Rose' }]);\n\n      const bands = yield db.collection('bands').find().toArray();\n      assert.deepEqual(bands, [\n        { _id: `Guns N' Roses`, members: ['Axl Rose'] }\n      ]);\n    })\n  \n```\n\n## It supports inheritance via $extend\n\nYou can also re-use objects using the `$extend` keyword. Suppose each\nperson in the 'people' collection should have a parent pointer to the\nband they're a part of. You can save yourself some copy/paste by using\n`$extend`:\n\n```yaml\n$gnrMember:\n  band: Guns N' Roses\n\npeople:\n  - $extend: $gnrMember\n    _id: Axl Rose\n  - _id: Slash\n    $extend: $gnrMember\n\n```\n\n\n```javascript\n\n    co(function*() {\n      const filename = './example/$extend.yml';\n      const contents = fs.readFileSync(filename);\n      const parsed = yaml.safeLoad(contents);\n\n      const mongodbUri = 'mongodb://localhost:27017/test';\n      // Insert data into dookie\n      // Or, at the command line:\n      // `dookie push --db test --file ./example/$extend.yml`\n      yield dookie.push(mongodbUri, parsed, filename);\n\n      // ------------------------\n      // Now that you've pushed, you should see the data in MongoDB\n      const db = yield mongodb.MongoClient.connect(mongodbUri);\n\n      const people = yield db.collection('people').find().toArray();\n      assert.deepEqual(people, [\n        { band: `Guns N' Roses`, _id: 'Axl Rose' },\n        { band: `Guns N' Roses`, _id: 'Slash' }\n      ]);\n    })\n  \n```\n\n## It can evaluate code with $eval\n\nDookie also lets you evaluate code in your YAML. The code runs with the\ncurrent document as the context.\n\n```yaml\npeople:\n  - _id: 0\n    firstName: Axl\n    lastName: Rose\n    name:\n      $eval: this.firstName + ' ' + this.lastName\n\n```\n\n\n```javascript\n\n    co(function*() {\n      const filename = './example/$eval.yml';\n      const contents = fs.readFileSync(filename);\n      const parsed = yaml.safeLoad(contents);\n\n      const mongodbUri = 'mongodb://localhost:27017/test';\n      // Insert data into dookie\n      // Or, at the command line:\n      // `dookie push --db test --file ./example/$eval.yml`\n      yield dookie.push(mongodbUri, parsed, filename);\n\n      // ------------------------\n      // Now that you've pushed, you should see the data in MongoDB\n      const db = yield mongodb.MongoClient.connect(mongodbUri);\n\n      const people = yield db.collection('people').find().toArray();\n      assert.deepEqual(people, [\n        { _id: 0, firstName: 'Axl', lastName: 'Rose', name: 'Axl Rose' }\n      ]);\n    })\n  \n```\n\n## It can pull() data out of MongoDB\n\nThe above examples show how dookie can `push()` data into MongoDB. Dookie\ncan also `pull()` data out of MongoDB in JSON format. Why not just use\nmongoexport or mongodump? Mongoexport can only export a single collection,\nmongodump exports hard-to-read binary data, and neither can be run from\nNode without `.exec()`. Dookie lets you transfer whole databases in\na human readable format, and `assert()` on the entire state of your\ndatabase in tests with ease.\n\n\n```javascript\n\n    co(function*() {\n      const mongodbUri = 'mongodb://localhost:27017/test';\n      // Insert data into dookie\n      // Or, at the command line:\n      // `dookie pull --db test --file ./output.json`\n      const json = yield dookie.pull(mongodbUri);\n\n      assert.deepEqual(Object.keys(json), ['people']);\n      assert.deepEqual(json.people, [\n        { _id: 0, firstName: 'Axl', lastName: 'Rose', name: 'Axl Rose' }\n      ]);\n    })\n  \n```\n\n## AIKON updates\n\nForked this repo to fix a few bugs:\n- Now uses latest Mongo connection params\n- Now closes Mongo connection after push and pull (if options.clearConnection = true)","readmeFilename":"README.md"}