Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@plt4rm/odm
Advanced tools
Readme
plt4rm's ODM (Object Document Mapper) is built for NodeJS and provides transparent persistence for JavaScript objects to MongoDB database.
Supports schemas with multi-level inheritance. Also supports interception on operations (create, read, update and delete).
npm install --save @plt4rm/odm
const {ODM} = require("@plt4rm/odm");
const odm = new ODM();
const config = {
"host": "localhost",
"port": "27017",
"database": "collection-service",
"dialect": "mongodb",
};
odm.connect(config).then(() => {
console.log('connection success');
odm.databaseExists().then(() => {
console.log('db exists');
odm.closeConnection();
}, () => {
console.log("db does not exists");
odm.closeConnection();
});
}, (err) => {
console.log('connection failed');
odm.closeConnection();
});
// after establishing connection
odm.addInterceptor({
getName: function () {
return "my-intercept";
},
intercept: (collectionName, operation, when, payload) => {
return new Promise((resolve, reject) => {
if (collectionName === 'student') {
if (operation === 'CREATE') {
console.log("[collectionName=" + collectionName + ", operation=" + operation + ", when=" + when + "]");
if (when === "BEFORE") {
for (let record of payload.records) {
console.log("computed field updated for :: " + record.get('name'));
record.set("computed", record.get("name") + " +++ computed");
}
}
}
if (operation === 'READ') {
console.log("[collectionName=" + collectionName + ", operation=" + operation + ", when=" + when + "]");
if (when === "AFTER") {
for (let record of payload.records)
console.log(JSON.stringify(record.toObject(), null, 4));
}
}
}
resolve(payload);
});
}
});
odm.defineCollection({
name: 'student',
fields: [{
name: 'name',
type: 'string'
}, {
name: 'computed',
type: 'string'
}]
});
let studentCollection = odm.collection("student");
let s = studentCollection.createNewRecord();
s.set("name", "John " + new Date().toISOString());
s.insert().then(function () {
studentCollection.find().toArray().then(function (students) {
odm.closeConnection();
});
});
// after establishing connection
odm.addFieldType({
getDataType: function () {
return new StringDataType()
},
getType: function () {
return "email"
},
async validateValue(schema: Schema, field: Field, record: any, context: any) {
const pattern = "(.+)@(.+){2,}\\.(.+){2,}";
if (!new RegExp(pattern).test(record[field.getName()]))
throw new Error("Not a valid email");
},
validateDefinition: function (fieldDefinition: any) {
return !!fieldDefinition.name
},
getValueIntercept(schema: Schema, field: Field, record: any, context: any): any {
return record[field.getName()];
},
setValueIntercept(schema: Schema, field: Field, newValue: any, record: any, context: any): any {
return newValue;
},
setODM() {}
});
odm.defineCollection({
name: 'student',
fields: [{
name: 'name',
type: 'string'
}, {
name: 'email',
type: 'email'
}, {
name: 'dob',
type: 'date'
}]
});
let studentCollection = odm.collection("student");
let s = studentCollection.createNewRecord();
s.set("name", "John");
s.set("email", "test@example.com");
s.set("dob", new Date());
s.insert().then(function () {
console.log("Student created");
odm.closeConnection();
}, (err) => {
console.log(err);
odm.closeConnection();
});
Check the examples >> here <<
FAQs
PLT4RM's ODM (Object Document Mapper) is built for NodeJS and provides transparent persistence for JavaScript objects to MongoDB database
We found that @plt4rm/odm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.