@keyv/mongo 1.2.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nyc_output/735a3ced-e6b6-402c-aaa5-3b4f8904072b.json +1 -0
- package/.nyc_output/{5820d74a-2c5d-4545-b2e1-19b4fc0d16f0.json → e5f2a160-d88e-49f6-8163-497c124f9412.json} +0 -0
- package/.nyc_output/processinfo/735a3ced-e6b6-402c-aaa5-3b4f8904072b.json +1 -0
- package/.nyc_output/processinfo/{5820d74a-2c5d-4545-b2e1-19b4fc0d16f0.json → e5f2a160-d88e-49f6-8163-497c124f9412.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/README.md +2 -2
- package/package.json +58 -58
- package/src/index.js +276 -30
- package/test/test.js +145 -2
- package/.nyc_output/e600d32e-2bd2-4fcc-ba04-b79d5cfa2d6b.json +0 -1
- package/.nyc_output/processinfo/e600d32e-2bd2-4fcc-ba04-b79d5cfa2d6b.json +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js":{"path":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js","statementMap":{"0":{"start":{"line":3,"column":21},"end":{"line":3,"column":38}},"1":{"start":{"line":4,"column":15},"end":{"line":4,"column":39}},"2":{"start":{"line":5,"column":20},"end":{"line":5,"column":50}},"3":{"start":{"line":6,"column":21},"end":{"line":6,"column":52}},"4":{"start":{"line":7,"column":13},"end":{"line":7,"column":28}},"5":{"start":{"line":9,"column":22},"end":{"line":9,"column":124}},"6":{"start":{"line":12,"column":2},"end":{"line":12,"column":10}},"7":{"start":{"line":13,"column":2},"end":{"line":13,"column":26}},"8":{"start":{"line":14,"column":2},"end":{"line":14,"column":18}},"9":{"start":{"line":15,"column":2},"end":{"line":17,"column":3}},"10":{"start":{"line":16,"column":3},"end":{"line":16,"column":17}},"11":{"start":{"line":19,"column":2},"end":{"line":21,"column":3}},"12":{"start":{"line":20,"column":3},"end":{"line":20,"column":46}},"13":{"start":{"line":23,"column":2},"end":{"line":30,"column":4}},"14":{"start":{"line":32,"column":23},"end":{"line":36,"column":3}},"15":{"start":{"line":34,"column":13},"end":{"line":34,"column":34}},"16":{"start":{"line":38,"column":2},"end":{"line":42,"column":4}},"17":{"start":{"line":40,"column":13},"end":{"line":40,"column":33}},"18":{"start":{"line":45,"column":2},"end":{"line":117,"column":5}},"19":{"start":{"line":46,"column":3},"end":{"line":116,"column":7}},"20":{"start":{"line":48,"column":5},"end":{"line":50,"column":6}},"21":{"start":{"line":49,"column":6},"end":{"line":49,"column":39}},"22":{"start":{"line":52,"column":5},"end":{"line":52,"column":39}},"23":{"start":{"line":53,"column":5},"end":{"line":115,"column":6}},"24":{"start":{"line":54,"column":6},"end":{"line":57,"column":9}},"25":{"start":{"line":58,"column":6},"end":{"line":58,"column":71}},"26":{"start":{"line":59,"column":6},"end":{"line":61,"column":9}},"27":{"start":{"line":62,"column":6},"end":{"line":64,"column":9}},"28":{"start":{"line":65,"column":6},"end":{"line":67,"column":9}},"29":{"start":{"line":68,"column":6},"end":{"line":70,"column":9}},"30":{"start":{"line":72,"column":6},"end":{"line":77,"column":7}},"31":{"start":{"line":76,"column":7},"end":{"line":76,"column":70}},"32":{"start":{"line":79,"column":6},"end":{"line":84,"column":7}},"33":{"start":{"line":83,"column":7},"end":{"line":83,"column":73}},"34":{"start":{"line":86,"column":6},"end":{"line":86,"column":71}},"35":{"start":{"line":88,"column":6},"end":{"line":88,"column":60}},"36":{"start":{"line":89,"column":6},"end":{"line":95,"column":8}},"37":{"start":{"line":96,"column":6},"end":{"line":102,"column":8}},"38":{"start":{"line":104,"column":6},"end":{"line":112,"column":7}},"39":{"start":{"line":111,"column":7},"end":{"line":111,"column":70}},"40":{"start":{"line":114,"column":6},"end":{"line":114,"column":26}},"41":{"start":{"line":121,"column":2},"end":{"line":146,"column":3}},"42":{"start":{"line":122,"column":3},"end":{"line":145,"column":6}},"43":{"start":{"line":123,"column":4},"end":{"line":129,"column":7}},"44":{"start":{"line":131,"column":19},"end":{"line":131,"column":62}},"45":{"start":{"line":132,"column":4},"end":{"line":144,"column":7}},"46":{"start":{"line":133,"column":16},"end":{"line":133,"column":18}},"47":{"start":{"line":134,"column":5},"end":{"line":134,"column":41}},"48":{"start":{"line":134,"column":30},"end":{"line":134,"column":39}},"49":{"start":{"line":136,"column":5},"end":{"line":139,"column":8}},"50":{"start":{"line":137,"column":6},"end":{"line":137,"column":51}},"51":{"start":{"line":138,"column":6},"end":{"line":138,"column":20}},"52":{"start":{"line":141,"column":5},"end":{"line":143,"column":8}},"53":{"start":{"line":142,"column":6},"end":{"line":142,"column":23}},"54":{"start":{"line":148,"column":2},"end":{"line":156,"column":4}},"55":{"start":{"line":149,"column":3},"end":{"line":155,"column":5}},"56":{"start":{"line":150,"column":4},"end":{"line":152,"column":5}},"57":{"start":{"line":151,"column":5},"end":{"line":151,"column":22}},"58":{"start":{"line":154,"column":4},"end":{"line":154,"column":21}},"59":{"start":{"line":160,"column":20},"end":{"line":160,"column":79}},"60":{"start":{"line":162,"column":2},"end":{"line":178,"column":3}},"61":{"start":{"line":163,"column":3},"end":{"line":177,"column":6}},"62":{"start":{"line":164,"column":19},"end":{"line":169,"column":6}},"63":{"start":{"line":171,"column":4},"end":{"line":176,"column":7}},"64":{"start":{"line":172,"column":5},"end":{"line":174,"column":8}},"65":{"start":{"line":173,"column":6},"end":{"line":173,"column":22}},"66":{"start":{"line":175,"column":5},"end":{"line":175,"column":23}},"67":{"start":{"line":180,"column":2},"end":{"line":186,"column":4}},"68":{"start":{"line":181,"column":3},"end":{"line":185,"column":4}},"69":{"start":{"line":190,"column":2},"end":{"line":192,"column":3}},"70":{"start":{"line":191,"column":3},"end":{"line":191,"column":33}},"71":{"start":{"line":194,"column":2},"end":{"line":204,"column":3}},"72":{"start":{"line":195,"column":3},"end":{"line":203,"column":6}},"73":{"start":{"line":196,"column":23},"end":{"line":196,"column":32}},"74":{"start":{"line":197,"column":19},"end":{"line":199,"column":6}},"75":{"start":{"line":200,"column":4},"end":{"line":202,"column":25}},"76":{"start":{"line":201,"column":20},"end":{"line":201,"column":71}},"77":{"start":{"line":201,"column":66},"end":{"line":201,"column":70}},"78":{"start":{"line":202,"column":18},"end":{"line":202,"column":23}},"79":{"start":{"line":206,"column":2},"end":{"line":210,"column":4}},"80":{"start":{"line":207,"column":3},"end":{"line":209,"column":44}},"81":{"start":{"line":209,"column":20},"end":{"line":209,"column":43}},"82":{"start":{"line":214,"column":2},"end":{"line":231,"column":3}},"83":{"start":{"line":215,"column":3},"end":{"line":230,"column":6}},"84":{"start":{"line":216,"column":23},"end":{"line":216,"column":32}},"85":{"start":{"line":217,"column":19},"end":{"line":219,"column":6}},"86":{"start":{"line":220,"column":4},"end":{"line":229,"column":9}},"87":{"start":{"line":223,"column":7},"end":{"line":225,"column":8}},"88":{"start":{"line":224,"column":8},"end":{"line":224,"column":21}},"89":{"start":{"line":227,"column":7},"end":{"line":227,"column":57}},"90":{"start":{"line":227,"column":25},"end":{"line":227,"column":55}},"91":{"start":{"line":228,"column":7},"end":{"line":228,"column":19}},"92":{"start":{"line":233,"column":2},"end":{"line":237,"column":4}},"93":{"start":{"line":234,"column":3},"end":{"line":236,"column":44}},"94":{"start":{"line":236,"column":20},"end":{"line":236,"column":43}},"95":{"start":{"line":241,"column":2},"end":{"line":243,"column":3}},"96":{"start":{"line":242,"column":3},"end":{"line":242,"column":82}},"97":{"start":{"line":242,"column":38},"end":{"line":242,"column":80}},"98":{"start":{"line":242,"column":70},"end":{"line":242,"column":79}},"99":{"start":{"line":245,"column":2},"end":{"line":251,"column":4}},"100":{"start":{"line":246,"column":3},"end":{"line":250,"column":26}},"101":{"start":{"line":250,"column":16},"end":{"line":250,"column":25}},"102":{"start":{"line":255,"column":2},"end":{"line":257,"column":3}},"103":{"start":{"line":256,"column":3},"end":{"line":256,"column":16}},"104":{"start":{"line":259,"column":2},"end":{"line":271,"column":5}},"105":{"start":{"line":260,"column":22},"end":{"line":260,"column":31}},"106":{"start":{"line":261,"column":18},"end":{"line":263,"column":5}},"107":{"start":{"line":265,"column":3},"end":{"line":270,"column":114}},"108":{"start":{"line":270,"column":26},"end":{"line":270,"column":112}},"109":{"start":{"line":270,"column":63},"end":{"line":270,"column":93}},"110":{"start":{"line":270,"column":107},"end":{"line":270,"column":111}},"111":{"start":{"line":275,"column":2},"end":{"line":277,"column":3}},"112":{"start":{"line":276,"column":3},"end":{"line":276,"column":16}},"113":{"start":{"line":279,"column":2},"end":{"line":291,"column":5}},"114":{"start":{"line":280,"column":22},"end":{"line":280,"column":31}},"115":{"start":{"line":281,"column":18},"end":{"line":283,"column":5}},"116":{"start":{"line":285,"column":3},"end":{"line":290,"column":124}},"117":{"start":{"line":290,"column":31},"end":{"line":290,"column":122}},"118":{"start":{"line":290,"column":73},"end":{"line":290,"column":103}},"119":{"start":{"line":290,"column":117},"end":{"line":290,"column":121}},"120":{"start":{"line":295,"column":19},"end":{"line":301,"column":3}},"121":{"start":{"line":296,"column":3},"end":{"line":300,"column":31}},"122":{"start":{"line":300,"column":14},"end":{"line":300,"column":30}},"123":{"start":{"line":302,"column":2},"end":{"line":302,"column":19}},"124":{"start":{"line":306,"column":2},"end":{"line":310,"column":3}},"125":{"start":{"line":307,"column":3},"end":{"line":309,"column":29}},"126":{"start":{"line":307,"column":38},"end":{"line":309,"column":27}},"127":{"start":{"line":309,"column":17},"end":{"line":309,"column":26}},"128":{"start":{"line":312,"column":2},"end":{"line":316,"column":27}},"129":{"start":{"line":313,"column":3},"end":{"line":315,"column":4}},"130":{"start":{"line":316,"column":16},"end":{"line":316,"column":25}},"131":{"start":{"line":320,"column":0},"end":{"line":320,"column":27}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":11,"column":1},"end":{"line":11,"column":2}},"loc":{"start":{"line":11,"column":27},"end":{"line":118,"column":2}},"line":11},"1":{"name":"(anonymous_1)","decl":{"start":{"line":34,"column":4},"end":{"line":34,"column":5}},"loc":{"start":{"line":34,"column":13},"end":{"line":34,"column":34}},"line":34},"2":{"name":"(anonymous_2)","decl":{"start":{"line":40,"column":4},"end":{"line":40,"column":5}},"loc":{"start":{"line":40,"column":13},"end":{"line":40,"column":33}},"line":40},"3":{"name":"(anonymous_3)","decl":{"start":{"line":45,"column":29},"end":{"line":45,"column":30}},"loc":{"start":{"line":45,"column":40},"end":{"line":117,"column":3}},"line":45},"4":{"name":"(anonymous_4)","decl":{"start":{"line":47,"column":6},"end":{"line":47,"column":7}},"loc":{"start":{"line":47,"column":25},"end":{"line":116,"column":5}},"line":47},"5":{"name":"(anonymous_5)","decl":{"start":{"line":120,"column":1},"end":{"line":120,"column":2}},"loc":{"start":{"line":120,"column":10},"end":{"line":157,"column":2}},"line":120},"6":{"name":"(anonymous_6)","decl":{"start":{"line":122,"column":28},"end":{"line":122,"column":29}},"loc":{"start":{"line":122,"column":38},"end":{"line":145,"column":4}},"line":122},"7":{"name":"(anonymous_7)","decl":{"start":{"line":132,"column":23},"end":{"line":132,"column":24}},"loc":{"start":{"line":132,"column":34},"end":{"line":144,"column":5}},"line":132},"8":{"name":"(anonymous_8)","decl":{"start":{"line":134,"column":24},"end":{"line":134,"column":25}},"loc":{"start":{"line":134,"column":30},"end":{"line":134,"column":39}},"line":134},"9":{"name":"(anonymous_9)","decl":{"start":{"line":136,"column":22},"end":{"line":136,"column":23}},"loc":{"start":{"line":136,"column":28},"end":{"line":139,"column":6}},"line":136},"10":{"name":"(anonymous_10)","decl":{"start":{"line":141,"column":23},"end":{"line":141,"column":24}},"loc":{"start":{"line":141,"column":32},"end":{"line":143,"column":6}},"line":141},"11":{"name":"(anonymous_11)","decl":{"start":{"line":148,"column":27},"end":{"line":148,"column":28}},"loc":{"start":{"line":149,"column":3},"end":{"line":155,"column":5}},"line":149},"12":{"name":"(anonymous_12)","decl":{"start":{"line":149,"column":45},"end":{"line":149,"column":46}},"loc":{"start":{"line":149,"column":52},"end":{"line":155,"column":4}},"line":149},"13":{"name":"(anonymous_13)","decl":{"start":{"line":159,"column":1},"end":{"line":159,"column":2}},"loc":{"start":{"line":159,"column":22},"end":{"line":187,"column":2}},"line":159},"14":{"name":"(anonymous_14)","decl":{"start":{"line":163,"column":28},"end":{"line":163,"column":29}},"loc":{"start":{"line":163,"column":38},"end":{"line":177,"column":4}},"line":163},"15":{"name":"(anonymous_15)","decl":{"start":{"line":171,"column":23},"end":{"line":171,"column":24}},"loc":{"start":{"line":171,"column":34},"end":{"line":176,"column":5}},"line":171},"16":{"name":"(anonymous_16)","decl":{"start":{"line":172,"column":25},"end":{"line":172,"column":26}},"loc":{"start":{"line":172,"column":31},"end":{"line":174,"column":6}},"line":172},"17":{"name":"(anonymous_17)","decl":{"start":{"line":180,"column":27},"end":{"line":180,"column":28}},"loc":{"start":{"line":181,"column":3},"end":{"line":185,"column":4}},"line":181},"18":{"name":"(anonymous_18)","decl":{"start":{"line":189,"column":1},"end":{"line":189,"column":2}},"loc":{"start":{"line":189,"column":13},"end":{"line":211,"column":2}},"line":189},"19":{"name":"(anonymous_19)","decl":{"start":{"line":195,"column":28},"end":{"line":195,"column":29}},"loc":{"start":{"line":195,"column":38},"end":{"line":203,"column":4}},"line":195},"20":{"name":"(anonymous_20)","decl":{"start":{"line":201,"column":11},"end":{"line":201,"column":12}},"loc":{"start":{"line":201,"column":20},"end":{"line":201,"column":71}},"line":201},"21":{"name":"(anonymous_21)","decl":{"start":{"line":201,"column":60},"end":{"line":201,"column":61}},"loc":{"start":{"line":201,"column":66},"end":{"line":201,"column":70}},"line":201},"22":{"name":"(anonymous_22)","decl":{"start":{"line":202,"column":12},"end":{"line":202,"column":13}},"loc":{"start":{"line":202,"column":18},"end":{"line":202,"column":23}},"line":202},"23":{"name":"(anonymous_23)","decl":{"start":{"line":206,"column":27},"end":{"line":206,"column":28}},"loc":{"start":{"line":207,"column":3},"end":{"line":209,"column":44}},"line":207},"24":{"name":"(anonymous_24)","decl":{"start":{"line":209,"column":10},"end":{"line":209,"column":11}},"loc":{"start":{"line":209,"column":20},"end":{"line":209,"column":43}},"line":209},"25":{"name":"(anonymous_25)","decl":{"start":{"line":213,"column":1},"end":{"line":213,"column":2}},"loc":{"start":{"line":213,"column":18},"end":{"line":238,"column":2}},"line":213},"26":{"name":"(anonymous_26)","decl":{"start":{"line":215,"column":28},"end":{"line":215,"column":29}},"loc":{"start":{"line":215,"column":38},"end":{"line":230,"column":4}},"line":215},"27":{"name":"(anonymous_27)","decl":{"start":{"line":222,"column":6},"end":{"line":222,"column":7}},"loc":{"start":{"line":222,"column":15},"end":{"line":229,"column":7}},"line":222},"28":{"name":"(anonymous_28)","decl":{"start":{"line":227,"column":17},"end":{"line":227,"column":18}},"loc":{"start":{"line":227,"column":25},"end":{"line":227,"column":55}},"line":227},"29":{"name":"(anonymous_29)","decl":{"start":{"line":233,"column":27},"end":{"line":233,"column":28}},"loc":{"start":{"line":234,"column":3},"end":{"line":236,"column":44}},"line":234},"30":{"name":"(anonymous_30)","decl":{"start":{"line":236,"column":10},"end":{"line":236,"column":11}},"loc":{"start":{"line":236,"column":20},"end":{"line":236,"column":43}},"line":236},"31":{"name":"(anonymous_31)","decl":{"start":{"line":240,"column":1},"end":{"line":240,"column":2}},"loc":{"start":{"line":240,"column":9},"end":{"line":252,"column":2}},"line":240},"32":{"name":"(anonymous_32)","decl":{"start":{"line":242,"column":28},"end":{"line":242,"column":29}},"loc":{"start":{"line":242,"column":38},"end":{"line":242,"column":80}},"line":242},"33":{"name":"(anonymous_33)","decl":{"start":{"line":242,"column":64},"end":{"line":242,"column":65}},"loc":{"start":{"line":242,"column":70},"end":{"line":242,"column":79}},"line":242},"34":{"name":"(anonymous_34)","decl":{"start":{"line":245,"column":27},"end":{"line":245,"column":28}},"loc":{"start":{"line":246,"column":3},"end":{"line":250,"column":26}},"line":246},"35":{"name":"(anonymous_35)","decl":{"start":{"line":250,"column":10},"end":{"line":250,"column":11}},"loc":{"start":{"line":250,"column":16},"end":{"line":250,"column":25}},"line":250},"36":{"name":"(anonymous_36)","decl":{"start":{"line":254,"column":1},"end":{"line":254,"column":2}},"loc":{"start":{"line":254,"column":16},"end":{"line":272,"column":2}},"line":254},"37":{"name":"(anonymous_37)","decl":{"start":{"line":259,"column":27},"end":{"line":259,"column":28}},"loc":{"start":{"line":259,"column":37},"end":{"line":271,"column":3}},"line":259},"38":{"name":"(anonymous_38)","decl":{"start":{"line":270,"column":10},"end":{"line":270,"column":11}},"loc":{"start":{"line":270,"column":26},"end":{"line":270,"column":112}},"line":270},"39":{"name":"(anonymous_39)","decl":{"start":{"line":270,"column":55},"end":{"line":270,"column":56}},"loc":{"start":{"line":270,"column":63},"end":{"line":270,"column":93}},"line":270},"40":{"name":"(anonymous_40)","decl":{"start":{"line":270,"column":101},"end":{"line":270,"column":102}},"loc":{"start":{"line":270,"column":107},"end":{"line":270,"column":111}},"line":270},"41":{"name":"(anonymous_41)","decl":{"start":{"line":274,"column":1},"end":{"line":274,"column":2}},"loc":{"start":{"line":274,"column":25},"end":{"line":292,"column":2}},"line":274},"42":{"name":"(anonymous_42)","decl":{"start":{"line":279,"column":27},"end":{"line":279,"column":28}},"loc":{"start":{"line":279,"column":37},"end":{"line":291,"column":3}},"line":279},"43":{"name":"(anonymous_43)","decl":{"start":{"line":290,"column":10},"end":{"line":290,"column":11}},"loc":{"start":{"line":290,"column":31},"end":{"line":290,"column":122}},"line":290},"44":{"name":"(anonymous_44)","decl":{"start":{"line":290,"column":65},"end":{"line":290,"column":66}},"loc":{"start":{"line":290,"column":73},"end":{"line":290,"column":103}},"line":290},"45":{"name":"(anonymous_45)","decl":{"start":{"line":290,"column":111},"end":{"line":290,"column":112}},"loc":{"start":{"line":290,"column":117},"end":{"line":290,"column":121}},"line":290},"46":{"name":"(anonymous_46)","decl":{"start":{"line":294,"column":1},"end":{"line":294,"column":2}},"loc":{"start":{"line":294,"column":29},"end":{"line":303,"column":2}},"line":294},"47":{"name":"(anonymous_47)","decl":{"start":{"line":295,"column":43},"end":{"line":295,"column":44}},"loc":{"start":{"line":296,"column":3},"end":{"line":300,"column":31}},"line":296},"48":{"name":"(anonymous_48)","decl":{"start":{"line":300,"column":9},"end":{"line":300,"column":10}},"loc":{"start":{"line":300,"column":14},"end":{"line":300,"column":30}},"line":300},"49":{"name":"(anonymous_49)","decl":{"start":{"line":305,"column":1},"end":{"line":305,"column":2}},"loc":{"start":{"line":305,"column":10},"end":{"line":317,"column":2}},"line":305},"50":{"name":"(anonymous_50)","decl":{"start":{"line":307,"column":28},"end":{"line":307,"column":29}},"loc":{"start":{"line":307,"column":38},"end":{"line":309,"column":27}},"line":307},"51":{"name":"(anonymous_51)","decl":{"start":{"line":309,"column":10},"end":{"line":309,"column":11}},"loc":{"start":{"line":309,"column":17},"end":{"line":309,"column":26}},"line":309},"52":{"name":"(anonymous_52)","decl":{"start":{"line":312,"column":27},"end":{"line":312,"column":28}},"loc":{"start":{"line":313,"column":3},"end":{"line":315,"column":4}},"line":313},"53":{"name":"(anonymous_53)","decl":{"start":{"line":316,"column":9},"end":{"line":316,"column":10}},"loc":{"start":{"line":316,"column":16},"end":{"line":316,"column":25}},"line":316}},"branchMap":{"0":{"loc":{"start":{"line":14,"column":8},"end":{"line":14,"column":17}},"type":"binary-expr","locations":[{"start":{"line":14,"column":8},"end":{"line":14,"column":11}},{"start":{"line":14,"column":15},"end":{"line":14,"column":17}}],"line":14},"1":{"loc":{"start":{"line":15,"column":2},"end":{"line":17,"column":3}},"type":"if","locations":[{"start":{"line":15,"column":2},"end":{"line":17,"column":3}},{"start":{"line":15,"column":2},"end":{"line":17,"column":3}}],"line":15},"2":{"loc":{"start":{"line":19,"column":2},"end":{"line":21,"column":3}},"type":"if","locations":[{"start":{"line":19,"column":2},"end":{"line":21,"column":3}},{"start":{"line":19,"column":2},"end":{"line":21,"column":3}}],"line":19},"3":{"loc":{"start":{"line":48,"column":5},"end":{"line":50,"column":6}},"type":"if","locations":[{"start":{"line":48,"column":5},"end":{"line":50,"column":6}},{"start":{"line":48,"column":5},"end":{"line":50,"column":6}}],"line":48},"4":{"loc":{"start":{"line":53,"column":5},"end":{"line":115,"column":6}},"type":"if","locations":[{"start":{"line":53,"column":5},"end":{"line":115,"column":6}},{"start":{"line":53,"column":5},"end":{"line":115,"column":6}}],"line":53},"5":{"loc":{"start":{"line":55,"column":23},"end":{"line":55,"column":60}},"type":"binary-expr","locations":[{"start":{"line":55,"column":23},"end":{"line":55,"column":47}},{"start":{"line":55,"column":51},"end":{"line":55,"column":60}}],"line":55},"6":{"loc":{"start":{"line":121,"column":2},"end":{"line":146,"column":3}},"type":"if","locations":[{"start":{"line":121,"column":2},"end":{"line":146,"column":3}},{"start":{"line":121,"column":2},"end":{"line":146,"column":3}}],"line":121},"7":{"loc":{"start":{"line":150,"column":4},"end":{"line":152,"column":5}},"type":"if","locations":[{"start":{"line":150,"column":4},"end":{"line":152,"column":5}},{"start":{"line":150,"column":4},"end":{"line":152,"column":5}}],"line":150},"8":{"loc":{"start":{"line":160,"column":20},"end":{"line":160,"column":79}},"type":"cond-expr","locations":[{"start":{"line":160,"column":46},"end":{"line":160,"column":72}},{"start":{"line":160,"column":75},"end":{"line":160,"column":79}}],"line":160},"9":{"loc":{"start":{"line":162,"column":2},"end":{"line":178,"column":3}},"type":"if","locations":[{"start":{"line":162,"column":2},"end":{"line":178,"column":3}},{"start":{"line":162,"column":2},"end":{"line":178,"column":3}}],"line":162},"10":{"loc":{"start":{"line":190,"column":2},"end":{"line":192,"column":3}},"type":"if","locations":[{"start":{"line":190,"column":2},"end":{"line":192,"column":3}},{"start":{"line":190,"column":2},"end":{"line":192,"column":3}}],"line":190},"11":{"loc":{"start":{"line":194,"column":2},"end":{"line":204,"column":3}},"type":"if","locations":[{"start":{"line":194,"column":2},"end":{"line":204,"column":3}},{"start":{"line":194,"column":2},"end":{"line":204,"column":3}}],"line":194},"12":{"loc":{"start":{"line":214,"column":2},"end":{"line":231,"column":3}},"type":"if","locations":[{"start":{"line":214,"column":2},"end":{"line":231,"column":3}},{"start":{"line":214,"column":2},"end":{"line":231,"column":3}}],"line":214},"13":{"loc":{"start":{"line":223,"column":7},"end":{"line":225,"column":8}},"type":"if","locations":[{"start":{"line":223,"column":7},"end":{"line":225,"column":8}},{"start":{"line":223,"column":7},"end":{"line":225,"column":8}}],"line":223},"14":{"loc":{"start":{"line":241,"column":2},"end":{"line":243,"column":3}},"type":"if","locations":[{"start":{"line":241,"column":2},"end":{"line":243,"column":3}},{"start":{"line":241,"column":2},"end":{"line":243,"column":3}}],"line":241},"15":{"loc":{"start":{"line":255,"column":2},"end":{"line":257,"column":3}},"type":"if","locations":[{"start":{"line":255,"column":2},"end":{"line":257,"column":3}},{"start":{"line":255,"column":2},"end":{"line":257,"column":3}}],"line":255},"16":{"loc":{"start":{"line":275,"column":2},"end":{"line":277,"column":3}},"type":"if","locations":[{"start":{"line":275,"column":2},"end":{"line":277,"column":3}},{"start":{"line":275,"column":2},"end":{"line":277,"column":3}}],"line":275},"17":{"loc":{"start":{"line":298,"column":25},"end":{"line":298,"column":59}},"type":"cond-expr","locations":[{"start":{"line":298,"column":37},"end":{"line":298,"column":52}},{"start":{"line":298,"column":55},"end":{"line":298,"column":59}}],"line":298},"18":{"loc":{"start":{"line":306,"column":2},"end":{"line":310,"column":3}},"type":"if","locations":[{"start":{"line":306,"column":2},"end":{"line":310,"column":3}},{"start":{"line":306,"column":2},"end":{"line":310,"column":3}}],"line":306}},"s":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":363,"7":363,"8":363,"9":363,"10":342,"11":363,"12":3,"13":363,"14":363,"15":1814,"16":363,"17":1814,"18":363,"19":363,"20":362,"21":1,"22":361,"23":361,"24":14,"25":14,"26":14,"27":14,"28":14,"29":14,"30":14,"31":28,"32":14,"33":28,"34":14,"35":347,"36":347,"37":347,"38":347,"39":1735,"40":347,"41":37,"42":6,"43":6,"44":6,"45":6,"46":6,"47":6,"48":4,"49":6,"50":2,"51":2,"52":6,"53":2,"54":31,"55":31,"56":31,"57":12,"58":19,"59":58,"60":58,"61":6,"62":6,"63":6,"64":6,"65":6,"66":6,"67":52,"68":52,"69":16,"70":3,"71":13,"72":2,"73":2,"74":2,"75":2,"76":2,"77":1,"78":1,"79":11,"80":11,"81":11,"82":5,"83":2,"84":2,"85":2,"86":2,"87":2,"88":1,"89":1,"90":3,"91":1,"92":3,"93":3,"94":3,"95":307,"96":1,"97":1,"98":1,"99":306,"100":306,"101":306,"102":2,"103":1,"104":1,"105":1,"106":1,"107":1,"108":1,"109":1,"110":1,"111":2,"112":1,"113":1,"114":1,"115":1,"116":1,"117":1,"118":0,"119":1,"120":3,"121":3,"122":15,"123":3,"124":4,"125":2,"126":2,"127":2,"128":2,"129":2,"130":2,"131":1},"f":{"0":363,"1":1814,"2":1814,"3":363,"4":362,"5":37,"6":6,"7":6,"8":4,"9":2,"10":2,"11":31,"12":31,"13":58,"14":6,"15":6,"16":6,"17":52,"18":16,"19":2,"20":2,"21":1,"22":1,"23":11,"24":11,"25":5,"26":2,"27":2,"28":3,"29":3,"30":3,"31":307,"32":1,"33":1,"34":306,"35":306,"36":2,"37":1,"38":1,"39":1,"40":1,"41":2,"42":1,"43":1,"44":0,"45":1,"46":3,"47":3,"48":15,"49":4,"50":2,"51":2,"52":2,"53":2},"b":{"0":[363,1],"1":[342,21],"2":[3,360],"3":[1,361],"4":[14,347],"5":[14,14],"6":[6,31],"7":[12,19],"8":[8,50],"9":[6,52],"10":[3,13],"11":[2,11],"12":[2,3],"13":[1,1],"14":[1,306],"15":[1,1],"16":[1,1],"17":[3,0],"18":[2,2]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"05b7c7edbf3e32937488309d6fee364182360962","contentHash":"cb513fabb420917136a79e4914d46bae7003a9bf485c7671aba32a6b402990dc"}}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":"e5f2a160-d88e-49f6-8163-497c124f9412","pid":49572,"argv":["/Users/jaredwray/.nvm/versions/node/v16.13.1/bin/node","/Users/jaredwray/src/github.com/jaredwray/keyv/node_modules/ava/lib/worker/base.js"],"execArgv":["--enable-source-maps"],"cwd":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo","time":1646226471927,"ppid":49565,"coverageFilename":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/.nyc_output/735a3ced-e6b6-402c-aaa5-3b4f8904072b.json","externalId":"","uuid":"735a3ced-e6b6-402c-aaa5-3b4f8904072b","files":["/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":null,"pid":
|
|
1
|
+
{"parent":null,"pid":49572,"argv":["/Users/jaredwray/.nvm/versions/node/v16.13.1/bin/node","/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/node_modules/.bin/ava"],"execArgv":[],"cwd":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo","time":1646226471738,"ppid":49565,"coverageFilename":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/.nyc_output/e5f2a160-d88e-49f6-8163-497c124f9412.json","externalId":"","uuid":"e5f2a160-d88e-49f6-8163-497c124f9412","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"735a3ced-e6b6-402c-aaa5-3b4f8904072b":{"parent":"e5f2a160-d88e-49f6-8163-497c124f9412","children":[]},"e5f2a160-d88e-49f6-8163-497c124f9412":{"parent":null,"children":["735a3ced-e6b6-402c-aaa5-3b4f8904072b"]}},"files":{"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js":["735a3ced-e6b6-402c-aaa5-3b4f8904072b"]},"externalIds":{}}
|
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
> MongoDB storage adapter for Keyv
|
|
4
4
|
|
|
5
|
-
[](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml)
|
|
6
|
+
[](https://codecov.io/gh/jaredwray/keyv)
|
|
7
7
|
[](https://www.npmjs.com/package/@keyv/mongo)
|
|
8
8
|
|
|
9
9
|
MongoDB storage adapter for [Keyv](https://github.com/jaredwray/keyv).
|
package/package.json
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
2
|
+
"name": "@keyv/mongo",
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "MongoDB storage adapter for Keyv",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "xo && nyc ava",
|
|
8
|
+
"coverage": "nyc report --reporter=text-lcov > coverage.lcov",
|
|
9
|
+
"clean": "rm -rf node_modules && rm -rf .nyc_output && rm -rf coverage.lcov"
|
|
10
|
+
},
|
|
11
|
+
"xo": {
|
|
12
|
+
"extends": "xo-lukechilds",
|
|
13
|
+
"rules": {
|
|
14
|
+
"unicorn/prefer-module": 0,
|
|
15
|
+
"unicorn/no-array-reduce": 0,
|
|
16
|
+
"unicorn/prefer-object-from-entries": 0
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"ava": {
|
|
20
|
+
"require": [
|
|
21
|
+
"requirable"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/jaredwray/keyv.git"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"mongo",
|
|
30
|
+
"mongodb",
|
|
31
|
+
"keyv",
|
|
32
|
+
"storage",
|
|
33
|
+
"adapter",
|
|
34
|
+
"key",
|
|
35
|
+
"value",
|
|
36
|
+
"store",
|
|
37
|
+
"cache",
|
|
38
|
+
"ttl"
|
|
39
|
+
],
|
|
40
|
+
"author": "Jared Wray <me@jaredwray.com> (https://jaredwray.com)",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/jaredwray/keyv/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/jaredwray/keyv",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"mongodb": "^4.4.0",
|
|
48
|
+
"pify": "^5.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@keyv/test-suite": "*",
|
|
52
|
+
"ava": "^4.0.1",
|
|
53
|
+
"eslint-config-xo-lukechilds": "^1.0.1",
|
|
54
|
+
"keyv": "*",
|
|
55
|
+
"nyc": "^15.1.0",
|
|
56
|
+
"requirable": "^1.0.5",
|
|
57
|
+
"this": "^1.1.0",
|
|
58
|
+
"xo": "^0.48.0"
|
|
59
|
+
}
|
|
60
60
|
}
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const EventEmitter = require('events');
|
|
4
|
-
const
|
|
4
|
+
const Buffer = require('buffer').Buffer;
|
|
5
|
+
const mongoClient = require('mongodb').MongoClient;
|
|
6
|
+
const GridFSBucket = require('mongodb').GridFSBucket;
|
|
5
7
|
const pify = require('pify');
|
|
6
8
|
|
|
9
|
+
const keyvMongoKeys = new Set(['url', 'collection', 'namespace', 'serialize', 'deserialize', 'uri', 'useGridFS', 'dialect']);
|
|
7
10
|
class KeyvMongo extends EventEmitter {
|
|
8
11
|
constructor(url, options) {
|
|
9
12
|
super();
|
|
@@ -17,43 +20,170 @@ class KeyvMongo extends EventEmitter {
|
|
|
17
20
|
url = Object.assign({ url: url.uri }, url);
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
this.opts = Object.assign(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
this.opts = Object.assign(
|
|
24
|
+
{
|
|
25
|
+
url: 'mongodb://127.0.0.1:27017',
|
|
26
|
+
collection: 'keyv',
|
|
27
|
+
},
|
|
28
|
+
url,
|
|
29
|
+
options,
|
|
30
|
+
);
|
|
25
31
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const mongoOptions = Object.fromEntries(
|
|
33
|
+
Object.entries(this.opts).filter(
|
|
34
|
+
([k]) => !keyvMongoKeys.has(k),
|
|
35
|
+
),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
this.opts = Object.fromEntries(
|
|
39
|
+
Object.entries(this.opts).filter(
|
|
40
|
+
([k]) => keyvMongoKeys.has(k),
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Implementation from sql by lukechilds,
|
|
45
|
+
this.connect = new Promise(resolve => {
|
|
46
|
+
mongoClient.connect(this.opts.url, mongoOptions
|
|
47
|
+
, (error, client) => {
|
|
48
|
+
if (error) {
|
|
49
|
+
return this.emit('error', error);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.db = client.db(this.opts.db);
|
|
53
|
+
if (this.opts.useGridFS) {
|
|
54
|
+
this.bucket = new GridFSBucket(this.db, {
|
|
55
|
+
readPreference: this.opts.readPreference || 'primary',
|
|
56
|
+
bucketName: this.opts.collection,
|
|
57
|
+
});
|
|
58
|
+
this.store = this.db.collection(this.opts.collection + '.files');
|
|
59
|
+
this.store.createIndex({
|
|
60
|
+
filename: 'hashed',
|
|
61
|
+
});
|
|
62
|
+
this.store.createIndex({
|
|
63
|
+
uploadDate: -1,
|
|
64
|
+
});
|
|
65
|
+
this.store.createIndex({
|
|
66
|
+
'metadata.expiresAt': 1,
|
|
67
|
+
});
|
|
68
|
+
this.store.createIndex({
|
|
69
|
+
'metadata.lastAccessed': 1,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
for (const method of [
|
|
73
|
+
'updateOne',
|
|
74
|
+
'count',
|
|
75
|
+
]) {
|
|
76
|
+
this.store[method] = pify(this.store[method].bind(this.store));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
for (const method of [
|
|
80
|
+
'find',
|
|
81
|
+
'drop',
|
|
82
|
+
]) {
|
|
83
|
+
this.bucket[method] = pify(this.bucket[method].bind(this.bucket));
|
|
84
|
+
}
|
|
39
85
|
|
|
40
|
-
|
|
86
|
+
resolve({ bucket: this.bucket, store: this.store, db: this.db });
|
|
87
|
+
} else {
|
|
88
|
+
this.store = this.db.collection(this.opts.collection);
|
|
89
|
+
this.store.createIndex(
|
|
90
|
+
{ key: 1 },
|
|
91
|
+
{
|
|
92
|
+
unique: true,
|
|
93
|
+
background: true,
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
this.store.createIndex(
|
|
97
|
+
{ expiresAt: 1 },
|
|
98
|
+
{
|
|
99
|
+
expireAfterSeconds: 0,
|
|
100
|
+
background: true,
|
|
101
|
+
},
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
for (const method of [
|
|
105
|
+
'updateOne',
|
|
106
|
+
'findOne',
|
|
107
|
+
'deleteOne',
|
|
108
|
+
'deleteMany',
|
|
109
|
+
'count',
|
|
110
|
+
]) {
|
|
111
|
+
this.store[method] = pify(this.store[method].bind(this.store));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
resolve(this.store);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
41
118
|
}
|
|
42
119
|
|
|
43
120
|
get(key) {
|
|
44
|
-
|
|
45
|
-
.then(
|
|
46
|
-
|
|
121
|
+
if (this.opts.useGridFS) {
|
|
122
|
+
return this.connect.then(client => {
|
|
123
|
+
client.store.updateOne({
|
|
124
|
+
filename: key,
|
|
125
|
+
}, {
|
|
126
|
+
$set: {
|
|
127
|
+
'metadata.lastAccessed': new Date(),
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const stream = client.bucket.openDownloadStreamByName(key);
|
|
132
|
+
return new Promise(resolve => {
|
|
133
|
+
let resp = [];
|
|
134
|
+
stream.on('error', () => resolve());
|
|
135
|
+
|
|
136
|
+
stream.on('end', () => {
|
|
137
|
+
resp = Buffer.concat(resp).toString('utf-8');
|
|
138
|
+
resolve(resp);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
stream.on('data', chunk => {
|
|
142
|
+
resp.push(chunk);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return this.connect.then(store =>
|
|
149
|
+
store.findOne({ key: { $eq: key } }).then(doc => {
|
|
150
|
+
if (!doc) {
|
|
47
151
|
return undefined;
|
|
48
152
|
}
|
|
49
153
|
|
|
50
154
|
return doc.value;
|
|
51
|
-
})
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
52
157
|
}
|
|
53
158
|
|
|
54
159
|
set(key, value, ttl) {
|
|
55
|
-
const expiresAt =
|
|
56
|
-
|
|
160
|
+
const expiresAt = typeof ttl === 'number' ? new Date(Date.now() + ttl) : null;
|
|
161
|
+
|
|
162
|
+
if (this.opts.useGridFS) {
|
|
163
|
+
return this.connect.then(client => {
|
|
164
|
+
const stream = client.bucket.openUploadStream(key, {
|
|
165
|
+
metadata: {
|
|
166
|
+
expiresAt,
|
|
167
|
+
lastAccessed: new Date(),
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return new Promise(resolve => {
|
|
172
|
+
stream.on('finish', () => {
|
|
173
|
+
resolve(stream);
|
|
174
|
+
});
|
|
175
|
+
stream.end(value);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return this.connect.then(store =>
|
|
181
|
+
store.updateOne(
|
|
182
|
+
{ key: { $eq: key } },
|
|
183
|
+
{ $set: { key, value, expiresAt } },
|
|
184
|
+
{ upsert: true },
|
|
185
|
+
),
|
|
186
|
+
);
|
|
57
187
|
}
|
|
58
188
|
|
|
59
189
|
delete(key) {
|
|
@@ -61,13 +191,129 @@ class KeyvMongo extends EventEmitter {
|
|
|
61
191
|
return Promise.resolve(false);
|
|
62
192
|
}
|
|
63
193
|
|
|
64
|
-
|
|
65
|
-
.then(
|
|
194
|
+
if (this.opts.useGridFS) {
|
|
195
|
+
return this.connect.then(client => {
|
|
196
|
+
const connection = client.db;
|
|
197
|
+
const bucket = new GridFSBucket(connection, {
|
|
198
|
+
bucketName: this.opts.collection,
|
|
199
|
+
});
|
|
200
|
+
return bucket.find({ filename: key }).toArray()
|
|
201
|
+
.then(files => client.bucket.delete(files[0]._id).then(() => true))
|
|
202
|
+
.catch(() => false);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return this.connect.then(store =>
|
|
207
|
+
store
|
|
208
|
+
.deleteOne({ key: { $eq: key } })
|
|
209
|
+
.then(object => object.deletedCount > 0),
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
deleteMany(keys) {
|
|
214
|
+
if (this.opts.useGridFS) {
|
|
215
|
+
return this.connect.then(client => {
|
|
216
|
+
const connection = client.db;
|
|
217
|
+
const bucket = new GridFSBucket(connection, {
|
|
218
|
+
bucketName: this.opts.collection,
|
|
219
|
+
});
|
|
220
|
+
return bucket.find({ filename: { $in: keys } }).toArray()
|
|
221
|
+
.then(
|
|
222
|
+
files => {
|
|
223
|
+
if (files.length === 0) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
files.map(file => client.bucket.delete(file._id));
|
|
228
|
+
return true;
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return this.connect.then(store =>
|
|
234
|
+
store
|
|
235
|
+
.deleteMany({ key: { $in: keys } })
|
|
236
|
+
.then(object => object.deletedCount > 0),
|
|
237
|
+
);
|
|
66
238
|
}
|
|
67
239
|
|
|
68
240
|
clear() {
|
|
69
|
-
|
|
70
|
-
.then(() => undefined);
|
|
241
|
+
if (this.opts.useGridFS) {
|
|
242
|
+
return this.connect.then(client => client.bucket.drop().then(() => undefined));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return this.connect.then(store =>
|
|
246
|
+
store
|
|
247
|
+
.deleteMany({
|
|
248
|
+
key: new RegExp(`^${this.namespace}:`),
|
|
249
|
+
})
|
|
250
|
+
.then(() => undefined),
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
clearExpired() {
|
|
255
|
+
if (!this.opts.useGridFS) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return this.connect.then(client => {
|
|
260
|
+
const connection = client.db;
|
|
261
|
+
const bucket = new GridFSBucket(connection, {
|
|
262
|
+
bucketName: this.opts.collection,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
return bucket.find({
|
|
266
|
+
'metadata.expiresAt': {
|
|
267
|
+
$lte: new Date(Date.now()),
|
|
268
|
+
},
|
|
269
|
+
}).toArray()
|
|
270
|
+
.then(expiredFiles => Promise.all(expiredFiles.map(file => client.bucket.delete(file._id))).then(() => true));
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
clearUnusedFor(seconds) {
|
|
275
|
+
if (!this.opts.useGridFS) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return this.connect.then(client => {
|
|
280
|
+
const connection = client.db;
|
|
281
|
+
const bucket = new GridFSBucket(connection, {
|
|
282
|
+
bucketName: this.opts.collection,
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
return bucket.find({
|
|
286
|
+
'metadata.lastAccessed': {
|
|
287
|
+
$lte: new Date(Date.now() - (seconds * 1000)),
|
|
288
|
+
},
|
|
289
|
+
}).toArray()
|
|
290
|
+
.then(lastAccessedFiles => Promise.all(lastAccessedFiles.map(file => client.bucket.delete(file._id))).then(() => true));
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async * iterator(namespace) {
|
|
295
|
+
const iterator = await this.connect.then(store =>
|
|
296
|
+
store
|
|
297
|
+
.find({
|
|
298
|
+
key: new RegExp(`^${namespace ? namespace + ':' : '.*'}`),
|
|
299
|
+
})
|
|
300
|
+
.map(x => [x.key, x.value]),
|
|
301
|
+
);
|
|
302
|
+
yield * iterator;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
has(key) {
|
|
306
|
+
if (this.opts.useGridFS) {
|
|
307
|
+
return this.connect.then(client => client.store.count(
|
|
308
|
+
{ filename: { $eq: key } },
|
|
309
|
+
).then(doc => doc !== 0));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return this.connect.then(store =>
|
|
313
|
+
store.count(
|
|
314
|
+
{ key: { $eq: key } },
|
|
315
|
+
),
|
|
316
|
+
).then(doc => doc !== 0);
|
|
71
317
|
}
|
|
72
318
|
}
|
|
73
319
|
|
package/test/test.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
const test = require('ava');
|
|
2
2
|
const keyvTestSuite = require('@keyv/test-suite').default;
|
|
3
|
+
const { keyvOfficialTests, keyvIteratorTests } = require('@keyv/test-suite');
|
|
3
4
|
const Keyv = require('keyv');
|
|
4
5
|
const KeyvMongo = require('this');
|
|
5
6
|
|
|
7
|
+
const options = { useNewUrlParser: true, useUnifiedTopology: true, serverSelectionTimeoutMS: 5000 };
|
|
8
|
+
|
|
6
9
|
const mongoURL = 'mongodb://127.0.0.1:27017';
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
keyvOfficialTests(test, Keyv, mongoURL, 'mongodb://foo', options);
|
|
12
|
+
|
|
13
|
+
const store = () => new KeyvMongo(mongoURL, options);
|
|
9
14
|
keyvTestSuite(test, Keyv, store);
|
|
15
|
+
keyvIteratorTests(test, Keyv, store);
|
|
10
16
|
|
|
11
17
|
test('default options', t => {
|
|
12
18
|
const store = new KeyvMongo();
|
|
@@ -30,6 +36,22 @@ test('Collection option merges into default options', t => {
|
|
|
30
36
|
});
|
|
31
37
|
});
|
|
32
38
|
|
|
39
|
+
test('useGridFS .has(key) where key is the key we are looking for', async t => {
|
|
40
|
+
const keyv = new KeyvMongo({ useGridFS: true, collection: 'foo' });
|
|
41
|
+
await keyv.set('foo', 'bar');
|
|
42
|
+
t.is(await keyv.has('foo'), true);
|
|
43
|
+
t.is(await keyv.has('fizz'), false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('useGridFS option merges into default options', t => {
|
|
47
|
+
const store = new KeyvMongo({ useGridFS: true, collection: 'foo' });
|
|
48
|
+
t.deepEqual(store.opts, {
|
|
49
|
+
url: mongoURL,
|
|
50
|
+
useGridFS: true,
|
|
51
|
+
collection: 'foo',
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
33
55
|
test('Collection option merges into default options if URL is passed', t => {
|
|
34
56
|
const store = new KeyvMongo(mongoURL, { collection: 'foo' });
|
|
35
57
|
t.deepEqual(store.opts, {
|
|
@@ -39,6 +61,127 @@ test('Collection option merges into default options if URL is passed', t => {
|
|
|
39
61
|
});
|
|
40
62
|
|
|
41
63
|
test('.delete() with no args doesn\'t empty the collection', async t => {
|
|
42
|
-
const store = new KeyvMongo('foo'); // Make sure we don't actually connect
|
|
64
|
+
const store = new KeyvMongo('mongodb://foo'); // Make sure we don't actually connect
|
|
43
65
|
t.false(await store.delete());
|
|
44
66
|
});
|
|
67
|
+
|
|
68
|
+
test('.delete() with key as number', async t => {
|
|
69
|
+
const store = new KeyvMongo(mongoURL, { collection: 'foo' });
|
|
70
|
+
t.false(await store.delete(123));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test.serial('Stores value in GridFS', async t => {
|
|
74
|
+
const store = new KeyvMongo(Object.assign({
|
|
75
|
+
useGridFS: true,
|
|
76
|
+
}, options));
|
|
77
|
+
const result = await store.set('key1', 'keyv1', 0);
|
|
78
|
+
const get = await store.get('key1');
|
|
79
|
+
t.is(result.filename, 'key1');
|
|
80
|
+
t.is(get, 'keyv1');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test.serial('Gets value from GridFS', async t => {
|
|
84
|
+
const store = new KeyvMongo(Object.assign({
|
|
85
|
+
useGridFS: true,
|
|
86
|
+
}, options));
|
|
87
|
+
const result = await store.get('key1');
|
|
88
|
+
t.is(result, 'keyv1');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test.serial('Deletes value from GridFS', async t => {
|
|
92
|
+
const store = new KeyvMongo(Object.assign({
|
|
93
|
+
useGridFS: true,
|
|
94
|
+
}, options));
|
|
95
|
+
const result = await store.delete('key1');
|
|
96
|
+
t.is(result, true);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test.serial('Deletes non existent value from GridFS', async t => {
|
|
100
|
+
const store = new KeyvMongo(Object.assign({
|
|
101
|
+
useGridFS: true,
|
|
102
|
+
}, options));
|
|
103
|
+
const result = await store.delete('no-existent-value');
|
|
104
|
+
t.is(result, false);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test.serial('Stores value with TTL in GridFS', async t => {
|
|
108
|
+
const store = new KeyvMongo(Object.assign({
|
|
109
|
+
useGridFS: true,
|
|
110
|
+
}, options));
|
|
111
|
+
const result = await store.set('key1', 'keyv1', 0);
|
|
112
|
+
t.is(result.filename, 'key1');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test.serial('Clears expired value from GridFS', async t => {
|
|
116
|
+
const store = new KeyvMongo(Object.assign({
|
|
117
|
+
useGridFS: true,
|
|
118
|
+
}, options));
|
|
119
|
+
const cleared = await store.clearExpired();
|
|
120
|
+
t.is(cleared, true);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test.serial('Clears unused files from GridFS', async t => {
|
|
124
|
+
const store = new KeyvMongo(Object.assign({
|
|
125
|
+
useGridFS: true,
|
|
126
|
+
}, options));
|
|
127
|
+
const cleared = await store.clearUnusedFor(5);
|
|
128
|
+
t.is(cleared, true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test.serial('Clears expired value only when GridFS options is true', async t => {
|
|
132
|
+
const store = new KeyvMongo(Object.assign(options));
|
|
133
|
+
const cleared = await store.clearExpired();
|
|
134
|
+
t.is(cleared, false);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test.serial('Clears unused files only when GridFS options is true', async t => {
|
|
138
|
+
const store = new KeyvMongo(Object.assign(options));
|
|
139
|
+
const cleared = await store.clearUnusedFor(5);
|
|
140
|
+
t.is(cleared, false);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test.serial('Gets non-existent file and return should be undefined', async t => {
|
|
144
|
+
const store = new KeyvMongo(Object.assign({
|
|
145
|
+
useGridFS: true,
|
|
146
|
+
}, options));
|
|
147
|
+
const result = await store.get('non-existent-file');
|
|
148
|
+
t.is(typeof result, 'undefined');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test.serial('Non-string keys are not permitted in delete', async t => {
|
|
152
|
+
const store = new KeyvMongo(Object.assign({
|
|
153
|
+
useGridFS: true,
|
|
154
|
+
}, options));
|
|
155
|
+
const result = await store.delete({
|
|
156
|
+
ok: true,
|
|
157
|
+
});
|
|
158
|
+
t.is(result, false);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test.serial('.deleteMany([keys]) should delete multiple gridfs key', async t => {
|
|
162
|
+
const keyv = new KeyvMongo(Object.assign({
|
|
163
|
+
useGridFS: true,
|
|
164
|
+
}, options));
|
|
165
|
+
await keyv.set('foo', 'bar');
|
|
166
|
+
await keyv.set('foo1', 'bar1');
|
|
167
|
+
await keyv.set('foo2', 'bar2');
|
|
168
|
+
t.is(await keyv.deleteMany(['foo', 'foo1', 'foo2']), true);
|
|
169
|
+
t.is(await keyv.get('foo'), undefined);
|
|
170
|
+
t.is(await keyv.get('foo1'), undefined);
|
|
171
|
+
t.is(await keyv.get('foo2'), undefined);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test.serial('.deleteMany([keys]) with nonexistent gridfs keys resolves to false', async t => {
|
|
175
|
+
const keyv = new KeyvMongo(Object.assign({
|
|
176
|
+
useGridFS: true,
|
|
177
|
+
}, options));
|
|
178
|
+
t.is(await keyv.deleteMany(['foo', 'foo1', 'foo2']), false);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test.serial('Clears entire cache store', async t => {
|
|
182
|
+
const store = new KeyvMongo(Object.assign({
|
|
183
|
+
useGridFS: true,
|
|
184
|
+
}, options));
|
|
185
|
+
const result = await store.clear();
|
|
186
|
+
t.is(typeof result, 'undefined');
|
|
187
|
+
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js":{"path":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js","statementMap":{"0":{"start":{"line":3,"column":21},"end":{"line":3,"column":38}},"1":{"start":{"line":4,"column":16},"end":{"line":4,"column":34}},"2":{"start":{"line":5,"column":13},"end":{"line":5,"column":28}},"3":{"start":{"line":9,"column":2},"end":{"line":9,"column":10}},"4":{"start":{"line":10,"column":2},"end":{"line":10,"column":26}},"5":{"start":{"line":11,"column":2},"end":{"line":11,"column":18}},"6":{"start":{"line":12,"column":2},"end":{"line":14,"column":3}},"7":{"start":{"line":13,"column":3},"end":{"line":13,"column":17}},"8":{"start":{"line":16,"column":2},"end":{"line":18,"column":3}},"9":{"start":{"line":17,"column":3},"end":{"line":17,"column":46}},"10":{"start":{"line":20,"column":2},"end":{"line":23,"column":19}},"11":{"start":{"line":24,"column":2},"end":{"line":24,"column":35}},"12":{"start":{"line":26,"column":21},"end":{"line":26,"column":61}},"13":{"start":{"line":27,"column":2},"end":{"line":30,"column":5}},"14":{"start":{"line":31,"column":2},"end":{"line":34,"column":5}},"15":{"start":{"line":35,"column":2},"end":{"line":38,"column":9}},"16":{"start":{"line":36,"column":3},"end":{"line":36,"column":62}},"17":{"start":{"line":37,"column":3},"end":{"line":37,"column":17}},"18":{"start":{"line":40,"column":2},"end":{"line":40,"column":58}},"19":{"start":{"line":40,"column":31},"end":{"line":40,"column":56}},"20":{"start":{"line":44,"column":2},"end":{"line":51,"column":6}},"21":{"start":{"line":46,"column":4},"end":{"line":48,"column":5}},"22":{"start":{"line":47,"column":5},"end":{"line":47,"column":22}},"23":{"start":{"line":50,"column":4},"end":{"line":50,"column":21}},"24":{"start":{"line":55,"column":20},"end":{"line":55,"column":81}},"25":{"start":{"line":56,"column":2},"end":{"line":56,"column":91}},"26":{"start":{"line":60,"column":2},"end":{"line":62,"column":3}},"27":{"start":{"line":61,"column":3},"end":{"line":61,"column":33}},"28":{"start":{"line":64,"column":2},"end":{"line":65,"column":33}},"29":{"start":{"line":65,"column":19},"end":{"line":65,"column":31}},"30":{"start":{"line":69,"column":2},"end":{"line":70,"column":26}},"31":{"start":{"line":70,"column":15},"end":{"line":70,"column":24}},"32":{"start":{"line":74,"column":0},"end":{"line":74,"column":27}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":8,"column":1},"end":{"line":8,"column":2}},"loc":{"start":{"line":8,"column":27},"end":{"line":41,"column":2}},"line":8},"1":{"name":"(anonymous_1)","decl":{"start":{"line":35,"column":54},"end":{"line":35,"column":55}},"loc":{"start":{"line":35,"column":74},"end":{"line":38,"column":3}},"line":35},"2":{"name":"(anonymous_2)","decl":{"start":{"line":40,"column":22},"end":{"line":40,"column":23}},"loc":{"start":{"line":40,"column":31},"end":{"line":40,"column":56}},"line":40},"3":{"name":"(anonymous_3)","decl":{"start":{"line":43,"column":1},"end":{"line":43,"column":2}},"loc":{"start":{"line":43,"column":10},"end":{"line":52,"column":2}},"line":43},"4":{"name":"(anonymous_4)","decl":{"start":{"line":45,"column":9},"end":{"line":45,"column":10}},"loc":{"start":{"line":45,"column":16},"end":{"line":51,"column":4}},"line":45},"5":{"name":"(anonymous_5)","decl":{"start":{"line":54,"column":1},"end":{"line":54,"column":2}},"loc":{"start":{"line":54,"column":22},"end":{"line":57,"column":2}},"line":54},"6":{"name":"(anonymous_6)","decl":{"start":{"line":59,"column":1},"end":{"line":59,"column":2}},"loc":{"start":{"line":59,"column":13},"end":{"line":66,"column":2}},"line":59},"7":{"name":"(anonymous_7)","decl":{"start":{"line":65,"column":9},"end":{"line":65,"column":10}},"loc":{"start":{"line":65,"column":19},"end":{"line":65,"column":31}},"line":65},"8":{"name":"(anonymous_8)","decl":{"start":{"line":68,"column":1},"end":{"line":68,"column":2}},"loc":{"start":{"line":68,"column":9},"end":{"line":71,"column":2}},"line":68},"9":{"name":"(anonymous_9)","decl":{"start":{"line":70,"column":9},"end":{"line":70,"column":10}},"loc":{"start":{"line":70,"column":15},"end":{"line":70,"column":24}},"line":70}},"branchMap":{"0":{"loc":{"start":{"line":11,"column":8},"end":{"line":11,"column":17}},"type":"binary-expr","locations":[{"start":{"line":11,"column":8},"end":{"line":11,"column":11}},{"start":{"line":11,"column":15},"end":{"line":11,"column":17}}],"line":11},"1":{"loc":{"start":{"line":12,"column":2},"end":{"line":14,"column":3}},"type":"if","locations":[{"start":{"line":12,"column":2},"end":{"line":14,"column":3}},{"start":{"line":12,"column":2},"end":{"line":14,"column":3}}],"line":12},"2":{"loc":{"start":{"line":16,"column":2},"end":{"line":18,"column":3}},"type":"if","locations":[{"start":{"line":16,"column":2},"end":{"line":18,"column":3}},{"start":{"line":16,"column":2},"end":{"line":18,"column":3}}],"line":16},"3":{"loc":{"start":{"line":46,"column":4},"end":{"line":48,"column":5}},"type":"if","locations":[{"start":{"line":46,"column":4},"end":{"line":48,"column":5}},{"start":{"line":46,"column":4},"end":{"line":48,"column":5}}],"line":46},"4":{"loc":{"start":{"line":55,"column":20},"end":{"line":55,"column":81}},"type":"cond-expr","locations":[{"start":{"line":55,"column":48},"end":{"line":55,"column":74}},{"start":{"line":55,"column":77},"end":{"line":55,"column":81}}],"line":55},"5":{"loc":{"start":{"line":60,"column":2},"end":{"line":62,"column":3}},"type":"if","locations":[{"start":{"line":60,"column":2},"end":{"line":62,"column":3}},{"start":{"line":60,"column":2},"end":{"line":62,"column":3}}],"line":60}},"s":{"0":1,"1":1,"2":1,"3":157,"4":157,"5":157,"6":157,"7":154,"8":157,"9":1,"10":157,"11":157,"12":157,"13":157,"14":157,"15":157,"16":471,"17":471,"18":157,"19":0,"20":25,"21":25,"22":8,"23":17,"24":26,"25":26,"26":7,"27":1,"28":6,"29":6,"30":129,"31":129,"32":1},"f":{"0":157,"1":471,"2":0,"3":25,"4":25,"5":26,"6":7,"7":6,"8":129,"9":129},"b":{"0":[157,1],"1":[154,3],"2":[1,156],"3":[8,17],"4":[1,25],"5":[1,6]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"476cb42cd1352543dc6c059664b734698fa13176","contentHash":"de28073ec4cda2eeada2d5d2a61686fd7ca7e66537795de14b90ad61d1cd6a55"}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":"5820d74a-2c5d-4545-b2e1-19b4fc0d16f0","pid":22836,"argv":["/Users/jaredwray/.nvm/versions/node/v16.13.1/bin/node","/Users/jaredwray/src/github.com/jaredwray/keyv/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo","time":1641079896918,"ppid":22835,"coverageFilename":"/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/.nyc_output/e600d32e-2bd2-4fcc-ba04-b79d5cfa2d6b.json","externalId":"","uuid":"e600d32e-2bd2-4fcc-ba04-b79d5cfa2d6b","files":["/Users/jaredwray/src/github.com/jaredwray/keyv/packages/mongo/src/index.js"]}
|