
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
一个用于构建 DSL(Domain Specific Language)查询语句的 JavaScript 库,提供链式 API 来构建复杂的查询条件、排序和分页。
npm install dslquery
import { Query, and, equals, greaterThan, asc } from 'dslquery';
// 创建一个查询
const query = new Query()
.withLimit(20)
.withSkip(0)
.withFilter(and(
equals("status", "active"),
greaterThan("age", 18)
))
.withSort(asc("name"));
// 获取查询参数
console.log(query.limit); // 20
console.log(query.skip); // 0
console.log(query.filter); // (and(status eq active)(age gt 18))
console.log(query.sort); // name asc
用于管理查询的主类,支持分页、过滤和排序。
withLimit(number) - 设置每页数量(默认:10)withSkip(number) - 设置跳过的记录数withFilter(expression) - 设置过滤条件withSort(sort) - 设置排序规则goto(pageNumber) - 跳转到指定页码gotoOffset(offset) - 相对当前页偏移onTotal(total) - 设置总记录数maxPage - 获取最大页数limit - 获取每页数量skip - 获取跳过的记录数filter - 获取构建后的过滤条件字符串sort - 获取构建后的排序字符串import { equals, notEquals, greaterThan, greaterThanOrEquals,
lessThan, lessThanOrEquals } from 'dslquery';
equals("name", "张三") // (name eq 张三)
notEquals("status", "deleted") // (status ne deleted)
greaterThan("age", 18) // (age gt 18)
greaterThanOrEquals("score", 60) // (score ge 60)
lessThan("price", 100) // (price lt 100)
lessThanOrEquals("count", 10) // (count le 10)
import { startsWith, endsWith, contains } from 'dslquery';
startsWith("name", "张") // (name sw 张)
endsWith("email", ".com") // (email ew .com)
contains("title", "测试") // (title ct 测试)
import { isIn, notIn, between } from 'dslquery';
isIn("status", ["active", "pending"]) // (name in %5B"active","pending"%5D)
notIn("role", ["admin", "super"]) // (role ni %5B"admin","super"%5D)
between("age", 18, 65) // (age bt 18,65)
import { isnull, notnull } from 'dslquery';
isnull("deletedAt") // (deletedAt isn)
notnull("email") // (email inn)
import { and, or, equals, greaterThan } from 'dslquery';
// AND 组合
and(
equals("status", "active"),
greaterThan("age", 18)
)
// 输出: (and(status eq active)(age gt 18))
// OR 组合
or(
equals("role", "admin"),
equals("role", "moderator")
)
// 输出: (or(role eq admin)(role eq moderator))
// 嵌套组合
and(
equals("status", "active"),
or(
equals("role", "admin"),
equals("role", "moderator")
)
)
// 输出: (and(status eq active)(or(role eq admin)(role eq moderator)))
import { asc, desc } from 'dslquery';
// 单字段排序
asc("name") // name asc
desc("createdAt") // createdAt desc
// 多字段排序
asc("name").desc("age") // name asc,age desc
desc("priority").asc("name") // priority desc,name asc
import { Query, and, equals, greaterThan, asc } from 'dslquery';
const query = new Query()
.withLimit(10)
.withFilter(and(
equals("status", "active"),
greaterThan("age", 18)
))
.withSort(asc("name"));
console.log(query.filter); // (and(status eq active)(age gt 18))
console.log(query.sort); // name asc
const query = new Query()
.withLimit(20);
// 跳转到第 5 页
query.goto(5);
console.log(query.skip); // 80
// 向前翻一页
query.gotoOffset(-1);
console.log(query.skip); // 60
// 设置总记录数并获取最大页数
query.onTotal(219);
console.log(query.maxPage); // 11
import { Query, and, or, equals, greaterThan, lessThan,
contains, isIn, desc } from 'dslquery';
const query = new Query()
.withLimit(50)
.withFilter(and(
equals("status", "active"),
or(
and(
greaterThan("age", 18),
lessThan("age", 65)
),
equals("vip", true)
),
contains("name", "张"),
isIn("city", ["北京", "上海", "深圳"])
))
.withSort(desc("createdAt").asc("name"));
console.log(query.filter);
// (and(status eq active)(or(and(age gt 18)(age lt 65))(vip eq true))(name ct 张)(city in %5B"北京","上海","深圳"%5D))
console.log(query.sort);
// createdAt desc,name asc
库会自动对特殊字符进行 URL 编码:
import { equals, isIn } from 'dslquery';
equals("name", "test()") // (name eq test%28%29)
isIn("tags", ["a+b", "c&d"]) // (tags in %5B"a%2Bb","c%26d"%5D)
# 安装依赖
npm install
# 运行测试
npm test
# 构建
npm run build
项目使用 Vitest 进行测试,测试覆盖了所有主要功能:
运行测试:
npm test
ISC
欢迎提交 Issue 和 Pull Request!
FAQs
一个用于构建 DSL(Domain Specific Language)查询语句的 JavaScript 库,提供链式 API 来构建复杂的查询条件、排序和分页。
The npm package dslquery receives a total of 28 weekly downloads. As such, dslquery popularity was classified as not popular.
We found that dslquery 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
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.