rsql-query-builder-mongodb
Advanced tools
Comparing version
@@ -6,2 +6,8 @@ import { RSQLBuilderBase } from 'rsql-query-builder'; | ||
type ComparisonOperator = 'regex' | 'notRegex' | 'exists'; | ||
declare enum MongoRegexOptions { | ||
CASE_INSENSITIVE = "i",// Ignore case | ||
MULTILINE = "m",// Multiline mode | ||
DOTALL = "s",// Dot matches newline | ||
EXTENDED = "x" | ||
} | ||
/** RSQL Query Builder for MongoDB. | ||
@@ -22,3 +28,3 @@ * | ||
*/ | ||
regex(selector: TSelector, regex: string, options?: string): RSQLBuilderMongoDB<TSelector>; | ||
regex(selector: TSelector, regex: string, options?: string | Array<MongoRegexOptions>): RSQLBuilderMongoDB<TSelector>; | ||
/** Add a NOT REGEX condition. | ||
@@ -33,3 +39,3 @@ * | ||
*/ | ||
notRegex(selector: TSelector, regex: string, options?: string): RSQLBuilderMongoDB<TSelector>; | ||
notRegex(selector: TSelector, regex: string, options?: string | Array<MongoRegexOptions>): RSQLBuilderMongoDB<TSelector>; | ||
/** Add a LIKE condition. | ||
@@ -44,3 +50,3 @@ * | ||
*/ | ||
like(selector: TSelector, regex: string, options?: string): RSQLBuilderMongoDB<TSelector>; | ||
like(selector: TSelector, regex: string, options?: string | Array<MongoRegexOptions>): RSQLBuilderMongoDB<TSelector>; | ||
/** Add a NOT LIKE condition. | ||
@@ -55,3 +61,3 @@ * | ||
*/ | ||
notLike(selector: TSelector, regex: string, options?: string): RSQLBuilderMongoDB<TSelector>; | ||
notLike(selector: TSelector, regex: string, options?: string | Array<MongoRegexOptions>): RSQLBuilderMongoDB<TSelector>; | ||
/** Add a SELECTOR EXISTS condition. | ||
@@ -71,2 +77,2 @@ * | ||
export { RSQLBuilderMongoDB }; | ||
export { MongoRegexOptions, RSQLBuilderMongoDB }; |
@@ -1,2 +0,2 @@ | ||
"use strict";var RSQLBuilderMongoDB=(()=>{var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var S=(o,r)=>{for(var t in r)i(o,t,{get:r[t],enumerable:!0})},m=(o,r,t,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of c(r))!d.call(o,s)&&s!==t&&i(o,s,{get:()=>r[s],enumerable:!(e=g(r,s))||e.enumerable});return o};var q=o=>m(i({},"__esModule",{value:!0}),o);var L={};S(L,{RSQLBuilderMongoDB:()=>p});var O=class n{constructor(r={}){this.comparisonOperators={equal:{rsql:"=="},notEqual:{rsql:"!="},lessThan:{rsql:"=lt="},greaterThan:{rsql:"=gt="},lessThanOrEqual:{rsql:"=le="},greaterThanOrEqual:{rsql:"=ge="},in:{rsql:"=in=",isArray:!0},notIn:{rsql:"=out=",isArray:!0}},this.rsqlStr="",this.defaultLogicOperator="and",this.replaceExistingLogicOperator=!0,this.customComparisonOperators={},r.defaultLogicOperator&&(this.defaultLogicOperator=r.defaultLogicOperator),r.customComparisonOperators&&(this.customComparisonOperators=r.customComparisonOperators)}escapeString(r){let t=/[();,]/g;return r.replace(t,"\\$&")}valueToString(r){if(r===null)return"null";if(typeof r=="string")return'"'+this.escapeString(r)+'"';if(typeof r=="number")return r.toString();if(typeof r=="boolean")return r===!0?"true":"false";if(r instanceof Date)return r.toISOString();throw new Error("Unhandled value type")}ensureLogicOperator(r){this.rsqlStr.length!==0&&!this.rsqlStr.endsWith(";")&&!this.rsqlStr.endsWith(",")&&this.appendLogicOperator(r||this.defaultLogicOperator)}removeTrailingLogicOperator(){for(;this.rsqlStr.endsWith(";")||this.rsqlStr.endsWith(",");)this.rsqlStr=this.rsqlStr.slice(0,-1)}appendLogicOperator(r){switch(this.replaceExistingLogicOperator&&this.removeTrailingLogicOperator(),r){case"or":this.rsqlStr+=",";break;case"and":default:this.rsqlStr+=";";break}}addComparison(r,t,e){this.ensureLogicOperator();let s=this.customComparisonOperators[t]||this.comparisonOperators[t];if(!s)throw new Error(`Invalid comparison operator '${s}'`);if(s.isArray===!0){if(!Array.isArray(e))throw new Error(`Array comparison operator '${s}' requires an array value.`);let u=e.map(h=>this.valueToString(h));this.rsqlStr+=r+s.rsql+"("+u.join(",")+")"}else{if(Array.isArray(e))throw new Error(`Non-array comparison operator '${s}' does not support array values.`);this.rsqlStr+=r+s.rsql+this.valueToString(e)}return this}addLogicOperator(r){return this.appendLogicOperator(r),this}toString(){return this.rsqlStr}isEmpty(){return this.rsqlStr.length===0}reset(){return this.rsqlStr="",this}concat(r){return r.isEmpty()||(this.ensureLogicOperator(),this.rsqlStr+=r.toString()),this}merge(r,t){for(let e of r)this.ensureLogicOperator(t?.logicOperator),this.group(e);return this}and(){return this.appendLogicOperator("and"),this}or(){return this.appendLogicOperator("or"),this}group(r){return this.ensureLogicOperator(),this.rsqlStr+="("+r.toString()+")",this}equal(r,t){return this.addComparison(r,"equal",t)}notEqual(r,t){return this.addComparison(r,"notEqual",t)}lessThan(r,t){return this.addComparison(r,"lessThan",t)}lessThanOrEqual(r,t){return this.addComparison(r,"lessThanOrEqual",t)}greaterThan(r,t){return this.addComparison(r,"greaterThan",t)}greaterThanOrEqual(r,t){return this.addComparison(r,"greaterThanOrEqual",t)}in(r,t){return this.addComparison(r,"in",t)}notIn(r,t){return this.addComparison(r,"notIn",t)}static merge(r,t){return new n({defaultLogicOperator:t?.logicOperator}).merge(r.filter(e=>e!==void 0&&!e.isEmpty()))}},l=O;var a=class extends l{constructor(){super({customComparisonOperators:{regex:{rsql:"=regex="},notRegex:{rsql:"=notregex="},exists:{rsql:"=exists="}}})}regex(r,t,e){return super.addComparison(r,"regex",t),this}notRegex(r,t,e){return super.addComparison(r,"notRegex",t),this}like(r,t,e){return this.regex(r,t,e)}notLike(r,t,e){return this.notRegex(r,t,e)}exists(r){return super.addComparison(r,"exists",!0),this}notExists(r){return super.addComparison(r,"exists",!1),this}},p=a;return q(L);})(); | ||
"use strict";var RSQLBuilderMongoDB=(()=>{var a=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var O=(i,r)=>{for(var e in r)a(i,e,{get:r[e],enumerable:!0})},L=(i,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of m(r))!q.call(i,s)&&s!==e&&a(i,s,{get:()=>r[s],enumerable:!(t=S(r,s))||t.enumerable});return i};var T=i=>L(a({},"__esModule",{value:!0}),i);var y={};O(y,{MongoRegexOptions:()=>l,RSQLBuilderMongoDB:()=>g});var f=class p{constructor(r={}){this.comparisonOperators={equal:{rsql:"=="},notEqual:{rsql:"!="},lessThan:{rsql:"=lt="},greaterThan:{rsql:"=gt="},lessThanOrEqual:{rsql:"=le="},greaterThanOrEqual:{rsql:"=ge="},in:{rsql:"=in=",isArray:!0},notIn:{rsql:"=out=",isArray:!0}},this.rsqlStr="",this.defaultLogicOperator="and",this.replaceExistingLogicOperator=!0,this.customComparisonOperators={},r.defaultLogicOperator&&(this.defaultLogicOperator=r.defaultLogicOperator),r.customComparisonOperators&&(this.customComparisonOperators=r.customComparisonOperators)}escapeString(r){let e=/[();,]/g;return r.replace(e,"\\$&")}valueToString(r){if(r===null)return"null";if(typeof r=="string")return'"'+this.escapeString(r)+'"';if(typeof r=="number")return r.toString();if(typeof r=="boolean")return r===!0?"true":"false";if(r instanceof Date)return r.toISOString();throw new Error("Unhandled value type")}ensureLogicOperator(r){this.rsqlStr.length!==0&&!this.rsqlStr.endsWith(";")&&!this.rsqlStr.endsWith(",")&&this.appendLogicOperator(r||this.defaultLogicOperator)}removeTrailingLogicOperator(){for(;this.rsqlStr.endsWith(";")||this.rsqlStr.endsWith(",");)this.rsqlStr=this.rsqlStr.slice(0,-1)}appendLogicOperator(r){switch(this.replaceExistingLogicOperator&&this.removeTrailingLogicOperator(),r){case"or":this.rsqlStr+=",";break;case"and":default:this.rsqlStr+=";";break}}addComparison(r,e,t,s){this.ensureLogicOperator();let o=this.customComparisonOperators[e]||this.comparisonOperators[e];if(!o)throw new Error(`Invalid comparison operator '${o}'`);let u=s?"="+s:"";if(o.isArray===!0){if(!Array.isArray(t))throw new Error(`Array comparison operator '${o}' requires an array value.`);let c=t.map(d=>this.valueToString(d));this.rsqlStr+=r+o.rsql+"("+c.join(",")+")"+u}else{if(Array.isArray(t))throw new Error(`Non-array comparison operator '${o}' does not support array values.`);this.rsqlStr+=r+o.rsql+this.valueToString(t)+u}return this}addLogicOperator(r){return this.appendLogicOperator(r),this}toString(){return this.rsqlStr}isEmpty(){return this.rsqlStr.length===0}reset(){return this.rsqlStr="",this}concat(r){return r.isEmpty()||(this.ensureLogicOperator(),this.rsqlStr+=r.toString()),this}merge(r,e){for(let t of r)this.ensureLogicOperator(e?.logicOperator),this.group(t);return this}and(){return this.appendLogicOperator("and"),this}or(){return this.appendLogicOperator("or"),this}group(r){return this.ensureLogicOperator(),this.rsqlStr+="("+r.toString()+")",this}equal(r,e){return this.addComparison(r,"equal",e)}notEqual(r,e){return this.addComparison(r,"notEqual",e)}lessThan(r,e){return this.addComparison(r,"lessThan",e)}lessThanOrEqual(r,e){return this.addComparison(r,"lessThanOrEqual",e)}greaterThan(r,e){return this.addComparison(r,"greaterThan",e)}greaterThanOrEqual(r,e){return this.addComparison(r,"greaterThanOrEqual",e)}in(r,e){return this.addComparison(r,"in",e)}notIn(r,e){return this.addComparison(r,"notIn",e)}static merge(r,e){return new p({defaultLogicOperator:e?.logicOperator}).merge(r.filter(t=>t!==void 0&&!t.isEmpty()))}},h=f;var l=(s=>(s.CASE_INSENSITIVE="i",s.MULTILINE="m",s.DOTALL="s",s.EXTENDED="x",s))(l||{}),n=class extends h{constructor(){super({customComparisonOperators:{regex:{rsql:"=regex="},notRegex:{rsql:"=notregex="},exists:{rsql:"=exists="}}})}regex(r,e,t){return Array.isArray(t)&&(t=t.join("")),super.addComparison(r,"regex",e,t),this}notRegex(r,e,t){return Array.isArray(t)&&(t=t.join("")),super.addComparison(r,"notRegex",e,t),this}like(r,e,t){return Array.isArray(t)&&(t=t.join("")),this.regex(r,e,t)}notLike(r,e,t){return Array.isArray(t)&&(t=t.join("")),this.notRegex(r,e,t)}exists(r){return super.addComparison(r,"exists",!0),this}notExists(r){return super.addComparison(r,"exists",!1),this}},g=n;return T(y);})(); | ||
//# sourceMappingURL=index.global.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},S=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of g(e))!c.call(t,s)&&s!==r&&i(t,s,{get:()=>e[s],enumerable:!(o=p(e,s))||o.enumerable});return t};var a=t=>S(i({},"__esModule",{value:!0}),t);var d={};x(d,{RSQLBuilderMongoDB:()=>u});module.exports=a(d);var l=require("rsql-query-builder"),n=class extends l.RSQLBuilderBase{constructor(){super({customComparisonOperators:{regex:{rsql:"=regex="},notRegex:{rsql:"=notregex="},exists:{rsql:"=exists="}}})}regex(e,r,o){return super.addComparison(e,"regex",r),this}notRegex(e,r,o){return super.addComparison(e,"notRegex",r),this}like(e,r,o){return this.regex(e,r,o)}notLike(e,r,o){return this.notRegex(e,r,o)}exists(e){return super.addComparison(e,"exists",!0),this}notExists(e){return super.addComparison(e,"exists",!1),this}},u=n;0&&(module.exports={RSQLBuilderMongoDB}); | ||
"use strict";var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var c=(s,e)=>{for(var t in e)o(s,t,{get:e[t],enumerable:!0})},d=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of x(e))!S.call(s,i)&&i!==t&&o(s,i,{get:()=>e[i],enumerable:!(r=g(e,i))||r.enumerable});return s};var T=s=>d(o({},"__esModule",{value:!0}),s);var p={};c(p,{MongoRegexOptions:()=>n,RSQLBuilderMongoDB:()=>u});module.exports=T(p);var a=require("rsql-query-builder"),n=(i=>(i.CASE_INSENSITIVE="i",i.MULTILINE="m",i.DOTALL="s",i.EXTENDED="x",i))(n||{}),l=class extends a.RSQLBuilderBase{constructor(){super({customComparisonOperators:{regex:{rsql:"=regex="},notRegex:{rsql:"=notregex="},exists:{rsql:"=exists="}}})}regex(e,t,r){return Array.isArray(r)&&(r=r.join("")),super.addComparison(e,"regex",t,r),this}notRegex(e,t,r){return Array.isArray(r)&&(r=r.join("")),super.addComparison(e,"notRegex",t,r),this}like(e,t,r){return Array.isArray(r)&&(r=r.join("")),this.regex(e,t,r)}notLike(e,t,r){return Array.isArray(r)&&(r=r.join("")),this.notRegex(e,t,r)}exists(e){return super.addComparison(e,"exists",!0),this}notExists(e){return super.addComparison(e,"exists",!1),this}},u=l;0&&(module.exports={MongoRegexOptions,RSQLBuilderMongoDB}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "rsql-query-builder-mongodb", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Library for building RSQL query strings for MongoDB.", | ||
@@ -12,3 +12,3 @@ "main": "dist/index.js", | ||
"build": "npm run clean && tsup", | ||
"publish": "npm run test && npm run build && npm publish", | ||
"publish-library": "npm run test && npm run build && npm publish", | ||
"test": "vitest run" | ||
@@ -15,0 +15,0 @@ }, |
@@ -5,6 +5,2 @@ # rsql-query-builder-mongodb | ||
# rsql-query-builder | ||
Library for building RSQL query strings in TypeScript and JavaScript. | ||
[![NPM Version][npm-version-image]][npm-url] | ||
@@ -11,0 +7,0 @@ [![NPM License][npm-license-image]][npm-url] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
49510
11.7%96
11.63%24
-14.29%