
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
@lakshya004/cosmos-odm
Advanced tools
Azure Cosmos DB ODM/ORM with a Mongoose-like query builder and schema validation using Zod.
A lightweight Object Document Mapper (ODM) for Azure Cosmos DB with:
User.name
, User.age
) for type-safe queriesnpm i @lakshya004/cosmos-odm
import { DBConnection, Model, qb } from "cosmos-odm";
import z from "zod";
// 1️⃣ Connect to Cosmos DB
const db = new DBConnection(
"<COSMOS_DB_ENDPOINT>",
"<COSMOS_DB_KEY>"
);
// 2️⃣ Define a schema using Zod
const schema = z.object({
id: z.string().optional(),
name: z.string(),
age: z.number(),
});
// 3️⃣ Connect to a collection
const collection = await db.connectCollection("MyDatabase", "Users");
// 4️⃣ Create a Model
const User = new Model(schema, collection);
// ✅ Access schema-safe fields
console.log(User.name); // { name: "name" }
console.log(User.age); // { name: "age" }
// 5️⃣ Insert a document
const newUser = await User.insert({ name: "Alice", age: 28 });
// 6️⃣ Query with Query Builder + fields
const q = qb().and(
qb().eq(User.fields.name, "Alice"),
qb().gt(User.fields.age, 20)
);
const { resources } = await User.find({
filter: q,
fields: { id: User.fields.id, name: User.fields.name, age: User.fields.age },
limit: 10,
});
// 7️⃣ Update by ID
await User.updateById({ doc: { age: 29 }, id: newUser.id! });
// 8️⃣ Delete by ID
await User.deleteById(newUser.id!);
// Single insert
await User.insert({ name: "Lakshya", age: 20 });
// Bulk insert
await User.insertMany([
{ name: "Rakesh", age: 30 },
{ name: "Dhruv", age: 20 },
]);
// By ID
await User.findById("doc-id", "partition-key");
// With filter
const q = qb().ilike(User.fields.name, "lak");
const users = await User.find({ filter: q, limit: 5 });
// By ID
await User.updateById({
doc: { age: 25 },
id: "doc-id",
partitionKey: "partition-key"
});
// By filter
await User.update({
doc: { age: 37 },
filter: qb().eq(User.fields.name, "Makshya"),
});
// Partition key optional id same as doc-id
await User.deleteById("doc-id", "partition-key");
// Total count
const total = await User.count();
// Count with filter
const filtered = await User.count({
filter: qb().ilike(User.name, "lak"),
});
// Getting result in descending order of ages
const user_desc = await User.find({
orderBy: q.order(q.desc(User.fields.age)),
});
// Getting result in ascending order of ages
const user_asc = await User.find({
orderBy: q.order(q.asc(User.fields.age)),
});
Method | Description |
---|---|
connectDatabase(dbName) | Creates or connects to a database |
connectCollection(dbName, collectionName) | Creates or connects to a container |
A generic, schema-driven data access class.
Method | Description |
---|---|
insert(doc) | Insert a single document |
insertMany(docs) | Insert multiple documents |
findById(id, partitionKey?) | Find a document by ID |
find({ filter, fields, limit, offset }) | Query documents |
updateById({ doc, id, partitionKey }) | Update a document by ID |
update({ doc, filter }) | Update multiple documents by filter |
deleteById(id, partitionKey?) | Delete a document by ID |
count({ filter?, field? }) | Count documents |
Schema-aware, type-safe query builder.
Method | Example |
---|---|
.eq(field, value) | qb().eq(User.name, "John") |
.ne(field, value) | qb().ne(User.status, "inactive") |
.gt(field, value) | qb().gt(User.age, 30) |
.lt(field, value) | qb().lt(User.score, 100) |
.gte(field, value) | qb().gte(User.age, 18) |
.lte(field, value) | qb().lte(User.age, 65) |
.inArray(field, values) | qb().inArray(User.role, ["admin", "user"]) |
.ieq(field, value) | Case-insensitive equality |
.ilike(field, value) | Case-insensitive contains |
.and(...conditions) | Combine with AND |
.or(...conditions) | Combine with OR |
.desc(field) | Helper to add descending order |
.asc(field) | Helper to add ascending order |
.order(...fields) | To combine asc and desc functions values together |
.build() | Returns { query, params } |
MIT
FAQs
Azure Cosmos DB ODM/ORM with a Mongoose-like query builder and schema validation using Zod.
The npm package @lakshya004/cosmos-odm receives a total of 296 weekly downloads. As such, @lakshya004/cosmos-odm popularity was classified as not popular.
We found that @lakshya004/cosmos-odm demonstrated a healthy version release cadence and project activity because the last version was released less than 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
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.