{"_id":"@ashnazg/chok-db","_rev":"4-aa785830a47c8530c3895324eeac75bd","name":"@ashnazg/chok-db","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.0":{"name":"@ashnazg/chok-db","version":"1.0.0","description":"a FS-based doc db for pico-scale datasets","main":"main.js","repository":{"type":"git","url":"q:/git/me/projects.git"},"repository_path":"ashnazg-npm/chok-db","author":{"name":"Alexander Mathews xander@ashnazg.com"},"license":"MIT","dependencies":{"chokidar":"^3.5.1","q":"^1.5.1"},"_id":"@ashnazg/chok-db@1.0.0","dist":{"shasum":"934df759ef59a624c7c5a7f8b97933949c031f88","integrity":"sha512-UrLcOqqgxZ99943Q3omylMXqQdb2i75AXBFkqqvCKduQb1RBZG1TgIXD2L6RXZjCzDIHmLMyqsl4lr0i8IUiEA==","tarball":"https://registry.npmjs.org/@ashnazg/chok-db/-/chok-db-1.0.0.tgz","fileCount":4,"unpackedSize":6500,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgKGK2CRA9TVsSAnZWagAAjYgP/iIwTawB36877WsUe+2g\nT1xGUn9cqq6iFljfuNwW9/9p11mtsV8550NbWMb8covkurOu9delNAw3lAiO\nrdGw3XUqK7TtNttRRk98n7P2KLW28TuIUAUpEzINHGH+mZdWSDvrjpqn6m5w\nJnYUK7mYfVf/YYekLiQGYK6G1c5vwa+hsggu6hCzT4k1DTBrXdiwWLSheVEl\nbZRri4LFAyWIppePccFG3GoMiEroQ7pjKrnBU5AF21ZwAg74HGAwSdAH204k\n8oNcL5Z4COkuaJq4TWLRC5vC9M1QHm3Zai8ztmQfL9HIIbW8oYlAP7de7iiY\n25LjhTBtSTn8J18pI+cjSPMlM2Z0qMK9a26rEK7dVmeVz5zyVPE4WkBdKAHf\nyeE/+wjjyHh3nQa9YcxgSR9/a5Nf1cU9H/5hU2pwlGI58u75MMH9QfGaSAOE\nori/0DAp6rvq8Qf8czK5AfbV6awinUxzo1sJiEqQbCRfQKuZzdTTi/9fKG71\nI6Ymg2TG2KimyhitvmVF+IPOMestUgPkPJFQ6FCnOEoVYvDQOG83rv1JLu4u\naVEQVIRl5ww6BpPXHZApepxhaNlsfdiI6VZi9/OQK6sm6R/t2w/5ytzlDCoK\ny0sjJ9WuTc77TnXGGzWkh9EdHZWi/FX8gUSzYGp3b5JGXVhyvJOqYSqovm9X\nwy3T\r\n=XOeW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDyn4J4Pj0WjHFQ7ofead+ZITFyphZltj6fBsn4G/KMmQIgWq/eUBL7zALqg8COczuFh77bn8qS3Ol4tzVPV2YEQhw="}]},"_npmUser":{"name":"xander","email":"xander@ashnazg.com"},"directories":{},"maintainers":[{"name":"xander","email":"xander@ashnazg.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/chok-db_1.0.0_1613259446003_0.2317596944827851"},"_hasShrinkwrap":false},"1.0.1":{"name":"@ashnazg/chok-db","version":"1.0.1","description":"a FS-based doc db for pico-scale datasets","main":"main.js","repository":{"type":"git","url":"q:/git/me/projects.git"},"repository_path":"ashnazg-npm/chok-db","author":{"name":"Alexander Mathews xander@ashnazg.com"},"license":"MIT","dependencies":{"chokidar":"^3.5.1","q":"^1.5.1"},"_id":"@ashnazg/chok-db@1.0.1","dist":{"shasum":"0a0a379dbef331e99cfb89f5ba955806fbf46d64","integrity":"sha512-Fch9tFFB1IM2O/WtXpUa2Bq/FwBbakIvR4CDfYTjII9BppIctUZVzoKwJ1iXEFsZIUiLIqATWhWfrfEuIS77mQ==","tarball":"https://registry.npmjs.org/@ashnazg/chok-db/-/chok-db-1.0.1.tgz","fileCount":4,"unpackedSize":7508,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgKIcOCRA9TVsSAnZWagAAaOwP+wd+yKmoNT6SgTLnrQZI\n+iY+7PpHdbs4rEl1Mnl/g4HY19o7pDr/fG/WO+WFql5IdPSizWQdEYWMvSSE\nFrm0TQdHs7etQ1RQ4Wli7tV0Jm4S89vESpZK+anEAa+vyDD1v3fjw40scWTN\nucTKBNC8Qr/v+ordvyhQ+NbGX/NeH57OyPumTyWQ5Bj0dVM2PPCHrTIvUxhP\nc8rVWj6XXroT3BTYeYwx1pPLOzyE/PvIK25SavzztsmmAyfe9V1WHdjRvrL/\nTIWfzvgu1SgAtPDw8jPYaOTZ/Z0XLgFFpSboHEuW6oSRgocORmAdRh0IJ4Ta\n4KdPPqEn32Dcbx7cSpi+J5ZIv73IczJjckh8/rnEF9gtvX7dQ7xJgQ5eZy87\nRfv+Dn6e166THfGhCjL01vBoJbSNkO63gt9tg7glGWUQqB+DBaVQwT8j1uXR\nUWAr7NhQOsa4od8Za/r5o9YPzErJ5BTTtfPgSEAvKuqL6L19EvzC5JB84nbE\nCOPRLVywU/RtsThEJFren8satzP3hsaXDwdnXg/lNcsj6WD4iAXOWf4SDPKA\nZigxc/wHVL0a4gTztSnLK5y5Vblxo6VxuyiiYv2z18vrr/N0zlN3MdejslDV\nKRF+qFZXW8loLIWv5lya3g+ZQ7/LyyUSn58opu2tpC8zBrrNqOaZ0tt0UF31\nJ7TV\r\n=QNZi\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCb1Y9hunpCxMIOBDZT9L1LZZonyn6IFLjmANXW/W+RvgIgSQJ8eZxNWP1Fgf08V9ofgDOW+RnCmvrr2OrbYLAQROk="}]},"_npmUser":{"name":"xander","email":"xander@ashnazg.com"},"directories":{},"maintainers":[{"name":"xander","email":"xander@ashnazg.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/chok-db_1.0.1_1613268750349_0.02607005065753132"},"_hasShrinkwrap":false},"1.0.2":{"name":"@ashnazg/chok-db","version":"1.0.2","description":"a FS-based doc db for pico-scale datasets","main":"main.js","repository":{"type":"git","url":"q:/git/me/projects.git"},"repository_path":"ashnazg-npm/chok-db","author":{"name":"Alexander Mathews xander@ashnazg.com"},"license":"MIT","dependencies":{"chokidar":"^3.5.1","q":"^1.5.1"},"_id":"@ashnazg/chok-db@1.0.2","dist":{"shasum":"17e6d69131391c02c92fcf024239a4164c93700a","integrity":"sha512-Noi/35kUPDqTS7yZJoexv2QRjMRUciJQ855SNmABcl5trZ3kHHvc4NWAwYTcuHrJFUXJUruoqM1f8f22wxOdww==","tarball":"https://registry.npmjs.org/@ashnazg/chok-db/-/chok-db-1.0.2.tgz","fileCount":4,"unpackedSize":7439,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgKKQsCRA9TVsSAnZWagAAbykP/1We3YT49hkN0pkCsbRE\nQpP4KVqkTXUSM+vcrH38AVbHLpcPLvtOunD2wQjm0SRUnCZQBDStDKO1sAZx\nM4sCFkBBleDhOU8asgeDstBz1YOYps+B5bie+zaNrfmzf2u61S6o2guV6x7i\naxfn3tvLLTgKK1h+pXSPca+uyoNpAyWvJIbVWSj1rc0ey7Pbn1Y6hoiJ5P1i\nyZUq3RG08oHbHUt3ZY82TbTv0kiSm60q130Dpvdgzf9sgarrg8fPiMB45bf6\nshzHEXsBoYrC+juxswMZiQjBa2xzbytSS/ckoyhpWAgreZleKdkVOZdgzY0Q\nBTPurop43xj47KptMvILUywU0naCdrDvRUMSJurqkKK+9t6w/C1KCnMDMS5U\n+yn1MZT6vOoXM6ES9qOFQIw3/MvlqMbL/hHrWp/S88vYwu6nJw7qjP7oQaWj\n0+5QUixmLYz248rK8vP/VjA/L8LSLWDaEMuxCuiS16oibNsbUx+uDWubSj3R\nhh363nJRGBoSXgjEvZ+KN20RzxJ7GZhbQ/Z8dmblfSaXRcSMga6UULEkmfWe\nl+zMWOwhgNfud/2THtFH00bvMEtm9R2ibJivSwdQJ/GiUyrEa7geV4H142nW\nGlsbHsIumFTFo8qCwFpKO1vyhWqGqzNUCZ4PeS00MNGQ6AoxQmyok+53SoiW\nc5T2\r\n=g4Ia\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGGo0Jy2lk439tVZkwPwcooy2KhXE6bgVfyixP86NnOnAiEA8kt/TtHrbSx50YNpJPlowQ5jCmftILHY0nH3yHiRejc="}]},"_npmUser":{"name":"xander","email":"xander@ashnazg.com"},"directories":{},"maintainers":[{"name":"xander","email":"xander@ashnazg.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/chok-db_1.0.2_1613276204337_0.967608031608937"},"_hasShrinkwrap":false},"1.0.3":{"name":"@ashnazg/chok-db","version":"1.0.3","description":"a FS-based doc db for pico-scale datasets","main":"main.js","repository":{"type":"git","url":"q:/git/me/projects.git"},"repository_path":"ashnazg-npm/chok-db","author":{"name":"Alexander Mathews xander@ashnazg.com"},"license":"MIT","dependencies":{"chokidar":"^3.5.1","q":"^1.5.1"},"_id":"@ashnazg/chok-db@1.0.3","dist":{"shasum":"fa8caf2addd1d0b0b951d511501ea8b8e0e884f8","integrity":"sha512-d05jpLQ9VmROQ549caF8CeAUl76YXsGcNhlCcVsQ5bT5lo0xB+/p7bXTJZHDKyLY9hDaiia5XphqPxK0i80HeA==","tarball":"https://registry.npmjs.org/@ashnazg/chok-db/-/chok-db-1.0.3.tgz","fileCount":4,"unpackedSize":7734,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhMZr1CRA9TVsSAnZWagAAEGAP/Agz2gjTsAbeKa4dqDHO\ntfMzJ+NmfasruqPV1PAz4CKmyY56Y/0Ag9jNMeWaRnqUjlYJwZvj49AgDW9v\nsmwqXXdydMg91B5FQKy7Sk8qEHrtcDeJxFXvNNctCO0Hkqtin3tpd9f9TqFT\nCAWMlqhRCHEPSADIILGCwytawnkERVKWOMWqUsC7X/FD0duL9PRtq1HQptDG\nZ5rghQi1WC6sLpuuH76bTv3lvSdVpxwGgcTTx3cUNRhmfk9iVR+ZbspM55ev\nHFYOZr0NC7a3z79ITjghIN9Hi7GN5UkndIaE6REo+yKi5kF9RSj6PpmNP+Xy\nWc+KUR3vK2Tu5iGvVbAdAeZyBLeEJNwNaXo/FXOGHYAAvlai0edGyfZ0KbEU\ndS0YxEDmPgZxkWMPZ/Mhp4pb43bMUeoKBIUxhpKwVrLGze2bP8ueuVc8s8yf\nB8KyHMMl0sbFBeSDbwGMWCLYdoBU4zlRHe00KPuDayjl1yWA2//ERxkoXz0M\nxjohndkHDYfgHfBwxJiWZG1+OyUO84gVpGbDRriccFeP/hEjE4odLwDbOi5+\n4pn4t6u21EC9k6SriwJyjqh8b4/G0SCzCkymG19/c1fBgzGoLQvAQiOEfxUO\nhkhv01KuBrbmI5kzaWS0dZwwle02kzrnbndT63FIXzTjUa3O6hBKGvSeBO0r\nVVCQ\r\n=CtZP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHas/Ly71wA++rdmILzQJ+tBhAw7eDvYL/MkXcM5pkySAiEA44uAiLOVwRuaoGhEdbVOO5yDxesu8EDG2yKB/e192Aw="}]},"_npmUser":{"name":"xander","email":"xander@ashnazg.com"},"directories":{},"maintainers":[{"name":"xander","email":"xander@ashnazg.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/chok-db_1.0.3_1630640885593_0.18238972415958155"},"_hasShrinkwrap":false}},"time":{"created":"2021-02-13T23:37:25.880Z","1.0.0":"2021-02-13T23:37:26.137Z","modified":"2022-04-04T15:45:51.047Z","1.0.1":"2021-02-14T02:12:30.596Z","1.0.2":"2021-02-14T04:16:44.487Z","1.0.3":"2021-09-03T03:48:05.744Z"},"maintainers":[{"name":"xander","email":"xander@ashnazg.com"}],"description":"a FS-based doc db for pico-scale datasets","repository":{"type":"git","url":"q:/git/me/projects.git"},"author":{"name":"Alexander Mathews xander@ashnazg.com"},"license":"MIT","readme":"* **What**: A filesystem-based pico-NoSQL-DB that allows mutations by filesystem operations while running to co-exist with API state changes.\n* **Why**: For every project that needs commerical-scale and -robustness on millions of rows, there's several 'our business runs on XLS and manual labor' automatable projects\n\twho's data would easily fit in the microcontroller in my garage door opener. Some of these use cases also need the kind of history-tracking that git would give me.\n\tSo I built an extremely KISS storage layer that allows me to use unixy tools to do bulk record maintenance.\n* **How**: using chokidar to to monitor the filesystem kept the complexity of this library to a minimum.\n\n```\nconst chokdb = require('@ashnazg/chok-db');\nconst client = await chokdb({path: 'folder_of_jsons/'});\n\nclient.create({a:1,b:2}); // autoassigns new ID\nclient.update(1, {a:2,b:1});\nconsole.log(client.read(1));\nclient.del(1);\n```\n\nThe three mutators return promise({db, id}) as a convenience.\n\nWant to just grab the whole map of rows? Skip the ID param on read().\n```\nconst map = client.read();\n```\n(Both usages of read() are synchronous.)\n\n## fast or write-guaranteed?\nAll mutators complete the work in-memory synchronously, and then asynchronously write to disk.\n\nIf you await the create/update/del call before responding to caller, you're in write-guaranteed mode.\n\nif you want the ID that create() used without waiting for the file write, just check `client.last_id_created` synchronously right after create() returns.\n\n(Regardless of fast vs safe usage, `client.last_id_created` is always zero when the service initializes and not retained between runs.)\n\n## Customize Behavior\nThe chokdb({path}) function takes several other inputs; you could swap JSON for YAML or turn on verbose logging:\n```\nconst yaml_backed_client = await chokdb({path: 'myyamls/', parser: string2yaml, serializer: yaml2string});\n\n// here's all the current debug/log hooks:\nconst client = await chokdb({\n\tpath,\n\tlog: {\n\t\twrite(id, body) { console.log(\"writing\", id, body); },\n\t\tevt(chok_event_name, row_filename) { console.log(\"chokidar event\", chok_event_name, row_filename); },\n\t\tparseErr(filename, error) { console.error('got', error, 'when I parsed', filename); }, // if you don't provide a parseErr, it just throws the error to chokidar instead.\n\t}\n});\n```\n\n## stream of events\nWant to be notified of changes?\n\nI wanted a way to push updates to websocket clients, so once the data's persisted to disk, these optional hooks are called:\n\n```\nconst client = await chokdb({\n\tpath,\n\tonadd(dying_record) {}\n\tonchange(altered_record) {}\n\tonunlink(new_record) {} // this is the only hook that happens _before_ the memory DB is updated.\n});\n```\n\n## Pico-Validation\nWant to see if a user-provided value is a safe and present row ID?\n```\nclient.validate(id); // throws on any 404 or unsanitary input.\n```\n\n## ID field\nLike SQLite, chokdb rows expose the internal auto increment to you. (This makes it easy for me to pass the row from DB/FE/UI/sub-UI and back again.)\n\nBut the ID field in the row is not changable; attempts will be reset next time you update().\n\nNor is there a way through this API to renumber a row. (But since the memory DB tracks changes on disk, this is trivial from the filesystem: `mv 1.json 5.json`)\n\n## Release 1.0.3\n* fixed: To be fully unixy, row files' last line also has a '\\n'\n* new: .write(id) and .update(id) now support the idea that the second (body) param is optional -- in that mode, just save the mutations made directly to the memory copy.\n\n## Release 1.0.2\nJust fixed this README\n\n## Release 1.0.1\n* bugfix: catastrophic typo in unlink handler\n* feature: chokdb will now mkdir the path you give it if it doesn't exist. (Make sure the base already exists; this isn't `mkdir -p`.)\n* tweak: unused IDs are now routinely reused. (I know how classic RDBS's do it, but I think that if your data integrity doctrine depends on this instead of foreign-keys/cascades, you've already lost.)\n","readmeFilename":"README.md"}