Socket
Socket
Sign inDemoInstall

mongosteel

Package Overview
Dependencies
18
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.5 to 1.3.6

dist/types/index.d.ts

4

dist/cjs/index.js

@@ -1,2 +0,2 @@

var M=Object.create;var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var m=o=>f(o,"__esModule",{value:!0});var I=typeof require!="undefined"?require:o=>{throw new Error('Dynamic require of "'+o+'" is not supported')};var L=(o,e)=>{m(o);for(var i in e)f(o,i,{get:e[i],enumerable:!0})},R=(o,e,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of k(e))!v.call(o,a)&&a!=="default"&&f(o,a,{get:()=>e[a],enumerable:!(i=S(e,a))||i.enumerable});return o},x=o=>R(m(f(o!=null?M(T(o)):{},"default",o&&o.__esModule&&"default"in o?{get:()=>o.default,enumerable:!0}:{value:o,enumerable:!0})),o);L(exports,{MongoSteel:()=>g,Schema:()=>h,model:()=>O,toUrl:()=>y});var u=class extends Error{constructor(e){super("This document is not valid!");Object.setPrototypeOf(this,u.prototype),this.obj=e}},h=class{constructor(e){function i(n){if(typeof n=="string")return n||(n="string"),{type:n,required:!0};if(Array.isArray(n))return n.length==2?{type:["string",i(n[1])],required:!0}:{type:[i(n[0])],required:!0};if(typeof n!="object")throw new Error("Unrecognised schema type!");return Object.keys(n).includes("type")&&Object.keys(n).includes("required")?(typeof n.type=="object"&&(n.type=i(n.type)),n):a(n)}function a(n){let l={};if(Array.isArray(n))throw new Error("Schema can't be an array!");if(typeof n!="object")throw new Error("Unrecognised schema type!");return Object.keys(n).forEach(r=>{l[r]=i(n[r])}),l}this.schema=a(e)}validate(e,i={}){if(typeof e!="object"||Array.isArray(e))return{valid:!1,reason:"majorBadType"};function a(r,s,t){switch(r.type){case"boolean":return typeof s!="boolean"?{valid:!1,reason:"badType",badKey:t}:!1;case"number":return typeof s!="number"?{valid:!1,reason:"badType",badKey:t}:!1;case"string":return typeof s!="string"?{valid:!1,reason:"badType",badKey:t}:r.pattern&&!r.pattern?.test(s)?{valid:!1,reason:"badType",badKey:t}:!1;case"mixed":return!1;default:return console.warn(`Unknown type for ${t}! The schema says ${r.type}`),!1}}let n="";function l(r,s){if(Object.keys(r).includes("type")&&Object.keys(r).includes("required")){let t=a(r,s,n);if(t)return t}else for(let t in r)if(typeof s=="object"&&!Array.isArray(s)&&!Object.keys(s).includes(t)){if(r[t].required&&!i.ignoreRequired)return{valid:!1,reason:"required",badKey:t};r[t].default&&!i.ignoreDefault&&(typeof r[t].default=="function"?e[t]=r[t].default():e[t]=r[t].default);continue}else if(Array.isArray(r[t].type)){if(r[t].type.length==2){if(typeof s[t]!="object"||Array.isArray(s[t]))return{valid:!1,reason:"badType",badKey:t};for(let c in s[t]){let p=l(r[t].type[1],s[t][c]);if(!p.valid)return p}}if(!Array.isArray(s[t]))return{valid:!1,reason:"badType",badKey:t};n=t,s[t].forEach(c=>{let p=l(r[t].type[0],c);if(!p.valid)return p})}else if(typeof r[t].type=="object"){let c=l(r[t].type,s[t]);if(!c.valid)return c}else{let c=a(r[t],s[t],t);if(c)return c}return{valid:!0,res:e}}return l(this.schema,e)}};var w=x(require("mongodb"));function y(o){return["dbName","location","password","user"].forEach(e=>{if(!Object.keys(o).includes(e))throw Error(`${e} is required in the options!`)}),o.dbOpts||(o.dbOpts={}),`mongodb://${encodeURI(o.user)}:${encodeURI(o.password)}@${encodeURI(o.location)}/${o.dbName}${Object.keys(o.dbOpts).length==0?"":"?"}${Object.keys(o.dbOpts).map((e,i)=>`${i==0?"":"&"}${encodeURI(`${e}=${(o.dbOpts??{})[e]}`)}`).join("")}`}var d={on:!1,models:{},opts:{}},g=class{static async connect(e,i,a){if(d.on){if(e)throw new Error(`I already have a connection to ${d.url}!`);return d.db}if(!e)throw new Error("I have nothing to connect to!");let n=typeof e=="string"?encodeURI(e):y(e),l=await w.MongoClient.connect(n,Object.assign({useNewUrlParser:!0,useUnifiedTopology:!0},i)),r=l.db(),s=Object.assign({},a);return d={on:!0,db:r,client:l,url:n,opts:s,models:d.models},r}static async disconnect(){d&&(await d.client?.close(),d={on:!1,client:void 0,db:void 0,url:void 0,models:d.models,opts:d.opts})}};var b=class{constructor(e,i,a,n){let l=i.validate(a);if(!l.valid&&!d.opts.noVerification)throw new u(l);this.doc=l.valid?l.res:a,this.schema=i,this.saved=!1,this.oldId="",this.methods=n;let r=setInterval(function(){d.on&&(clearInterval(r),this.collection=d.db.collection(e))},100)}async save(){!d.opts.noIdDetection&&this.saved&&this.oldId==this.doc._id&&(console.warn(`The _id ${this.doc._id} has already been saved once, overriding it with a new id...
To avoid this, use mongoSteel option { noIdDetection:true }`),delete this.doc._id);let e=await this.collection.insertOne(this.doc);if(!e.insertedId)throw Error("Not inserted");if(!d.opts.noDocsUpdate){let i=await this.collection.findOne({_id:e.insertedId});if(!i)throw Error("Weird");this.doc=i}return this.saved=!0,this.oldId=e.insertedId,this.doc}static async find(e){return await this.collection.find(e).toArray()}static async findOne(e){return await this.collection.findOne(e)}static async findOneAndDelete(e){let i=await this.collection.findOneAndDelete(e);if(!i.ok)throw new Error("findOneAndDelete returned not OK");return i.value}static async findOneAndReplace(e,i){let a=this.schema.validate(i);if(!a.valid)throw new u(a);i=a.res;let n=await this.collection.findOneAndReplace(e,i);if(!n.ok)throw new Error("findOneAndReplace returned not OK");return n.value}static async findOneAndUpdate(e,i){let a=this.schema.validate(i,{ignoreDefault:!0,ignoreRequired:!0});if(!a.valid)throw new u(a);let n=await this.collection.findOneAndUpdate(e,{$set:i});if(!n.ok)throw new Error("findOneAndUpdate returned not OK");return n.value}static async deleteMany(e){await this.collection.deleteMany(e)}};function O(o,e,i){class a extends b{constructor(r={}){super(o,e,r,i)}}let n=setInterval(function(){d.on&&(clearInterval(n),a.collection=d.db.collection(o))},100);return a.schema=e,a.methods=i,a}0&&(module.exports={MongoSteel,Schema,model,toUrl});
var M=Object.create;var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var m=t=>f(t,"__esModule",{value:!0});var I=typeof require!="undefined"?require:t=>{throw new Error('Dynamic require of "'+t+'" is not supported')};var L=(t,e)=>{m(t);for(var o in e)f(t,o,{get:e[o],enumerable:!0})},R=(t,e,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of k(e))!v.call(t,a)&&a!=="default"&&f(t,a,{get:()=>e[a],enumerable:!(o=S(e,a))||o.enumerable});return t},x=t=>R(m(f(t!=null?M(T(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);L(exports,{MongoSteel:()=>g,Schema:()=>h,model:()=>O,toUrl:()=>y});var u=class extends Error{constructor(e){super("This document is not valid!");Object.setPrototypeOf(this,u.prototype),this.obj=e}},h=class{constructor(e){function o(n){if(typeof n=="string")return n||(n="string"),{type:n,required:!0};if(Array.isArray(n))return n.length==2?{type:["string",o(n[1])],required:!0}:{type:[o(n[0])],required:!0};if(typeof n!="object")throw new Error("Unrecognised schema type!");return Object.keys(n).includes("type")&&Object.keys(n).includes("required")?(typeof n.type=="object"&&(n.type=o(n.type)),n):a(n)}function a(n){let l={};if(Array.isArray(n))throw new Error("Schema can't be an array!");if(typeof n!="object")throw new Error("Unrecognised schema type!");return Object.keys(n).forEach(r=>{l[r]=o(n[r])}),l}this.schema=a(e)}validate(e,o={}){if(typeof e!="object"||Array.isArray(e))return{valid:!1,reason:"majorBadType"};function a(r,s,i){switch(r.type){case"boolean":return typeof s!="boolean"?{valid:!1,reason:"badType",badKey:i}:!1;case"number":return typeof s!="number"?{valid:!1,reason:"badType",badKey:i}:!1;case"string":return typeof s!="string"?{valid:!1,reason:"badType",badKey:i}:r.pattern&&!r.pattern?.test(s)?{valid:!1,reason:"badType",badKey:i}:!1;case"mixed":return!1;default:return!1}}let n="";function l(r,s){if(Object.keys(r).includes("type")&&Object.keys(r).includes("required")){let i=a(r,s,n);if(i)return i}else for(let i in r)if(typeof s=="object"&&!Array.isArray(s)&&!Object.keys(s).includes(i)){if(r[i].required&&!o.ignoreRequired)return{valid:!1,reason:"required",badKey:i};r[i].default&&!o.ignoreDefault&&(typeof r[i].default=="function"?e[i]=r[i].default():e[i]=r[i].default)}else if(Array.isArray(r[i].type)){if(r[i].type.length==2){if(Array.isArray(s[i]))return{valid:!1,reason:"badType",badKey:i};for(let c in s[i]){let p=l(r[i].type[1],s[i][c]);if(!p.valid)return p}}if(!Array.isArray(s[i]))return{valid:!1,reason:"badType",badKey:i};n=i,s[i].forEach(c=>{let p=l(r[i].type[0],c);if(!p.valid)return p})}else if(typeof r[i].type=="object"){let c=l(r[i].type,s[i]);if(!c.valid)return c}else{let c=a(r[i],s[i],i);if(c)return c}return{valid:!0,res:e}}return l(this.schema,e)}};var w=x(require("mongodb"));function y(t){return["dbName","location","password","user"].forEach(e=>{if(!Object.keys(t).includes(e))throw Error(`${e} is required in the options!`)}),t.dbOpts||(t.dbOpts={}),`mongodb://${encodeURI(t.user)}:${encodeURI(t.password)}@${encodeURI(t.location)}/${t.dbName}${Object.keys(t.dbOpts).length==0?"":"?"}${Object.keys(t.dbOpts).map((e,o)=>`${o==0?"":"&"}${encodeURI(`${e}=${(t.dbOpts??{})[e]}`)}`).join("")}`}var d={on:!1,models:{},opts:{}},g=class{static async connect(e,o,a){if(d.on){if(e)throw new Error(`I already have a connection to ${d.url}!`);return d.db}if(!e)throw new Error("I have nothing to connect to!");let n=typeof e=="string"?encodeURI(e):y(e),l=await w.MongoClient.connect(n,Object.assign({useNewUrlParser:!0,useUnifiedTopology:!0},o)),r=l.db(),s=Object.assign({},a);return d={on:!0,db:r,client:l,url:n,opts:s,models:d.models},r}static async disconnect(){d&&(await d.client?.close(),d={on:!1,client:void 0,db:void 0,url:void 0,models:d.models,opts:d.opts})}};var b=class{constructor(e,o,a,n){let l=o.validate(a);if(!l.valid&&!d.opts.noVerification)throw new u(l);this.doc=l.valid?l.res:a,this.schema=o,this.saved=!1,this.oldId="",this.methods=n;let r=setInterval(function(){d.on&&(clearInterval(r),this.collection=d.db.collection(e))},100)}async save(){!d.opts.noIdDetection&&this.saved&&this.oldId==this.doc._id&&(console.warn(`The _id ${this.doc._id} has already been saved once, overriding it with a new id...
To avoid this, use mongoSteel option { noIdDetection:true }`),delete this.doc._id);let e=await this.collection.insertOne(this.doc);if(!e.insertedId)throw Error("Not inserted");if(!d.opts.noDocsUpdate){let o=await this.collection.findOne({_id:e.insertedId});if(!o)throw Error("Weird");this.doc=o}return this.saved=!0,this.oldId=e.insertedId,this.doc}static async find(e){return await this.collection.find(e).toArray()}static async findOne(e){return await this.collection.findOne(e)}static async findOneAndDelete(e){let o=await this.collection.findOneAndDelete(e);if(!o.ok)throw new Error("findOneAndDelete returned not OK");return o.value}static async findOneAndReplace(e,o){let a=this.schema.validate(o);if(!a.valid)throw new u(a);o=a.res;let n=await this.collection.findOneAndReplace(e,o);if(!n.ok)throw new Error("findOneAndReplace returned not OK");return n.value}static async findOneAndUpdate(e,o){let a=this.schema.validate(o,{ignoreDefault:!0,ignoreRequired:!0});if(!a.valid)throw new u(a);let n=await this.collection.findOneAndUpdate(e,{$set:o});if(!n.ok)throw new Error("findOneAndUpdate returned not OK");return n.value}static async deleteMany(e){await this.collection.deleteMany(e)}};function O(t,e,o){class a extends b{constructor(r={}){super(t,e,r,o)}}let n=setInterval(function(){d.on&&(clearInterval(n),a.collection=d.db.collection(t))},100);return a.schema=e,a.methods=o,a}0&&(module.exports={MongoSteel,Schema,model,toUrl});

@@ -1,2 +0,2 @@

var u=class extends Error{constructor(e){super("This document is not valid!");Object.setPrototypeOf(this,u.prototype),this.obj=e}},f=class{constructor(e){function i(n){if(typeof n=="string")return n||(n="string"),{type:n,required:!0};if(Array.isArray(n))return n.length==2?{type:["string",i(n[1])],required:!0}:{type:[i(n[0])],required:!0};if(typeof n!="object")throw new Error("Unrecognised schema type!");return Object.keys(n).includes("type")&&Object.keys(n).includes("required")?(typeof n.type=="object"&&(n.type=i(n.type)),n):r(n)}function r(n){let l={};if(Array.isArray(n))throw new Error("Schema can't be an array!");if(typeof n!="object")throw new Error("Unrecognised schema type!");return Object.keys(n).forEach(o=>{l[o]=i(n[o])}),l}this.schema=r(e)}validate(e,i={}){if(typeof e!="object"||Array.isArray(e))return{valid:!1,reason:"majorBadType"};function r(o,a,t){switch(o.type){case"boolean":return typeof a!="boolean"?{valid:!1,reason:"badType",badKey:t}:!1;case"number":return typeof a!="number"?{valid:!1,reason:"badType",badKey:t}:!1;case"string":return typeof a!="string"?{valid:!1,reason:"badType",badKey:t}:o.pattern&&!o.pattern?.test(a)?{valid:!1,reason:"badType",badKey:t}:!1;case"mixed":return!1;default:return console.warn(`Unknown type for ${t}! The schema says ${o.type}`),!1}}let n="";function l(o,a){if(Object.keys(o).includes("type")&&Object.keys(o).includes("required")){let t=r(o,a,n);if(t)return t}else for(let t in o)if(typeof a=="object"&&!Array.isArray(a)&&!Object.keys(a).includes(t)){if(o[t].required&&!i.ignoreRequired)return{valid:!1,reason:"required",badKey:t};o[t].default&&!i.ignoreDefault&&(typeof o[t].default=="function"?e[t]=o[t].default():e[t]=o[t].default);continue}else if(Array.isArray(o[t].type)){if(o[t].type.length==2){if(typeof a[t]!="object"||Array.isArray(a[t]))return{valid:!1,reason:"badType",badKey:t};for(let c in a[t]){let p=l(o[t].type[1],a[t][c]);if(!p.valid)return p}}if(!Array.isArray(a[t]))return{valid:!1,reason:"badType",badKey:t};n=t,a[t].forEach(c=>{let p=l(o[t].type[0],c);if(!p.valid)return p})}else if(typeof o[t].type=="object"){let c=l(o[t].type,a[t]);if(!c.valid)return c}else{let c=r(o[t],a[t],t);if(c)return c}return{valid:!0,res:e}}return l(this.schema,e)}};import{MongoClient as m}from"mongodb";function h(d){return["dbName","location","password","user"].forEach(e=>{if(!Object.keys(d).includes(e))throw Error(`${e} is required in the options!`)}),d.dbOpts||(d.dbOpts={}),`mongodb://${encodeURI(d.user)}:${encodeURI(d.password)}@${encodeURI(d.location)}/${d.dbName}${Object.keys(d.dbOpts).length==0?"":"?"}${Object.keys(d.dbOpts).map((e,i)=>`${i==0?"":"&"}${encodeURI(`${e}=${(d.dbOpts??{})[e]}`)}`).join("")}`}var s={on:!1,models:{},opts:{}},y=class{static async connect(e,i,r){if(s.on){if(e)throw new Error(`I already have a connection to ${s.url}!`);return s.db}if(!e)throw new Error("I have nothing to connect to!");let n=typeof e=="string"?encodeURI(e):h(e),l=await m.connect(n,Object.assign({useNewUrlParser:!0,useUnifiedTopology:!0},i)),o=l.db(),a=Object.assign({},r);return s={on:!0,db:o,client:l,url:n,opts:a,models:s.models},o}static async disconnect(){s&&(await s.client?.close(),s={on:!1,client:void 0,db:void 0,url:void 0,models:s.models,opts:s.opts})}};var g=class{constructor(e,i,r,n){let l=i.validate(r);if(!l.valid&&!s.opts.noVerification)throw new u(l);this.doc=l.valid?l.res:r,this.schema=i,this.saved=!1,this.oldId="",this.methods=n;let o=setInterval(function(){s.on&&(clearInterval(o),this.collection=s.db.collection(e))},100)}async save(){!s.opts.noIdDetection&&this.saved&&this.oldId==this.doc._id&&(console.warn(`The _id ${this.doc._id} has already been saved once, overriding it with a new id...
To avoid this, use mongoSteel option { noIdDetection:true }`),delete this.doc._id);let e=await this.collection.insertOne(this.doc);if(!e.insertedId)throw Error("Not inserted");if(!s.opts.noDocsUpdate){let i=await this.collection.findOne({_id:e.insertedId});if(!i)throw Error("Weird");this.doc=i}return this.saved=!0,this.oldId=e.insertedId,this.doc}static async find(e){return await this.collection.find(e).toArray()}static async findOne(e){return await this.collection.findOne(e)}static async findOneAndDelete(e){let i=await this.collection.findOneAndDelete(e);if(!i.ok)throw new Error("findOneAndDelete returned not OK");return i.value}static async findOneAndReplace(e,i){let r=this.schema.validate(i);if(!r.valid)throw new u(r);i=r.res;let n=await this.collection.findOneAndReplace(e,i);if(!n.ok)throw new Error("findOneAndReplace returned not OK");return n.value}static async findOneAndUpdate(e,i){let r=this.schema.validate(i,{ignoreDefault:!0,ignoreRequired:!0});if(!r.valid)throw new u(r);let n=await this.collection.findOneAndUpdate(e,{$set:i});if(!n.ok)throw new Error("findOneAndUpdate returned not OK");return n.value}static async deleteMany(e){await this.collection.deleteMany(e)}};function w(d,e,i){class r extends g{constructor(o={}){super(d,e,o,i)}}let n=setInterval(function(){s.on&&(clearInterval(n),r.collection=s.db.collection(d))},100);return r.schema=e,r.methods=i,r}export{y as MongoSteel,f as Schema,w as model,h as toUrl};
var u=class extends Error{constructor(e){super("This document is not valid!");Object.setPrototypeOf(this,u.prototype),this.obj=e}},f=class{constructor(e){function o(n){if(typeof n=="string")return n||(n="string"),{type:n,required:!0};if(Array.isArray(n))return n.length==2?{type:["string",o(n[1])],required:!0}:{type:[o(n[0])],required:!0};if(typeof n!="object")throw new Error("Unrecognised schema type!");return Object.keys(n).includes("type")&&Object.keys(n).includes("required")?(typeof n.type=="object"&&(n.type=o(n.type)),n):r(n)}function r(n){let l={};if(Array.isArray(n))throw new Error("Schema can't be an array!");if(typeof n!="object")throw new Error("Unrecognised schema type!");return Object.keys(n).forEach(i=>{l[i]=o(n[i])}),l}this.schema=r(e)}validate(e,o={}){if(typeof e!="object"||Array.isArray(e))return{valid:!1,reason:"majorBadType"};function r(i,a,t){switch(i.type){case"boolean":return typeof a!="boolean"?{valid:!1,reason:"badType",badKey:t}:!1;case"number":return typeof a!="number"?{valid:!1,reason:"badType",badKey:t}:!1;case"string":return typeof a!="string"?{valid:!1,reason:"badType",badKey:t}:i.pattern&&!i.pattern?.test(a)?{valid:!1,reason:"badType",badKey:t}:!1;case"mixed":return!1;default:return!1}}let n="";function l(i,a){if(Object.keys(i).includes("type")&&Object.keys(i).includes("required")){let t=r(i,a,n);if(t)return t}else for(let t in i)if(typeof a=="object"&&!Array.isArray(a)&&!Object.keys(a).includes(t)){if(i[t].required&&!o.ignoreRequired)return{valid:!1,reason:"required",badKey:t};i[t].default&&!o.ignoreDefault&&(typeof i[t].default=="function"?e[t]=i[t].default():e[t]=i[t].default)}else if(Array.isArray(i[t].type)){if(i[t].type.length==2){if(Array.isArray(a[t]))return{valid:!1,reason:"badType",badKey:t};for(let c in a[t]){let p=l(i[t].type[1],a[t][c]);if(!p.valid)return p}}if(!Array.isArray(a[t]))return{valid:!1,reason:"badType",badKey:t};n=t,a[t].forEach(c=>{let p=l(i[t].type[0],c);if(!p.valid)return p})}else if(typeof i[t].type=="object"){let c=l(i[t].type,a[t]);if(!c.valid)return c}else{let c=r(i[t],a[t],t);if(c)return c}return{valid:!0,res:e}}return l(this.schema,e)}};import{MongoClient as m}from"mongodb";function h(d){return["dbName","location","password","user"].forEach(e=>{if(!Object.keys(d).includes(e))throw Error(`${e} is required in the options!`)}),d.dbOpts||(d.dbOpts={}),`mongodb://${encodeURI(d.user)}:${encodeURI(d.password)}@${encodeURI(d.location)}/${d.dbName}${Object.keys(d.dbOpts).length==0?"":"?"}${Object.keys(d.dbOpts).map((e,o)=>`${o==0?"":"&"}${encodeURI(`${e}=${(d.dbOpts??{})[e]}`)}`).join("")}`}var s={on:!1,models:{},opts:{}},y=class{static async connect(e,o,r){if(s.on){if(e)throw new Error(`I already have a connection to ${s.url}!`);return s.db}if(!e)throw new Error("I have nothing to connect to!");let n=typeof e=="string"?encodeURI(e):h(e),l=await m.connect(n,Object.assign({useNewUrlParser:!0,useUnifiedTopology:!0},o)),i=l.db(),a=Object.assign({},r);return s={on:!0,db:i,client:l,url:n,opts:a,models:s.models},i}static async disconnect(){s&&(await s.client?.close(),s={on:!1,client:void 0,db:void 0,url:void 0,models:s.models,opts:s.opts})}};var g=class{constructor(e,o,r,n){let l=o.validate(r);if(!l.valid&&!s.opts.noVerification)throw new u(l);this.doc=l.valid?l.res:r,this.schema=o,this.saved=!1,this.oldId="",this.methods=n;let i=setInterval(function(){s.on&&(clearInterval(i),this.collection=s.db.collection(e))},100)}async save(){!s.opts.noIdDetection&&this.saved&&this.oldId==this.doc._id&&(console.warn(`The _id ${this.doc._id} has already been saved once, overriding it with a new id...
To avoid this, use mongoSteel option { noIdDetection:true }`),delete this.doc._id);let e=await this.collection.insertOne(this.doc);if(!e.insertedId)throw Error("Not inserted");if(!s.opts.noDocsUpdate){let o=await this.collection.findOne({_id:e.insertedId});if(!o)throw Error("Weird");this.doc=o}return this.saved=!0,this.oldId=e.insertedId,this.doc}static async find(e){return await this.collection.find(e).toArray()}static async findOne(e){return await this.collection.findOne(e)}static async findOneAndDelete(e){let o=await this.collection.findOneAndDelete(e);if(!o.ok)throw new Error("findOneAndDelete returned not OK");return o.value}static async findOneAndReplace(e,o){let r=this.schema.validate(o);if(!r.valid)throw new u(r);o=r.res;let n=await this.collection.findOneAndReplace(e,o);if(!n.ok)throw new Error("findOneAndReplace returned not OK");return n.value}static async findOneAndUpdate(e,o){let r=this.schema.validate(o,{ignoreDefault:!0,ignoreRequired:!0});if(!r.valid)throw new u(r);let n=await this.collection.findOneAndUpdate(e,{$set:o});if(!n.ok)throw new Error("findOneAndUpdate returned not OK");return n.value}static async deleteMany(e){await this.collection.deleteMany(e)}};function w(d,e,o){class r extends g{constructor(i={}){super(d,e,i,o)}}let n=setInterval(function(){s.on&&(clearInterval(n),r.collection=s.db.collection(d))},100);return r.schema=e,r.methods=o,r}export{y as MongoSteel,f as Schema,w as model,h as toUrl};
{
"name": "mongosteel",
"version": "1.3.5",
"version": "1.3.6",
"description": "A solid ODM for MongoDB",

@@ -20,4 +20,5 @@ "main": "dist/cjs/index",

"clean": "rm -rf dist docs/dist tmpTypes",
"minify:types": "node scripts/typeMinify",
"build:docs": "./node_modules/.bin/typedoc",
"build": "npm run clean && npm run build:js && npm run build:types && npm run build:docs",
"build": "npm run clean && npm run build:js && npm run build:types && npm run minify:types && npm run build:docs",
"prepublishOnly": "npm run build"

@@ -24,0 +25,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc