/** * `@koresar/jsmql/mongoose` — register jsmql with a mongoose module so the * standard `Model.find / updateOne / aggregate / …` static methods accept * jsmql source directly, alongside the regular MQL-JSON forms. * * const mongoose = require("mongoose"); * require("@koresar/jsmql/mongoose")(mongoose); * * User.find("$.age > 18"); // → Model.find({ age: { $gt: 18 } }) * User.aggregate(($) => { $match($.age > 18); $sort({ age: 1 }); }); * User.updateMany({}, ($) => $.score += 1); // → updateMany({}, [{ $set: { score: { $add: ["$score", 1] } } }]) * * ## Detection rule * * An argument is treated as jsmql input when it is a **string** or a * **function**. Plain objects and arrays pass through to the original * mongoose method unchanged, so existing MQL-JSON call sites (`Model.find({ * age: { $gt: 18 } })`, `Model.aggregate([{ $match: ... }])`) keep working * exactly as before. Users who want the template-tag form call `jsmql\`…\`` * themselves — the resulting object/array then takes the pass-through path. * * Modern mongoose (7+) returns Promises and no longer accepts callback * arguments, so the heuristic doesn't collide with `(err, result) => …` in * practice. * * ## One wrapper per method * * Each patched method is wrapped explicitly with its own named function. * The method signatures are stable across mongoose versions and small * enough that a per-method wrapper is easier to read and to debug than a * lookup table — a stack trace points straight at the method that did the * wrong thing, and the signature is right there next to the call. * * `findOneAndReplace` / `replaceOne` take a full *replacement document* at * argument 1, not an update spec — so we patch their filter slot only. * `findById` and `findByIdAndDelete` are id-only and aren't patched at all. * `Query.prototype.*` builder methods are out of scope today [DEF-020]; see docs/DEFERRED.md. */ import { type JsmqlInput } from "./index.ts"; /** * Register jsmql with a mongoose module. The function is the default export * of `@koresar/jsmql/mongoose`, so both call shapes work: * * const jsmqlMongoose = require("@koresar/jsmql/mongoose"); * jsmqlMongoose(mongoose); * * // or, ESM: * import jsmqlMongoose from "@koresar/jsmql/mongoose"; * jsmqlMongoose(mongoose); * * The `mongoose` parameter is typed `any` deliberately. We don't depend on * mongoose at compile time (no peer/dev dep, no `import "mongoose"`), so the * real `Mongoose` type isn't in scope here; the plugin treats the argument as * a duck-typed `{ Model: { find, …pre-patched statics… } }` and the per- * method wrappers below pass the rest through. Annotating each captured * original and wrapper parameter individually would add noise without * tightening the contract — every value just passes through to mongoose * untouched. */ export default function jsmqlMongoose(mongoose: any): void; declare module "mongoose" { interface Model { find(filter: JsmqlInput, projection?: any, options?: any): any; findOne(filter: JsmqlInput, projection?: any, options?: any): any; findOneAndUpdate(filter: JsmqlInput, update?: any, options?: any): any; findOneAndUpdate(filter: any, update: JsmqlInput, options?: any): any; findOneAndDelete(filter: JsmqlInput, options?: any): any; findOneAndReplace(filter: JsmqlInput, replacement?: any, options?: any): any; findByIdAndUpdate(id: any, update: JsmqlInput, options?: any): any; countDocuments(filter: JsmqlInput, options?: any): any; distinct(field: string, filter: JsmqlInput, options?: any): any; deleteOne(filter: JsmqlInput, options?: any): any; deleteMany(filter: JsmqlInput, options?: any): any; updateOne(filter: JsmqlInput, doc?: any, options?: any): any; updateOne(filter: any, doc: JsmqlInput, options?: any): any; updateMany(filter: JsmqlInput, update?: any, options?: any): any; updateMany(filter: any, update: JsmqlInput, options?: any): any; replaceOne(filter: JsmqlInput, doc?: any, options?: any): any; exists(filter: JsmqlInput, options?: any): any; aggregate(pipeline: JsmqlInput, options?: any): any; } } //# sourceMappingURL=mongoose.d.ts.map