insite-db 1.0.33 → 1.0.35
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/README.md +1 -1
- package/bun.lockb +0 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
package/bun.lockb
CHANGED
|
Binary file
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Binary as w,GridFSBucket as M,ObjectId as
|
|
1
|
+
import{Binary as w,GridFSBucket as M,ObjectId as y}from"mongodb";import{Collection as s}from"mongodb";s.prototype.ensureIndexes=async function(r){try{for(let e of r)await this.createIndex(...e)}catch{}};s.prototype.handleChangeStreamChange=function(r){process.env.NODE_ENV==="development"&&console.log("Change stream change",this.parent.collectionName,r);for(let e of this.parent.changeListeners)e(r)};import{MongoClient as l}from"mongodb";var a=class r extends Map{constructor(e){super(),this.db=e}async ensure(e,o={}){let{db:t}=this,n=this.get(e);return n||((await t.listCollections({name:e},{nameOnly:!0}).toArray()).length?n=t.collection(e):(n=await t.createCollection(e,{...o.jsonSchema&&{validator:{$jsonSchema:o.jsonSchema}},...o.blockCompressor&&{storageEngine:{wiredTiger:{configString:`block_compressor=${o.blockCompressor}`}}}}),delete o.jsonSchema,delete o.blockCompressor),this.set(e,n),this[e]=n,o.watch!==!1&&(n.changeListeners=new Set,n.changeStream=n.watch({fullDocument:o.fullDocument===!1?void 0:"updateLookup"}).on("change",n.handleChangeStreamChange).on("error",r.handleChangeStreamError))),o.jsonSchema&&await t.command({collMod:e,...o.jsonSchema&&{validator:{$jsonSchema:o.jsonSchema}}}),n}static handleChangeStreamError(e){console.error(`\u{1F33F}\u2757\uFE0F Mongo ${this.parent.collectionName} Change Stream:`,e)}};async function i(r,e){/localhost/.test(r)&&(r=r.replace(/localhost/,"127.0.0.1"));let o=new l(r,{maxPoolSize:100});try{await o.connect(),console.info("\u{1F33F} Mongo Client connected to",r.replace(/(?<=\/\/)[^:]+?:[^@]+@/,"").replace(/(?:\/|\?)[^/]*$/,""))}catch(c){console.error("\u{1F33F}\u2757\uFE0F Mongo Client connection: ",c)}o.on("close",()=>console.error("\u{1F33F}\u2757\uFE0F Mongo DB socket closed")).on("error",c=>console.error("\u{1F33F}\u2757\uFE0F Mongo DB:",c)).on("parseError",c=>console.error("\u{1F33F}\u2757\uFE0F Mongo DB parse:",c)).on("reconnect",()=>console.info("\u{1F33F} Mongo DB reconnected")).on("timeout",()=>console.error("\u{1F33F}\u2757\uFE0F Mongo DB timeout"));let t=o.db(e),n=new a(t);return t.insiteCollections=n,{client:o,db:t,collections:n}}export{w as Binary,M as GridFSBucket,y as ObjectId,i as connect};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.js", "../src/extensions/Collection.js", "../src/connect.js", "../src/Collections.js"],
|
|
4
4
|
"sourcesContent": ["export { Binary, GridFSBucket, ObjectId } from \"mongodb\";\nimport \"./extensions\";\n\n\nexport { connect } from \"./connect\";\n", "import { Collection } from \"mongodb\";\n\n\nCollection.prototype.ensureIndexes = async function (indexesToEnsure) {\n\t\n\t// const existingIndexes = await this.indexes();\n\t\n\t// TODO:\n\t\n\ttry {\n\t\tfor (const indexToEnsure of indexesToEnsure)\n\t\t\tawait this.createIndex(...indexToEnsure);\n\t} catch {}\n\t\n};\n\nCollection.prototype.handleChangeStreamChange = function (next) {\n\t\n\tif (process.env.NODE_ENV === \"development\")\n\t\tconsole.log(\"Change stream change\", this.parent.collectionName, next);\n\t\n\tfor (const listener of this.parent.changeListeners)\n\t\tlistener(next);\n\t\n};\n", "import { MongoClient } from \"mongodb\";\nimport { Collections } from \"./Collections\";\n\n\nexport async function connect(url, name) {\n\t\n\tif (/localhost/.test(url))\n\t\turl = url.replace(/localhost/, \"127.0.0.1\");\n\t\n\tconst client = new MongoClient(url, { maxPoolSize: 100 });\n\t\n\ttry {\n\t\tawait client.connect();\n\t\tconsole.info(\"\uD83C\uDF3F Mongo Client connected to\", url.replace(/(?<=\\/\\/)[^:]+?:[^@]+@/, \"\").replace(/(?:\\/|\\?)[^/]*$/, \"\"));\n\t} catch (error) {\n\t\tconsole.error(\"\uD83C\uDF3F\u2757\uFE0F Mongo Client connection: \", error);\n\t}\n\t\n\tclient\n\t\t.on(\"close\", () => console.error(\"\uD83C\uDF3F\u2757\uFE0F Mongo DB socket closed\"))\n\t\t.on(\"error\", error => console.error(\"\uD83C\uDF3F\u2757\uFE0F Mongo DB:\", error))\n\t\t.on(\"parseError\", error => console.error(\"\uD83C\uDF3F\u2757\uFE0F Mongo DB parse:\", error))\n\t\t.on(\"reconnect\", () => console.info(\"\uD83C\uDF3F Mongo DB reconnected\"))\n\t\t.on(\"timeout\", () => console.error(\"\uD83C\uDF3F\u2757\uFE0F Mongo DB timeout\"));\n\t\n\tconst db = client.db(name);\n\t\n\tconst collections = new Collections(db);\n\t\n\tdb.insiteCollections = collections;\n\t\n\treturn {\n\t\tclient,\n\t\tdb,\n\t\tcollections\n\t};\n}\n", "export class Collections extends Map {\n\tconstructor(db) {\n\t\tsuper();\n\t\t\n\t\tthis.db = db;\n\t\t\n\t}\n\t\n\tasync ensure(name, options = {}) {\n\t\t\n\t\tconst { db } = this;\n\t\t\n\t\tlet collection = this.get(name);\n\t\t\n\t\tif (!collection) {\n\t\t\tif ((await db.listCollections({ name }, { nameOnly: true }).toArray()).length)\n\t\t\t\tcollection = db.collection(name);\n\t\t\telse {\n\t\t\t\tcollection = await db.createCollection(name, {\n\t\t\t\t\t...options.jsonSchema && { validator: { $jsonSchema: options.jsonSchema } },\n\t\t\t\t\t...options.blockCompressor && { storageEngine: { wiredTiger: { configString: `block_compressor=${options.blockCompressor}` } } }\n\t\t\t\t});\n\t\t\t\tdelete options.jsonSchema;\n\t\t\t\tdelete options.blockCompressor;\n\t\t\t}\n\t\t\t\n\t\t\tthis.set(name, collection);\n\t\t\tthis[name] = collection;\n\t\t\t\n\t\t\tif (options.watch !== false) {\n\t\t\t\tcollection.changeListeners = new Set();\n\t\t\t\t\n\t\t\t\tcollection.changeStream =\n\t\t\t\t\tcollection.watch({ fullDocument: options.fullDocument === false ? undefined : \"updateLookup\" })\n\t\t\t\t\t\t.on(\"change\", collection.handleChangeStreamChange)\n\t\t\t\t\t\t.on(\"error\", Collections.handleChangeStreamError);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (options.jsonSchema)\n\t\t\tawait db.command({\n\t\t\t\tcollMod: name,\n\t\t\t\t...options.jsonSchema && { validator: { $jsonSchema: options.jsonSchema } }\n\t\t\t});\n\t\t\n\t\treturn collection;\n\t}\n\t\n\t\n\tstatic handleChangeStreamError(error) {\n\t\tconsole.error(`\uD83C\uDF3F\u2757\uFE0F Mongo ${this.parent.collectionName} Change Stream:`, error);\n\t\t\n\t}\n\t\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,UAAAA,EAAQ,gBAAAC,EAAc,YAAAC,MAAgB,UCA/C,OAAS,cAAAC,MAAkB,UAG3BA,EAAW,UAAU,cAAgB,eAAgBC,EAAiB,CAMrE,GAAI,CACH,QAAWC,KAAiBD,EAC3B,MAAM,KAAK,YAAY,GAAGC,CAAa,CACzC,MAAQ,CAAC,CAEV,EAEAF,EAAW,UAAU,yBAA2B,SAAUG,EAAM,
|
|
5
|
+
"mappings": "AAAA,OAAS,UAAAA,EAAQ,gBAAAC,EAAc,YAAAC,MAAgB,UCA/C,OAAS,cAAAC,MAAkB,UAG3BA,EAAW,UAAU,cAAgB,eAAgBC,EAAiB,CAMrE,GAAI,CACH,QAAWC,KAAiBD,EAC3B,MAAM,KAAK,YAAY,GAAGC,CAAa,CACzC,MAAQ,CAAC,CAEV,EAEAF,EAAW,UAAU,yBAA2B,SAAUG,EAAM,CAE3D,QAAQ,IAAI,WAAa,eAC5B,QAAQ,IAAI,uBAAwB,KAAK,OAAO,eAAgBA,CAAI,EA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,EAAQC,EAAKC,EAAM,CAEpC,YAAY,KAAKD,CAAG,IACvBA,EAAMA,EAAI,QAAQ,YAAa,WAAW,GAE3C,IAAME,EAAS,IAAIC,EAAYH,EAAK,CAAE,YAAa,GAAI,CAAC,EAExD,GAAI,CACH,MAAME,EAAO,QAAQ,EACrB,QAAQ,KAAK,sCAAgCF,EAAI,QAAQ,yBAA0B,EAAE,EAAE,QAAQ,kBAAmB,EAAE,CAAC,CACtH,OAASI,EAAO,CACf,QAAQ,MAAM,kDAAkCA,CAAK,CACtD,CAEAF,EACE,GAAG,QAAS,IAAM,QAAQ,MAAM,8CAA6B,CAAC,EAC9D,GAAG,QAASE,GAAS,QAAQ,MAAM,kCAAkBA,CAAK,CAAC,EAC3D,GAAG,aAAcA,GAAS,QAAQ,MAAM,wCAAwBA,CAAK,CAAC,EACtE,GAAG,YAAa,IAAM,QAAQ,KAAK,gCAAyB,CAAC,EAC7D,GAAG,UAAW,IAAM,QAAQ,MAAM,wCAAuB,CAAC,EAE5D,IAAMC,EAAKH,EAAO,GAAGD,CAAI,EAEnBK,EAAc,IAAIC,EAAYF,CAAE,EAEtC,OAAAA,EAAG,kBAAoBC,EAEhB,CACN,OAAAJ,EACA,GAAAG,EACA,YAAAC,CACD,CACD",
|
|
6
6
|
"names": ["Binary", "GridFSBucket", "ObjectId", "Collection", "indexesToEnsure", "indexToEnsure", "next", "listener", "MongoClient", "Collections", "_Collections", "db", "name", "options", "collection", "error", "connect", "url", "name", "client", "MongoClient", "error", "db", "collections", "Collections"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "insite-db",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"description": "MongoDB for inSite",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
|
-
"packageManager": "bun@1.1.
|
|
8
|
+
"packageManager": "bun@1.1.12",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
11
|
"build": "bun .conveyer.js"
|