insite-db 1.2.1 → 1.2.2

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.
@@ -1,9 +1,9 @@
1
1
  import type { Collection } from "mongodb";
2
- import type { CollectionOptions, InSiteDB } from "./types";
2
+ import type { InSiteCollectionOptions, InSiteDB } from "./types";
3
3
  export declare class Collections extends Map<string, Collection> {
4
4
  constructor(db: InSiteDB);
5
5
  db: InSiteDB;
6
6
  [key: string]: Collection | unknown;
7
- ensure(name: string, options?: CollectionOptions): Promise<Collection<import("bson").Document>>;
7
+ ensure(name: string, options?: InSiteCollectionOptions): Promise<Collection<import("bson").Document>>;
8
8
  }
9
9
  //# sourceMappingURL=Collections.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Collections.d.ts","sourceRoot":"","sources":["../src/Collections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsC,UAAU,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAqB3D,qBAAa,WAAY,SAAQ,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC;gBAC3C,EAAE,EAAE,QAAQ;IAOxB,EAAE,EAAE,QAAQ,CAAC;IAEb,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;IAE9B,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;CAwC1D"}
1
+ {"version":3,"file":"Collections.d.ts","sourceRoot":"","sources":["../src/Collections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsC,UAAU,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,KAAK,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAqBjE,qBAAa,WAAY,SAAQ,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC;gBAC3C,EAAE,EAAE,QAAQ;IAOxB,EAAE,EAAE,QAAQ,CAAC;IAEb,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;IAE9B,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,uBAA4B;CAwChE"}
@@ -1,11 +1,9 @@
1
- import { type CreateIndexesOptions, type IndexSpecification } from "mongodb";
2
- type IndexTuple = [IndexSpecification, CreateIndexesOptions];
3
1
  declare module "mongodb" {
4
2
  interface Collection {
5
3
  changeListeners?: Set<(listener: ChangeStreamDocument) => void>;
6
4
  changeStream?: ChangeStream;
7
- ensureIndexes(indexesToEnsure: IndexTuple[]): Promise<void>;
5
+ ensureIndexes(indexesToEnsure: [IndexSpecification, CreateIndexesOptions?][]): Promise<void>;
8
6
  }
9
7
  }
10
- export {};
8
+ export { type ChangeStreamDocument, Collection as InSiteCollection } from "mongodb";
11
9
  //# sourceMappingURL=Collection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../src/extensions/Collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,MAAM,SAAS,CAAC;AAGjB,KAAK,UAAU,GAAG,CAAE,kBAAkB,EAAE,oBAAoB,CAAE,CAAC;AAE/D,OAAO,QAAQ,SAAS,CAAC;IACxB,UAAU,UAAU;QACnB,eAAe,CAAC,EAAE,GAAG,CAAC,CAAC,QAAQ,EAAE,oBAAoB,KAAK,IAAI,CAAC,CAAC;QAChE,YAAY,CAAC,EAAE,YAAY,CAAC;QAC5B,aAAa,CAAC,eAAe,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KAC5D;CACD"}
1
+ {"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../src/extensions/Collection.ts"],"names":[],"mappings":"AAGA,OAAO,QAAQ,SAAS,CAAC;IACxB,UAAiB,UAAU;QAC1B,eAAe,CAAC,EAAE,GAAG,CAAC,CAAC,QAAQ,EAAE,oBAAoB,KAAK,IAAI,CAAC,CAAC;QAChE,YAAY,CAAC,EAAE,YAAY,CAAC;QAC5B,aAAa,CAAC,eAAe,EAAE,CAAE,kBAAkB,EAAE,oBAAoB,CAAC,CAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KAC/F;CACD;AAiBD,OAAO,EAAE,KAAK,oBAAoB,EAAE,UAAU,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC"}
@@ -1,2 +1,2 @@
1
- import "./Collection";
1
+ export * from "./Collection";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { connect } from "./connect";
2
- import "./extensions";
1
+ export * from "./connect";
2
+ export * from "./extensions";
3
+ export * from "./types";
3
4
  export { Binary, GridFSBucket, ObjectId } from "mongodb";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,cAAc,CAAC;AAGtB,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import{MongoClient as l}from"mongodb";function s(n){process.env.NODE_ENV==="development"&&console.log("Change stream change",this.parent.collectionName,n);for(let o of this.parent.changeListeners)o(n)}function a(n){console.error(`\u{1F33F}\u2757\uFE0F Mongo ${this.parent.collectionName} Change Stream:
2
- `,n.stack)}var i=class extends Map{constructor(o){super(),this.db=o}db;async ensure(o,e={}){let{db:r}=this,t=this.get(o);return t||((await r.listCollections({name:o},{nameOnly:!0}).toArray()).length?t=r.collection(o):(t=await r.createCollection(o,{...e.jsonSchema&&{validator:{$jsonSchema:e.jsonSchema}},...e.blockCompressor&&{storageEngine:{wiredTiger:{configString:`block_compressor=${e.blockCompressor}`}}}}),delete e.jsonSchema,delete e.blockCompressor),this.set(o,t),this[o]=t,e.watch!==!1&&(t.changeListeners=new Set,t.changeStream=t.watch(void 0,{fullDocument:e.fullDocument===!1?void 0:"updateLookup"}).on("change",s).on("error",a))),e.jsonSchema&&await r.command({collMod:o,...e.jsonSchema&&{validator:{$jsonSchema:e.jsonSchema}}}),t}};async function m(n,o){/localhost/.test(n)&&(n=n.replace(/localhost/,"127.0.0.1"));let e=new l(n,{maxPoolSize:100});try{await e.connect(),console.info("\u{1F33F} Mongo Client connected to",n.replace(/(?<=\/\/)[^:]+?:[^@]+@/,"").replace(/[/?][^/]*$/,""))}catch(c){console.error("\u{1F33F}\u2757\uFE0F Mongo Client connection: ",c)}e.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 r=e.db(o),t=new i(r);return r.insiteCollections=t,{client:e,db:r,collections:t}}import{Collection as h}from"mongodb";h.prototype.ensureIndexes=async function(n){try{for(let o of n)await this.createIndex(...o)}catch{}};import{Binary as I,GridFSBucket as b,ObjectId as w}from"mongodb";export{I as Binary,b as GridFSBucket,w as ObjectId,m as connect};
1
+ import{MongoClient as l}from"mongodb";function i(n){process.env.NODE_ENV==="development"&&console.log("Change stream change",this.parent.collectionName,n);for(let o of this.parent.changeListeners)o(n)}function s(n){console.error(`\u{1F33F}\u2757\uFE0F Mongo ${this.parent.collectionName} Change Stream:
2
+ `,n.stack)}var a=class extends Map{constructor(o){super(),this.db=o}db;async ensure(o,e={}){let{db:r}=this,t=this.get(o);return t||((await r.listCollections({name:o},{nameOnly:!0}).toArray()).length?t=r.collection(o):(t=await r.createCollection(o,{...e.jsonSchema&&{validator:{$jsonSchema:e.jsonSchema}},...e.blockCompressor&&{storageEngine:{wiredTiger:{configString:`block_compressor=${e.blockCompressor}`}}}}),delete e.jsonSchema,delete e.blockCompressor),this.set(o,t),this[o]=t,e.watch!==!1&&(t.changeListeners=new Set,t.changeStream=t.watch(void 0,{fullDocument:e.fullDocument===!1?void 0:"updateLookup"}).on("change",i).on("error",s))),e.jsonSchema&&await r.command({collMod:o,...e.jsonSchema&&{validator:{$jsonSchema:e.jsonSchema}}}),t}};async function f(n,o){/localhost/.test(n)&&(n=n.replace(/localhost/,"127.0.0.1"));let e=new l(n,{maxPoolSize:100});try{await e.connect(),console.info("\u{1F33F} Mongo Client connected to",n.replace(/(?<=\/\/)[^:]+?:[^@]+@/,"").replace(/[/?][^/]*$/,""))}catch(c){console.error("\u{1F33F}\u2757\uFE0F Mongo Client connection: ",c)}e.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 r=e.db(o),t=new a(r);return r.insiteCollections=t,{client:e,db:r,collections:t}}import{Collection as m}from"mongodb";import{Collection as D}from"mongodb";m.prototype.ensureIndexes=async function(n){try{for(let o of n)await this.createIndex(...o)}catch{}};import{Binary as k,GridFSBucket as j,ObjectId as E}from"mongodb";export{k as Binary,j as GridFSBucket,D as InSiteCollection,E as ObjectId,f as connect};
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/connect.ts", "../src/Collections.ts", "../src/extensions/Collection.ts", "../src/index.ts"],
4
- "sourcesContent": ["import { MongoClient } from \"mongodb\";\nimport { Collections } from \"./Collections\";\nimport type { InSiteDB } from \"./types\";\n\n\nexport async function connect(url: string, name: string) {\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) as InSiteDB;\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", "import type { ChangeStream, ChangeStreamDocument, Collection } from \"mongodb\";\nimport type { CollectionOptions, InSiteDB } from \"./types\";\n\n\n/* @this ChangeStream */\nfunction handleChangeStreamChange(this: ChangeStream, next: ChangeStreamDocument) {\n\t\n\tif (process.env.NODE_ENV === \"development\")\n\t\tconsole.log(\"Change stream change\", (this.parent as Collection).collectionName, next);\n\t\n\tfor (const listener of (this.parent as Collection).changeListeners!)\n\t\tlistener(next);\n\t\n}\n\n/* @this ChangeStream */\nfunction handleChangeStreamError(this: ChangeStream, error: Error) {\n\tconsole.error(`\uD83C\uDF3F\u2757\uFE0F Mongo ${(this.parent as Collection).collectionName} Change Stream:\\n`, error.stack);\n\t\n}\n\n\nexport class Collections extends Map<string, Collection> {\n\tconstructor(db: InSiteDB) {\n\t\tsuper();\n\t\t\n\t\tthis.db = db;\n\t\t\n\t}\n\t\n\tdb: InSiteDB;\n\t\n\t[key: string]: Collection | unknown;\n\t\n\tasync ensure(name: string, options: CollectionOptions = {}) {\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(undefined, { fullDocument: options.fullDocument === false ? undefined : \"updateLookup\" })\n\t\t\t\t\t\t.on(\"change\", handleChangeStreamChange)\n\t\t\t\t\t\t.on(\"error\", 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}\n", "import {\n\ttype ChangeStreamDocument,\n\tCollection,\n\ttype CreateIndexesOptions,\n\ttype IndexSpecification\n} from \"mongodb\";\n\n\ntype IndexTuple = [ IndexSpecification, CreateIndexesOptions ];\n\ndeclare module \"mongodb\" {\n\tinterface Collection { // eslint-disable-line no-shadow\n\t\tchangeListeners?: Set<(listener: ChangeStreamDocument) => void>;\n\t\tchangeStream?: ChangeStream;\n\t\tensureIndexes(indexesToEnsure: IndexTuple[]): Promise<void>;\n\t}\n}\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", "export { connect } from \"./connect\";\nimport \"./extensions\";\n\n\nexport { Binary, GridFSBucket, ObjectId } from \"mongodb\";\n"],
5
- "mappings": "AAAA,OAAS,eAAAA,MAAmB,UCK5B,SAASC,EAA6CC,EAA4B,CAE7E,QAAQ,IAAI,WAAa,eAC5B,QAAQ,IAAI,uBAAyB,KAAK,OAAsB,eAAgBA,CAAI,EAErF,QAAWC,KAAa,KAAK,OAAsB,gBAClDA,EAASD,CAAI,CAEf,CAGA,SAASE,EAA4CC,EAAc,CAClE,QAAQ,MAAM,+BAAe,KAAK,OAAsB,cAAc;AAAA,EAAqBA,EAAM,KAAK,CAEvG,CAGO,IAAMC,EAAN,cAA0B,GAAwB,CACxD,YAAYC,EAAc,CACzB,MAAM,EAEN,KAA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c,EAAE,CAAC,CACjH,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,CErCA,OAEC,cAAAE,MAGM,UAcPA,EAAW,UAAU,cAAgB,eAAgBC,EAAiB,CAMrE,GAAI,CACH,QAAWC,KAAiBD,EAC3B,MAAM,KAAK,YAAY,GAAGC,CAAa,CACzC,MAAQ,CAAC,CAEV,EC1BA,OAAS,UAAAC,EAAQ,gBAAAC,EAAc,YAAAC,MAAgB",
4
+ "sourcesContent": ["import { MongoClient } from \"mongodb\";\nimport { Collections } from \"./Collections\";\nimport type { InSiteDB } from \"./types\";\n\n\nexport async function connect(url: string, name: string) {\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) as InSiteDB;\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", "import type { ChangeStream, ChangeStreamDocument, Collection } from \"mongodb\";\nimport type { InSiteCollectionOptions, InSiteDB } from \"./types\";\n\n\n/* @this ChangeStream */\nfunction handleChangeStreamChange(this: ChangeStream, next: ChangeStreamDocument) {\n\t\n\tif (process.env.NODE_ENV === \"development\")\n\t\tconsole.log(\"Change stream change\", (this.parent as Collection).collectionName, next);\n\t\n\tfor (const listener of (this.parent as Collection).changeListeners!)\n\t\tlistener(next);\n\t\n}\n\n/* @this ChangeStream */\nfunction handleChangeStreamError(this: ChangeStream, error: Error) {\n\tconsole.error(`\uD83C\uDF3F\u2757\uFE0F Mongo ${(this.parent as Collection).collectionName} Change Stream:\\n`, error.stack);\n\t\n}\n\n\nexport class Collections extends Map<string, Collection> {\n\tconstructor(db: InSiteDB) {\n\t\tsuper();\n\t\t\n\t\tthis.db = db;\n\t\t\n\t}\n\t\n\tdb: InSiteDB;\n\t\n\t[key: string]: Collection | unknown;\n\t\n\tasync ensure(name: string, options: InSiteCollectionOptions = {}) {\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(undefined, { fullDocument: options.fullDocument === false ? undefined : \"updateLookup\" })\n\t\t\t\t\t\t.on(\"change\", handleChangeStreamChange)\n\t\t\t\t\t\t.on(\"error\", 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}\n", "import { type ChangeStreamDocument, Collection } from \"mongodb\";\n\n\ndeclare module \"mongodb\" {\n\texport interface Collection { // eslint-disable-line no-shadow\n\t\tchangeListeners?: Set<(listener: ChangeStreamDocument) => void>;\n\t\tchangeStream?: ChangeStream;\n\t\tensureIndexes(indexesToEnsure: [ IndexSpecification, CreateIndexesOptions? ][]): Promise<void>;\n\t}\n}\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\n\nexport { type ChangeStreamDocument, Collection as InSiteCollection } from \"mongodb\";\n", "export * from \"./connect\";\nexport * from \"./extensions\";\nexport * from \"./types\";\nexport { Binary, GridFSBucket, ObjectId } from \"mongodb\";\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"db", "name", "options", "collection", "connect", "url", "name", "client", "MongoClient", "error", "db", "collections", "Collections", "Collection", "indexesToEnsure", "indexToEnsure", "Binary", "GridFSBucket", "ObjectId"]
7
7
  }
package/dist/types.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { Collections } from "./Collections";
3
3
  export type InSiteDB = {
4
4
  insiteCollections: Collections;
5
5
  } & Db;
6
- export type CollectionOptions = {
6
+ export type InSiteCollectionOptions = {
7
7
  fullDocument?: boolean;
8
8
  jsonSchema?: Record<string, unknown>;
9
9
  blockCompressor?: "none" | "snappy" | "zlib" | "zstd";
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGjD,MAAM,MAAM,QAAQ,GAAG;IACtB,iBAAiB,EAAE,WAAW,CAAC;CAC/B,GAAG,EAAE,CAAC;AAEP,MAAM,MAAM,iBAAiB,GAAG;IAC/B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,eAAe,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IACtD,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGjD,MAAM,MAAM,QAAQ,GAAG;IACtB,iBAAiB,EAAE,WAAW,CAAC;CAC/B,GAAG,EAAE,CAAC;AAEP,MAAM,MAAM,uBAAuB,GAAG;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,eAAe,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IACtD,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insite-db",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "MongoDB for inSite",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",