insite-db 2.1.2 → 2.2.1

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,14 +1,13 @@
1
1
  import type { Collection, Document } from "mongodb";
2
- import type { DB, EnsureOptions, WatchedCollection } from "./types";
2
+ import type { CollectionOptions, DB, WatchedCollection } from "./types";
3
3
  export declare class Collections extends Map<string, Collection> {
4
+ #private;
4
5
  constructor(db: DB);
5
6
  db: DB;
6
7
  [key: string]: Collection | unknown;
7
- ensure<Doc extends Document>(name: string, options: EnsureOptions & {
8
+ ensure<Doc extends Document>(name: string, options: CollectionOptions & {
8
9
  watch: false;
9
10
  }): Promise<Collection<Doc>>;
10
- ensure<Doc extends Document>(name: string, options?: EnsureOptions & {
11
- watch?: true;
12
- }): Promise<WatchedCollection<Doc>>;
11
+ ensure<Doc extends Document>(name: string, options?: CollectionOptions): Promise<WatchedCollection<Doc>>;
13
12
  }
14
13
  //# sourceMappingURL=Collections.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Collections.d.ts","sourceRoot":"","sources":["../src/Collections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGX,UAAU,EACV,QAAQ,EACR,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,EAAE,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAqBpE,qBAAa,WAAY,SAAQ,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC;gBAC3C,EAAE,EAAE,EAAE;IAOlB,EAAE,EAAE,EAAE,CAAC;IAEP,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;IAE9B,MAAM,CAAC,GAAG,SAAS,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/G,MAAM,CAAC,GAAG,SAAS,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG;QAAE,KAAK,CAAC,EAAE,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;CA4C7H"}
1
+ {"version":3,"file":"Collections.d.ts","sourceRoot":"","sources":["../src/Collections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGxE,qBAAa,WAAY,SAAQ,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC;;gBAC3C,EAAE,EAAE,EAAE;IAOlB,EAAE,EAAE,EAAE,CAAC;IAOP,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;IAE9B,MAAM,CAAC,GAAG,SAAS,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACnH,MAAM,CAAC,GAAG,SAAS,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;CA8E9G"}
@@ -1,9 +1,20 @@
1
- import type { CollectionIndexes } from "../types";
1
+ import type { ChangeStreamListener, CollectionIndexes } from "../types";
2
2
  declare module "mongodb" {
3
3
  interface Collection<TSchema> {
4
- changeListeners?: Set<(listener: ChangeStreamDocument<TSchema>) => void>;
4
+ /** Ensures the presence of `indexes`. */
5
+ ensureIndexes(indexes: CollectionIndexes): Promise<void>;
6
+ /** Change Stream, watching for new changes in this collection. */
5
7
  changeStream?: ChangeStream<TSchema>;
6
- ensureIndexes(indexesToEnsure: CollectionIndexes): Promise<void>;
8
+ /** Adds the `listener` function to the end of the listeners array for the event `change`. */
9
+ onChange?(listener: ChangeStreamListener<TSchema>): this;
10
+ /** Adds the `listener` function to the *beginning* of the listeners array for the event `change`. */
11
+ prependChange?(listener: ChangeStreamListener<TSchema>): this;
12
+ /** Adds the **one-time** `listener` function to the end of the listeners array for the event `change`. */
13
+ onceChange?(listener: ChangeStreamListener<TSchema>): this;
14
+ /** Adds the **one-time** function to the *beginning* of the listeners array for the event `change`. */
15
+ prependOnceChange?(listener: ChangeStreamListener<TSchema>): this;
16
+ /** Removes the `listener` from the listener array for the event `change`. */
17
+ removeChangeListener?(listener: ChangeStreamListener<TSchema>): this;
7
18
  }
8
19
  }
9
20
  //# sourceMappingURL=Collection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../src/extensions/Collection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlD,OAAO,QAAQ,SAAS,CAAC;IACxB,UAAiB,UAAU,CAAC,OAAO;QAClC,eAAe,CAAC,EAAE,GAAG,CAAC,CAAC,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC;QACzE,YAAY,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;QACrC,aAAa,CAAC,eAAe,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KACjE;CACD"}
1
+ {"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../src/extensions/Collection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAqB,MAAM,UAAU,CAAC;AAM3F,OAAO,QAAQ,SAAS,CAAC;IACxB,UAAiB,UAAU,CAAC,OAAO;QAElC,yCAAyC;QACzC,aAAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAEzD,kEAAkE;QAClE,YAAY,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;QAErC,6FAA6F;QAC7F,QAAQ,CAAC,CAAC,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;QAEzD,qGAAqG;QACrG,aAAa,CAAC,CAAC,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;QAE9D,0GAA0G;QAC1G,UAAU,CAAC,CAAC,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;QAE3D,uGAAuG;QACvG,iBAAiB,CAAC,CAAC,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;QAElE,6EAA6E;QAC7E,oBAAoB,CAAC,CAAC,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;KAErE;CACD"}
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export type { Collections } from "./Collections";
2
2
  export * from "./connect";
3
3
  export * from "./extensions";
4
4
  export * from "./types";
5
+ export { CollectionOptions } from "./types";
5
6
  export * from "./utils";
6
7
  export * from "mongodb";
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,18 @@
1
- import{MongoClient as m}from"mongodb";function i(n){process.env.NODE_ENV==="development"&&console.info("\u{1F38F} Change stream change",this.parent.collectionName,n);for(let e of this.parent.changeListeners)e(n)}function l(n){console.error(`\u{1F33F}\u2757\uFE0F Mongo ${this.parent.collectionName} Change Stream:
2
- `,n.stack)}var s=class extends Map{constructor(e){super(),this.db=e}db;async ensure(e,o={}){let{db:r}=this,t=this.get(e);return t||((await r.listCollections({name:e},{nameOnly:!0}).toArray()).length?t=r.collection(e):(t=await r.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,t),this[e]=t,o.watch!==!1&&(t.changeListeners=new Set,t.changeStream=t.watch(void 0,{fullDocument:o.fullDocument===!1?void 0:"updateLookup"}).on("change",i).on("error",l))),o.jsonSchema&&await r.command({collMod:e,...o.jsonSchema&&{validator:{$jsonSchema:o.jsonSchema}}}),o.indexes&&await t.ensureIndexes(o.indexes),t}};async function u({url:n,name:e,...o}){/localhost/.test(n)&&(n=n.replace(/localhost/,"127.0.0.1"));let r=new m(n,{maxPoolSize:100,...o});try{await r.connect(),console.info("\u{1F33F} Mongo Client connected to",n.replace(/(?<=\/\/)[^:]+?:[^@]+@/,"").replace(/[/?][^/]*$/,""))}catch(c){console.error("\u{1F33F}\u2757\uFE0F Mongo Client connection: ",c)}r.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=r.db(e),a=new s(t);return{client:r,db:t,collections:a}}import{Collection as h}from"mongodb";h.prototype.ensureIndexes=async function(n){try{for(let e of n)await this.createIndex(...e)}catch{}};import{ObjectId as d}from"mongodb";function y(){return new d().toString()}export*from"mongodb";export{u as connect,y as newObjectIdString};
1
+ import{MongoClient as B}from"mongodb";function p(e=1,t=4){let r=" ".repeat(t),o={};Error.captureStackTrace(o,p);let n=o.stack.replace(/^Error\W+/m,"").replaceAll(/^\s+/gm,"").split(`
2
+ `).slice(e).join(`
3
+ ${r}`);return`${r}${n}`}function m(){}function M(e,t=0,r={}){let{leading:o=!1,trailing:n=!0}=r,{maxWait:s=1/0}=r,i,c,x,C,w,d,a,y,$=async()=>{let u=Date.now();u>=x?(i=void 0,x=void 0,clearTimeout(c),typeof a=="function"&&await a(),l.resolve(y),l.promise.isResolved=!0,d=o):(clearTimeout(i),i=setTimeout($,x-u))},S=Number.isFinite(s)?()=>{a===f&&(a=!1),f(),c=setTimeout(S,s)}:null;async function f(){return y=await e.apply(C,w)}o&&typeof o=="boolean"&&(o=f),d=o,n&&typeof n=="boolean"&&(n=f),a=n;let l=Object.assign(function(...u){return w=u,C=this,x=Date.now()+t,a=n,l.promise.isResolved&&(l.promise=Object.assign(new Promise(k=>{l.resolve=k,typeof d=="function"&&(d(),d=!1,a===f&&(a=!1)),i||(i=setTimeout($,t),S&&(c=setTimeout(S,s)))}),{isResolved:!1})),l.promise},{callback:e,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:m,run:f,clear:async u=>{clearTimeout(i),i=void 0,clearTimeout(c),l.promise.isResolved=!0,l.resolve(u?await f():y)}});return l}M.noop=Object.assign(()=>{},{callback:m,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:m,run:m,clear:m});function v(e,t,r,o,n=!0){return Array.isArray(e)&&(e=e.length),typeof o!="string"&&(n=o??!0,o=r),(n?`${e}\xA0`:"")+v.raw(e,t,r,o)}v.raw=(e,t,r,o=r)=>{e=Math.abs(e);let n=e%10,s=e%100;return n===1&&s!==11?t:n>=2&&n<=4&&!(s>=12&&s<=15)?r:o};function O(e,t){let r={...e};for(let o of t)delete r[o];return r}import{ObjectId as j}from"mongodb";function Co(){return new j().toString()}function T(e){let t=[];switch(e.operationType){case"insert":case"replace":t.push("fullDocument:",e.fullDocument);break;case"update":t.push("_id:",e.documentKey._id,`
4
+ `,"updateDescription:",e.updateDescription);break;case"delete":t.push("_id:",e.documentKey._id);break;default:t.push(e)}console.info("\u{1F33F}\u{1F38F}",`\x1B[1m${this.parent.collectionName}\x1B[0m`,`\x1B[3m${e.operationType}\x1B[0m`,...t)}function b(e){console.error(`\u{1F33F}\u2757\uFE0F MongoDB ${this.parent.collectionName} Change Stream:
5
+ `,e.stack)}var g=class extends Map{constructor(t){super(),this.db=t}db;#e=new Map;#t=new Map;#o=new Map;async ensure(t,r={}){let{db:o}=this,n=this.get(t)??await this.#e.get(t);if(!n){let{promise:s,resolve:i}=Promise.withResolvers();if(this.#e.set(t,s),(await o.listCollections({name:t},{nameOnly:!0}).toArray()).length?n=o.collection(t):(n=await o.createCollection(t,{...r.schema&&{validator:{$jsonSchema:r.schema}},...r.blockCompressor&&{storageEngine:{wiredTiger:{configString:`block_compressor=${r.blockCompressor}`}}}}),delete r.schema,delete r.blockCompressor),r.watch!==!1){let c=n.watch(void 0,{fullDocument:r.fullDocument===!1?void 0:"updateLookup"});(process.env.NODE_ENV==="development"?r.quiet!==!0:!r.quiet)&&c.on("change",T),c.on("error",b),n.changeStream=c}this.set(t,n),this[t]=n,i(n),this.#e.delete(t)}return r.schema&&(this.#t.has(t)?console.warn(`\u{1F33F}\u26A0\uFE0F Attempt to set schema for the \x1B[1m${t}\x1B[22m collection at
6
+ ${p()}
7
+
8
+ Which has already been set at
9
+ ${this.#t.get(t)}
10
+
11
+ Skipping`):(this.#t.set(t,p()),await o.command({collMod:t,validator:{$jsonSchema:r.schema}}))),r.indexes&&(this.#o.has(t)?console.warn(`\u{1F33F}\u26A0\uFE0F Attempt to set indexes for the \x1B[1m${t}\x1B[22m collection at
12
+ ${p()}
13
+
14
+ Which have already been set at
15
+ ${this.#o.get(t)}
16
+
17
+ Skipping`):(this.#o.set(t,p()),await n.ensureIndexes(r.indexes))),n}};async function Do({url:e,name:t,...r}){/localhost/.test(e)&&(e=e.replace(/localhost/,"127.0.0.1"));let o=new B(e,{maxPoolSize:100,...r});try{await o.connect(),console.info("\u{1F33F} MongoDB Client connected to",e.replace(/(?<=\/\/)[^:]+?:[^@]+@/,"").replace(/[/?][^/]*$/,""))}catch(i){console.error("\u{1F33F}\u2757\uFE0F MongoDB Client connection: ",i)}o.on("close",()=>console.error("\u{1F33F}\u2757\uFE0F MongoDB socket closed")).on("error",i=>console.error("\u{1F33F}\u2757\uFE0F MongoDB:",i)).on("parseError",i=>console.error("\u{1F33F}\u2757\uFE0F MongoDB parse:",i)).on("reconnect",()=>console.info("\u{1F33F} MongoDB reconnected")).on("timeout",()=>console.error("\u{1F33F}\u2757\uFE0F MongoDB timeout"));let n=o.db(t),s=new g(n);return{client:o,db:n,collections:s}}import{isDeepStrictEqual as D}from"node:util";import{Collection as h}from"mongodb";var I=2;h.prototype.ensureIndexes=async function(e,t=!1){if(t){let r=await this.indexes();for(let o=0;o<e.length;o++){let[n,s={}]=e[o];for(let i=0;i<r.length;i++){let c=r[i];if(D(n,c.key)&&D(s,O(c,["v","key","name"]))){e.splice(o--,1),r.splice(i,1);break}}}await Promise.all([...e.map(o=>this.createIndex(...o)),...r.filter(({name:o,v:n})=>o&&o!=="_id_"&&(!n||n<=I)).map(({name:o})=>this.dropIndex(o))])}else await Promise.all(e.map(r=>this.createIndex(...r)))};h.prototype.onChange=function(e){return this.changeStream.on("change",e),this};h.prototype.prependChange=function(e){return this.changeStream.prependListener("change",e),this};h.prototype.onceChange=function(e){return this.changeStream.once("change",e),this};h.prototype.prependOnceChange=function(e){return this.changeStream.prependOnceListener("change",e),this};h.prototype.removeChangeListener=function(e){return this.changeStream.removeListener("change",e),this};export*from"mongodb";export{Do as connect,Co as newObjectIdString,T as printChangeStreamChangeDetails,b as printChangeStreamError};
3
18
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/connect.ts", "../src/Collections.ts", "../src/extensions/Collection.ts", "../src/utils.ts", "../src/index.ts"],
4
- "sourcesContent": ["import { MongoClient } from \"mongodb\";\nimport { Collections } from \"./Collections\";\nimport type { DB, Options } from \"./types\";\n\n\nexport async function connect({ url, name, ...mongoClientOptions }: Options) {\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, {\n\t\tmaxPoolSize: 100,\n\t\t...mongoClientOptions\n\t});\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 DB;\n\t\n\tconst collections = new Collections(db);\n\t\n\treturn {\n\t\tclient,\n\t\tdb,\n\t\tcollections\n\t};\n}\n", "import type {\n\tChangeStream,\n\tChangeStreamDocument,\n\tCollection,\n\tDocument\n} from \"mongodb\";\nimport type { DB, EnsureOptions, WatchedCollection } 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.info(\"\uD83C\uDF8F Change stream change\", (this.parent as WatchedCollection).collectionName, next);\n\t\n\tfor (const listener of (this.parent as WatchedCollection).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 WatchedCollection).collectionName} Change Stream:\\n`, error.stack);\n\t\n}\n\n\nexport class Collections extends Map<string, Collection> {\n\tconstructor(db: DB) {\n\t\tsuper();\n\t\t\n\t\tthis.db = db;\n\t\t\n\t}\n\t\n\tdb: DB;\n\t\n\t[key: string]: Collection | unknown;\n\t\n\tasync ensure<Doc extends Document>(name: string, options: EnsureOptions & { watch: false }): Promise<Collection<Doc>>;\n\tasync ensure<Doc extends Document>(name: string, options?: EnsureOptions & { watch?: true }): Promise<WatchedCollection<Doc>>;\n\tasync ensure(name: string, options: EnsureOptions = {}) {\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\tif (options.indexes)\n\t\t\tawait collection.ensureIndexes(options.indexes);\n\t\t\n\t\treturn collection;\n\t}\n\t\n}\n", "import { Collection, type ChangeStreamDocument } from \"mongodb\";\nimport type { CollectionIndexes } from \"../types\";\n\n\ndeclare module \"mongodb\" {\n\texport interface Collection<TSchema> { // eslint-disable-line no-shadow\n\t\tchangeListeners?: Set<(listener: ChangeStreamDocument<TSchema>) => void>;\n\t\tchangeStream?: ChangeStream<TSchema>;\n\t\tensureIndexes(indexesToEnsure: CollectionIndexes): 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", "import { ObjectId } from \"mongodb\";\n\n\nexport function newObjectIdString() {\n\treturn (new ObjectId()).toString();\n}\n", "export type { Collections } from \"./Collections\";\nexport * from \"./connect\";\nexport * from \"./extensions\";\nexport * from \"./types\";\nexport * from \"./utils\";\nexport * from \"mongodb\";\n"],
5
- "mappings": "AAAA,OAAS,eAAAA,MAAmB,UCU5B,SAASC,EAA6CC,EAA4B,CAE7E,QAAQ,IAAI,WAAa,eAC5B,QAAQ,KAAK,iCAA4B,KAAK,OAA6B,eAAg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AAQ,OAAO,EAExCC,CACR,CAED,ED/EA,eAAsBC,EAAQ,CAAE,IAAAC,EAAK,KAAAC,EAAM,GAAGC,CAAmB,EAAY,CAExE,YAAY,KAAKF,CAAG,IACvBA,EAAMA,EAAI,QAAQ,YAAa,WAAW,GAE3C,IAAMG,EAAS,IAAIC,EAAYJ,EAAK,CACnC,YAAa,IACb,GAAGE,CACJ,CAAC,EAED,GAAI,CACH,MAAMC,EAAO,QAAQ,EACrB,QAAQ,KAAK,sCAAgCH,EAAI,QAAQ,yBAA0B,EAAE,EAAE,QAAQ,aAAc,EAAE,CAAC,CACjH,OAASK,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,GAAGF,CAAI,EAEnBM,EAAc,IAAIC,EAAYF,CAAE,EAEtC,MAAO,CACN,OAAAH,EACA,GAAAG,EACA,YAAAC,CACD,CACD,CEtCA,OAAS,cAAAE,MAA6C,UAatDA,EAAW,UAAU,cAAgB,eAAgBC,EAAiB,CAMrE,GAAI,CACH,QAAWC,KAAiBD,EAC3B,MAAM,KAAK,YAAY,GAAGC,CAAa,CACzC,MAAQ,CAAC,CAEV,ECxBA,OAAS,YAAAC,MAAgB,UAGlB,SAASC,GAAoB,CACnC,OAAQ,IAAID,EAAS,EAAG,SAAS,CAClC,CCAA,WAAc",
6
- "names": ["MongoClient", "handleChangeStreamChange", "next", "listener", "handleChangeStreamError", "error", "Collections", "db", "name", "options", "collection", "connect", "url", "name", "mongoClientOptions", "client", "MongoClient", "error", "db", "collections", "Collections", "Collection", "indexesToEnsure", "indexToEnsure", "ObjectId", "newObjectIdString"]
3
+ "sources": ["../src/connect.ts", "../../../../@nesvet/npm/n/src/captureStackTrace.ts", "../../../../@nesvet/npm/n/src/noop.ts", "../../../../@nesvet/npm/n/src/debounce.ts", "../../../../@nesvet/npm/n/src/howmuch.ts", "../../../../@nesvet/npm/n/src/omit.ts", "../src/utils.ts", "../src/Collections.ts", "../src/extensions/Collection.ts", "../src/index.ts"],
4
+ "sourcesContent": ["import { MongoClient } from \"mongodb\";\nimport { Collections } from \"./Collections\";\nimport type { DB, Options } from \"./types\";\n\n\nexport async function connect({ url, name, ...mongoClientOptions }: Options) {\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, {\n\t\tmaxPoolSize: 100,\n\t\t...mongoClientOptions\n\t});\n\t\n\ttry {\n\t\tawait client.connect();\n\t\tconsole.info(\"\uD83C\uDF3F MongoDB Client connected to\", url.replace(/(?<=\\/\\/)[^:]+?:[^@]+@/, \"\").replace(/[/?][^/]*$/, \"\"));\n\t} catch (error) {\n\t\tconsole.error(\"\uD83C\uDF3F\u2757\uFE0F MongoDB Client connection: \", error);\n\t}\n\t\n\tclient\n\t\t.on(\"close\", () => console.error(\"\uD83C\uDF3F\u2757\uFE0F MongoDB socket closed\"))\n\t\t.on(\"error\", error => console.error(\"\uD83C\uDF3F\u2757\uFE0F MongoDB:\", error))\n\t\t.on(\"parseError\", error => console.error(\"\uD83C\uDF3F\u2757\uFE0F MongoDB parse:\", error))\n\t\t.on(\"reconnect\", () => console.info(\"\uD83C\uDF3F MongoDB reconnected\"))\n\t\t.on(\"timeout\", () => console.error(\"\uD83C\uDF3F\u2757\uFE0F MongoDB timeout\"));\n\t\n\tconst db = client.db(name) as DB;\n\t\n\tconst collections = new Collections(db);\n\t\n\treturn {\n\t\tclient,\n\t\tdb,\n\t\tcollections\n\t};\n}\n", "declare global {\n\tinterface ErrorConstructor {\n\t\tcaptureStackTrace(targetObject: object, constructorOpt?: Function): void;// eslint-disable-line @typescript-eslint/no-unsafe-function-type\n\t}\n}\n\n\nexport function captureStackTrace(depth = 1, indent = 4) {\n\t\n\tconst indentString = \" \".repeat(indent);\n\t\n\tconst object = {} as { stack: string };\n\t\n\tError.captureStackTrace(object, captureStackTrace);\n\t\n\tconst stackTrace =\n\t\tobject.stack\n\t\t\t.replace(/^Error\\W+/m, \"\")\n\t\t\t.replaceAll(/^\\s+/gm, \"\")\n\t\t\t.split(\"\\n\")\n\t\t\t.slice(depth)\n\t\t\t.join(`\\n${indentString}`);\n\t\n\treturn `${indentString}${stackTrace}`;\n}\n", "export function noop() { /**/ }\n", "import { noop } from \"./noop.js\";\n\n\ntype Callback<Result> = (...args: unknown[]) => Result;\ntype FunctionOrBoolean = (() => unknown) | boolean;\ntype Options = { leading?: FunctionOrBoolean; maxWait?: number; trailing?: FunctionOrBoolean };\ntype NumberOrUndefined = number | undefined;\n\ntype DebouncedFunction<Result> = {\n\t(this: unknown, ..._args: unknown[]): Promise<Result>;\n};\n\nexport type Debounced<Result> = {\n\tcallback: Callback<Result>;\n\tpromise: {\n\t\tisResolved: boolean;\n\t} & Promise<unknown>;\n\tresolve: (value: Result) => void;\n\trun(): Promise<Result>;\n\tclear(shouldRun?: boolean): Promise<void>;\n} & DebouncedFunction<Result>;\n\n\nexport function debounce<Result>(callback: Callback<Result>, limit = 0, options: Options = {}) {\n\tlet { leading = false, trailing = true } = options;\n\tconst { maxWait = Infinity } = options;\n\t\n\tlet timeout: NumberOrUndefined;\n\tlet maxWaitTimeout: NumberOrUndefined;\n\tlet end: NumberOrUndefined;\n\tlet context: unknown;\n\tlet args: unknown[];\n\tlet initial: FunctionOrBoolean;\n\tlet final: FunctionOrBoolean;\n\tlet result: Result;\n\t\n\tconst expired = async () => {\n\t\t\n\t\tconst n = Date.now();\n\t\t\n\t\tif (n >= end!) {\n\t\t\ttimeout = undefined;\n\t\t\tend = undefined;\n\t\t\tclearTimeout(maxWaitTimeout);\n\t\t\tif (typeof final == \"function\")\n\t\t\t\tawait final();\n\t\t\tdebounced.resolve(result);\n\t\t\tdebounced.promise.isResolved = true;\n\t\t\tinitial = leading;\n\t\t} else {\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = setTimeout(expired, end! - n);\n\t\t}\n\t\t\n\t};\n\t\n\tconst maxWaitExpired = Number.isFinite(maxWait) ? () => {\n\t\t\n\t\tif (final === run)\n\t\t\tfinal = false;\n\t\trun();\n\t\tmaxWaitTimeout = setTimeout(maxWaitExpired as TimerHandler, maxWait);\n\t\t\n\t} : null;\n\t\n\tasync function run() {\n\t\treturn (result = await callback.apply(context, args));\n\t}\n\t\n\tif (leading && typeof leading == \"boolean\")\n\t\tleading = run;\n\tinitial = leading;\n\t\n\tif (trailing && typeof trailing == \"boolean\")\n\t\ttrailing = run;\n\tfinal = trailing;\n\t\n\tconst debounced: Debounced<Result> = Object.assign(function (..._args) {\n\t\targs = _args;\n\t\tcontext = this;// eslint-disable-line no-invalid-this\n\t\t\n\t\tend = Date.now() + limit;\n\t\tfinal = trailing;\n\t\t\n\t\tif (debounced.promise.isResolved)\n\t\t\tdebounced.promise = Object.assign(new Promise(resolve => {\n\t\t\t\tdebounced.resolve = resolve;\n\t\t\t\t\n\t\t\t\tif (typeof initial == \"function\") {\n\t\t\t\t\tinitial();\n\t\t\t\t\tinitial = false;\n\t\t\t\t\tif (final === run)\n\t\t\t\t\t\tfinal = false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (!timeout) {\n\t\t\t\t\ttimeout = setTimeout(expired, limit);\n\t\t\t\t\tif (maxWaitExpired)\n\t\t\t\t\t\tmaxWaitTimeout = setTimeout(maxWaitExpired, maxWait);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}), {\n\t\t\t\tisResolved: false\n\t\t\t});\n\t\t\n\t\treturn debounced.promise;\n\t} as DebouncedFunction<Result>, {\n\t\tcallback,\n\t\tpromise: Object.assign(Promise.resolve(), {\n\t\t\tisResolved: true\n\t\t}),\n\t\tresolve: noop,\n\t\trun,\n\t\tclear: async (shouldRun?: boolean) => {\n\t\t\t\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = undefined;\n\t\t\t\n\t\t\tclearTimeout(maxWaitTimeout);\n\t\t\t\n\t\t\tdebounced.promise.isResolved = true;\n\t\t\tdebounced.resolve(shouldRun ? await run() : result);\n\t\t\t\n\t\t}\n\t});\n\t\n\treturn debounced;\n}\n\n\ndebounce.noop = Object.assign(() => { /**/ }, {\n\tcallback: noop,\n\tpromise: Object.assign(Promise.resolve(), {\n\t\tisResolved: true\n\t}),\n\tresolve: noop,\n\trun: noop,\n\tclear: noop\n}) as unknown as Debounced<void>;\n\n\nexport function throttle<Result>(callback: Callback<Result>, limit?: number, options?: Options) {\n\treturn debounce(callback, limit, {\n\t\tmaxWait: limit,\n\t\tleading: true,\n\t\ttrailing: true,\n\t\t...options\n\t});\n}\n", "export function howmuch(number: [] | number, one: string, two: string, five: boolean | string, shouldPrintNumber = true) {\n\tif (Array.isArray(number))\n\t\tnumber = number.length;\n\t\n\tif (typeof five != \"string\") {\n\t\tshouldPrintNumber = five ?? true;\n\t\tfive = two;\n\t}\n\t\n\t\n\treturn (shouldPrintNumber ? `${number}\u00A0` : \"\") + howmuch.raw(number, one, two, five);\n}\n\nhowmuch.raw = (number: number, one: string, two: string, five = two) => {\n\tnumber = Math.abs(number);\n\tconst u = number % 10;\n\tconst d = number % 100;\n\t\n\treturn (\n\t\t(u === 1 && d !== 11) ?\n\t\t\tone :\n\t\t\t((u >= 2 && u <= 4) && !(d >= 12 && d <= 15)) ?\n\t\t\t\ttwo :\n\t\t\t\tfive\n\t);\n};\n", "export function omit<O extends object, K extends keyof O>(object: O, keys: K[]) {\n\tconst result = { ...object };\n\t\n\tfor (const key of keys)\n\t\tdelete result[key];\n\t\n\treturn result as Omit<O, K>;\n}\n", "import { ObjectId, type ChangeStream, type ChangeStreamDocument } from \"mongodb\";\nimport type { WatchedCollection } from \"./types\";\n\n\nexport function newObjectIdString() {\n\treturn (new ObjectId()).toString();\n}\n\n/** @this ChangeStream */\nexport function printChangeStreamChangeDetails(this: ChangeStream, next: ChangeStreamDocument) {\n\t\n\tconst messages = [];\n\t\n\tswitch (next.operationType) {\n\t\tcase \"insert\":\n\t\tcase \"replace\":\n\t\t\tmessages.push(\"fullDocument:\", next.fullDocument);\n\t\t\tbreak;\n\t\t\n\t\tcase \"update\":\n\t\t\tmessages.push(\"_id:\", next.documentKey._id, \"\\n\", \"updateDescription:\", next.updateDescription);\n\t\t\tbreak;\n\t\t\n\t\tcase \"delete\":\n\t\t\tmessages.push(\"_id:\", next.documentKey._id);\n\t\t\tbreak;\n\t\t\n\t\tdefault:\n\t\t\tmessages.push(next);\n\t}\n\t\n\tconsole.info(\"\uD83C\uDF3F\uD83C\uDF8F\", `\\x1B[1m${(this.parent as WatchedCollection).collectionName}\\x1B[0m`, `\\x1B[3m${next.operationType}\\x1B[0m`, ...messages);\n\t\n}\n\n/** @this ChangeStream */\nexport function printChangeStreamError(this: ChangeStream, error: Error) {\n\tconsole.error(`\uD83C\uDF3F\u2757\uFE0F MongoDB ${(this.parent as WatchedCollection).collectionName} Change Stream:\\n`, error.stack);\n\t\n}\n", "import type { Collection, Document } from \"mongodb\";\nimport { captureStackTrace } from \"@nesvet/n\";\nimport { printChangeStreamChangeDetails, printChangeStreamError } from \"./utils\";\nimport type { CollectionOptions, DB, WatchedCollection } from \"./types\";\n\n\nexport class Collections extends Map<string, Collection> {\n\tconstructor(db: DB) {\n\t\tsuper();\n\t\t\n\t\tthis.db = db;\n\t\t\n\t}\n\t\n\tdb: DB;\n\t\n\t#awaiting = new Map<string, Promise<Collection>>();\n\t\n\t#schemaSet = new Map<string, string>();\n\t#indexesSet = new Map<string, string>();\n\t\n\t[key: string]: Collection | unknown;\n\t\n\tasync ensure<Doc extends Document>(name: string, options: CollectionOptions & { watch: false }): Promise<Collection<Doc>>;\n\tasync ensure<Doc extends Document>(name: string, options?: CollectionOptions): Promise<WatchedCollection<Doc>>;\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) ?? await this.#awaiting.get(name);\n\t\t\n\t\tif (!collection) {\n\t\t\tconst { promise, resolve } = Promise.withResolvers<Collection>();\n\t\t\tthis.#awaiting.set(name, promise);\n\t\t\t\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.schema && { validator: { $jsonSchema: options.schema } },\n\t\t\t\t\t...options.blockCompressor && { storageEngine: { wiredTiger: { configString: `block_compressor=${options.blockCompressor}` } } }\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\tdelete options.schema;\n\t\t\t\tdelete options.blockCompressor;\n\t\t\t}\n\t\t\t\n\t\t\tif (options.watch !== false) {\n\t\t\t\tconst changeStream = collection.watch(undefined, { fullDocument: options.fullDocument === false ? undefined : \"updateLookup\" });\n\t\t\t\t\n\t\t\t\tif (process.env.NODE_ENV === \"development\" ? options.quiet !== true : !options.quiet)\n\t\t\t\t\tchangeStream.on(\"change\", printChangeStreamChangeDetails);\n\t\t\t\t\n\t\t\t\tchangeStream.on(\"error\", printChangeStreamError);\n\t\t\t\t\n\t\t\t\tcollection.changeStream = changeStream;\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\tresolve(collection);\n\t\t\tthis.#awaiting.delete(name);\n\t\t}\n\t\t\n\t\tif (options.schema)\n\t\t\tif (this.#schemaSet.has(name))\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`\uD83C\uDF3F\u26A0\uFE0F Attempt to set schema for the \\x1B[1m${name}\\x1B[22m collection at\\n` +\n\t\t\t\t\t`${captureStackTrace()}\\n` +\n\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\" Which has already been set at\\n\" +\n\t\t\t\t\t`${this.#schemaSet.get(name)}\\n` +\n\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\" Skipping\"\n\t\t\t\t);\n\t\t\telse {\n\t\t\t\tthis.#schemaSet.set(name, captureStackTrace());\n\t\t\t\t\n\t\t\t\tawait db.command({ collMod: name, validator: { $jsonSchema: options.schema } });\n\t\t\t}\n\t\t\n\t\tif (options.indexes)\n\t\t\tif (this.#indexesSet.has(name))\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`\uD83C\uDF3F\u26A0\uFE0F Attempt to set indexes for the \\x1B[1m${name}\\x1B[22m collection at\\n` +\n\t\t\t\t\t`${captureStackTrace()}\\n` +\n\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\" Which have already been set at\\n\" +\n\t\t\t\t\t`${this.#indexesSet.get(name)}\\n` +\n\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\" Skipping\"\n\t\t\t\t);\n\t\t\telse {\n\t\t\t\tthis.#indexesSet.set(name, captureStackTrace());\n\t\t\t\t\n\t\t\t\tawait collection.ensureIndexes(options.indexes);\n\t\t\t}\n\t\t\n\t\treturn collection;\n\t}\n\t\n}\n", "import { isDeepStrictEqual } from \"node:util\";\nimport { Collection } from \"mongodb\";\nimport { omit } from \"@nesvet/n\";\nimport type { ChangeStreamListener, CollectionIndexes, WatchedCollection } from \"../types\";\n\n\nconst ACTUAL_INDEX_VERSION = 2;\n\n\ndeclare module \"mongodb\" {\n\texport interface Collection<TSchema> { // eslint-disable-line no-shadow\n\t\t\n\t\t/** Ensures the presence of `indexes`. */\n\t\tensureIndexes(indexes: CollectionIndexes): Promise<void>;\n\t\t\n\t\t/** Change Stream, watching for new changes in this collection. */\n\t\tchangeStream?: ChangeStream<TSchema>;\n\t\t\n\t\t/** Adds the `listener` function to the end of the listeners array for the event `change`. */\n\t\tonChange?(listener: ChangeStreamListener<TSchema>): this;\n\t\t\n\t\t/** Adds the `listener` function to the *beginning* of the listeners array for the event `change`. */\n\t\tprependChange?(listener: ChangeStreamListener<TSchema>): this;\n\t\t\n\t\t/** Adds the **one-time** `listener` function to the end of the listeners array for the event `change`. */\n\t\tonceChange?(listener: ChangeStreamListener<TSchema>): this;\n\t\t\n\t\t/** Adds the **one-time** function to the *beginning* of the listeners array for the event `change`. */\n\t\tprependOnceChange?(listener: ChangeStreamListener<TSchema>): this;\n\t\t\n\t\t/** Removes the `listener` from the listener array for the event `change`. */\n\t\tremoveChangeListener?(listener: ChangeStreamListener<TSchema>): this;\n\t\t\n\t}\n}\n\n\nCollection.prototype.ensureIndexes = async function (indexes, dropOther = false) {\n\tif (dropOther) {\n\t\tconst existingIndexes = await this.indexes();\n\t\t\n\t\tfor (let i = 0; i < indexes.length; i++) {\n\t\t\tconst [ specification, options = {} ] = indexes[i];\n\t\t\t\n\t\t\tfor (let j = 0; j < existingIndexes.length; j++) {\n\t\t\t\tconst existingIndex = existingIndexes[j];\n\t\t\t\t\n\t\t\t\tif (\n\t\t\t\t\tisDeepStrictEqual(specification, existingIndex.key) &&\n\t\t\t\t\tisDeepStrictEqual(options, omit(existingIndex, [ \"v\", \"key\", \"name\" ]))\n\t\t\t\t) {\n\t\t\t\t\tindexes.splice(i--, 1);\n\t\t\t\t\texistingIndexes.splice(j, 1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tawait Promise.all([\n\t\t\t...indexes.map(index => this.createIndex(...index)),\n\t\t\t...existingIndexes.filter(({ name, v }) => name && name !== \"_id_\" && (!v || v <= ACTUAL_INDEX_VERSION)).map(({ name }) => this.dropIndex(name!))\n\t\t]);\n\t} else\n\t\tawait Promise.all(indexes.map(index => this.createIndex(...index)));\n\t\n};\n\nCollection.prototype.onChange = function (this: WatchedCollection, listener) {\n\tthis.changeStream.on(\"change\", listener);\n\t\n\treturn this;\n};\n\nCollection.prototype.prependChange = function (this: WatchedCollection, listener) {\n\tthis.changeStream.prependListener(\"change\", listener);\n\t\n\treturn this;\n};\n\nCollection.prototype.onceChange = function (this: WatchedCollection, listener) {\n\tthis.changeStream.once(\"change\", listener);\n\t\n\treturn this;\n};\n\nCollection.prototype.prependOnceChange = function (this: WatchedCollection, listener) {\n\tthis.changeStream.prependOnceListener(\"change\", listener);\n\t\n\treturn this;\n};\n\nCollection.prototype.removeChangeListener = function (this: WatchedCollection, listener) {\n\tthis.changeStream.removeListener(\"change\", listener);\n\t\n\treturn this;\n};\n", "export type { Collections } from \"./Collections\";\nexport * from \"./connect\";\nexport * from \"./extensions\";\nexport * from \"./types\";\nexport { CollectionOptions } from \"./types\";\nexport * from \"./utils\";\nexport * from \"mongodb\";\n"],
5
+ "mappings": "AAAA,OAAS,eAAAA,MAAmB,UCOtB,SAAUC,EAAkBC,EAAQ,EAAGC,EAAS,EAAC,CAEtD,IAAMC,EAAe,IAAI,OAAOD,CAAM,EAEhCE,EAAS,CAAA,EAEf,MAAM,kBAAkBA,EAAQJ,CAAiB,EAEjD,IAAMK,EACLD,EAAO,MACL,QAAQ,aAAc,EAAE,EACxB,WAAW,SAAU,EAAE,EACvB,MAAM;CAAI,EACV,MAAMH,CAAK,EACX,KAAK;EAAKE,CAAY,EAAE,EAE3B,MAAO,GAAGA,CAAY,GAAGE,CAAU,EACpC,CCxBM,SAAUC,GAAI,CAAU,CCuBxB,SAAUC,EAAiBC,EAA4BC,EAAQ,EAAGC,EAAmB,CAAA,EAAE,CAC5F,GAAI,CAAE,QAAAC,EAAU,GAAO,SAAAC,EAAW,EAAI,EAAKF,EACrC,CAAE,QAAAG,EAAU,GAAQ,EAAKH,EAE3BI,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEEC,EAAU,SAAW,CAE1B,IAAMC,EAAI,KAAK,IAAG,EAEdA,GAAKP,GACRF,EAAU,OACVE,EAAM,OACN,aAAaD,CAAc,EACvB,OAAOK,GAAS,YACnB,MAAMA,EAAK,EACZI,EAAU,QAAQH,CAAM,EACxBG,EAAU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AAC,CAAE,KAAAa,CAAK,IAAM,KAAK,UAAUA,CAAK,CAAC,CACjJ,CAAC,CACF,MACC,MAAM,QAAQ,IAAIX,EAAQ,IAAIU,GAAS,KAAK,YAAY,GAAGA,CAAK,CAAC,CAAC,CAEpE,EAEAX,EAAW,UAAU,SAAW,SAAmCc,EAAU,CAC5E,YAAK,aAAa,GAAG,SAAUA,CAAQ,EAEhC,IACR,EAEAd,EAAW,UAAU,cAAgB,SAAmCc,EAAU,CACjF,YAAK,aAAa,gBAAgB,SAAUA,CAAQ,EAE7C,IACR,EAEAd,EAAW,UAAU,WAAa,SAAmCc,EAAU,CAC9E,YAAK,aAAa,KAAK,SAAUA,CAAQ,EAElC,IACR,EAEAd,EAAW,UAAU,kBAAoB,SAAmCc,EAAU,CACrF,YAAK,aAAa,oBAAoB,SAAUA,CAAQ,EAEjD,IACR,EAEAd,EAAW,UAAU,qBAAuB,SAAmCc,EAAU,CACxF,YAAK,aAAa,eAAe,SAAUA,CAAQ,EAE5C,IACR,ECzFA,WAAc",
6
+ "names": ["MongoClient", "captureStackTrace", "depth", "indent", "indentString", "object", "stackTrace", "noop", "debounce", "callback", "limit", "options", "leading", "trailing", "maxWait", "timeout", "maxWaitTimeout", "end", "context", "args", "initial", "final", "result", "expired", "n", "debounced", "maxWaitExpired", "run", "_args", "resolve", "noop", "shouldRun", "howmuch", "number", "one", "two", "five", "shouldPrintNumber", "u", "d", "omit", "object", "keys", "result", "key", "ObjectId", "newObjectIdString", "printChangeStreamChangeDetails", "next", "messages", "printChangeStreamError", "error", "Collections", "db", "#awaiting", "#schemaSet", "#indexesSet", "name", "options", "collection", "promise", "resolve", "changeStream", "printChangeStreamChangeDetails", "printChangeStreamError", "captureStackTrace", "connect", "url", "name", "mongoClientOptions", "client", "MongoClient", "error", "db", "collections", "Collections", "isDeepStrictEqual", "Collection", "ACTUAL_INDEX_VERSION", "Collection", "indexes", "dropOther", "existingIndexes", "i", "specification", "options", "j", "existingIndex", "isDeepStrictEqual", "omit", "index", "name", "v", "listener"]
7
7
  }
package/dist/types.d.ts CHANGED
@@ -1,18 +1,20 @@
1
1
  import type { JSONSchema4 } from "json-schema";
2
- import type { Collection, CreateIndexesOptions, Db, Document, IndexSpecification, MongoClientOptions } from "mongodb";
2
+ import type { ChangeStreamDocument, Collection, CreateIndexesOptions, Db, Document, IndexSpecification, MongoClientOptions } from "mongodb";
3
3
  export type Options = MongoClientOptions & {
4
4
  url: string;
5
5
  name: string;
6
6
  };
7
7
  export type DB = Db;
8
8
  export type CollectionSchema = JSONSchema4;
9
- export type EnsureOptions = {
9
+ export type CollectionOptions = {
10
10
  fullDocument?: boolean;
11
- jsonSchema?: CollectionSchema;
11
+ schema?: CollectionSchema;
12
12
  indexes?: CollectionIndexes;
13
13
  blockCompressor?: "none" | "snappy" | "zlib" | "zstd";
14
14
  watch?: boolean;
15
+ quiet?: boolean;
15
16
  };
16
17
  export type CollectionIndexes = [IndexSpecification, CreateIndexesOptions?][];
17
- export type WatchedCollection<Doc extends Document = Document> = Collection<Doc> & Required<Pick<Collection<Doc>, "changeListeners" | "changeStream">>;
18
+ export type ChangeStreamListener<TSchema extends Document> = (listener: ChangeStreamDocument<TSchema>) => void;
19
+ export type WatchedCollection<Doc extends Document = Document> = Collection<Doc> & Required<Pick<Collection<Doc>, "changeStream" | "onceChange" | "onChange" | "prependChange" | "prependOnceChange" | "removeChangeListener">>;
18
20
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EACX,UAAU,EACV,oBAAoB,EACpB,EAAE,EACF,QAAQ,EACR,kBAAkB,EAClB,kBAAkB,EAClB,MAAM,SAAS,CAAC;AAGjB,MAAM,MAAM,OAAO,GAAG,kBAAkB,GAAG;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,IAA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B,CAAC;IAC1B,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IACtD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,CAAE,kBAAkB,EAAE,oBAAoB,CAAC,CAAE,EAAE,CAAC;AAEhF,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,QAAQ,IAAI,CAAC,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;AAE/G,MAAM,MAAM,iBAAiB,CAAC,GAAG,SAAS,QAAQ,GAAG,QAAQ,IAC5D,UAAU,CAAC,GAAG,CAAC,GACf,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,cAAc,GAAG,YAAY,GAAG,UAAU,GAAG,eAAe,GAAG,mBAAmB,GAAG,sBAAsB,CAAC,CAAC,CAAC"}
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,7 @@
1
+ import { type ChangeStream, type ChangeStreamDocument } from "mongodb";
1
2
  export declare function newObjectIdString(): string;
3
+ /** @this ChangeStream */
4
+ export declare function printChangeStreamChangeDetails(this: ChangeStream, next: ChangeStreamDocument): void;
5
+ /** @this ChangeStream */
6
+ export declare function printChangeStreamError(this: ChangeStream, error: Error): void;
2
7
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,WAEhC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAE,KAAK,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAIjF,wBAAgB,iBAAiB,WAEhC;AAED,yBAAyB;AACzB,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,oBAAoB,QAwB5F;AAED,yBAAyB;AACzB,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,QAGtE"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "insite-db",
3
- "version": "2.1.2",
3
+ "version": "2.2.1",
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.2.2",
8
+ "packageManager": "bun@1.2.5",
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1",
11
11
  "build": "bun .conveyer.js",
@@ -23,13 +23,14 @@
23
23
  "author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "mongodb": "^6.13.0"
26
+ "@nesvet/n": "^1.1.26",
27
+ "mongodb": "^6.14.2"
27
28
  },
28
29
  "devDependencies": {
29
- "@nesvet/conveyer": "^2.4.3",
30
- "@nesvet/eslint-config": "^2.0.47",
30
+ "@nesvet/conveyer": "^2.5.0",
31
+ "@nesvet/eslint-config": "^2.0.48",
31
32
  "@types/json-schema": "^7.0.15",
32
- "@types/node": "^22.13.1",
33
- "typescript": "^5.7.3"
33
+ "@types/node": "^22.13.10",
34
+ "typescript": "^5.8.2"
34
35
  }
35
36
  }