@qson/express 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jarno Parviainen and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # QSON query string parser and middleware for Express.js
2
+
3
+ See [@qson/js](https://www.npmjs.com/package/@qson/js) for what QSON is.
4
+
5
+ Use either of the following that fits your project.
6
+
7
+ Example:
8
+
9
+ ```js
10
+ import express from "express";
11
+ import { qsonQueryParser } from "@qson/express";
12
+
13
+ const app = express();
14
+ // Replace default query string parser (result is available in request.query)
15
+ // Parse query string keys starting with "q_" as QSON and others as raw strings (this setting is optional)
16
+ app.set("query parser", qsonQueryParser({ isQSON: (key) => key.startsWith("q_") }));
17
+ ```
18
+
19
+ or:
20
+
21
+ ```js
22
+ import express from "express";
23
+ import { qsonMiddleware } from "@qson/express";
24
+
25
+ const app = express();
26
+ // Parse query string and make the result available in request.qson (request.query is untouched)
27
+ // Keys "_id" is parsed as raw string and others are parsed as QSON
28
+ app.use(qsonMiddleware({ isQSON: (key) => key !== "_id" }));
29
+ ```
30
+
31
+ ## API
32
+
33
+ `qsonQueryParser([options])`
34
+ - options\<ParseQueryStringOptions>
35
+
36
+ `qsonMiddleware([options])`
37
+ - options\<ParseQueryStringOptions>
38
+
39
+ `ParseQueryStringOptions`
40
+ - isQSON\<`(key:string) => boolean`> a callback that gets key as an argument and returns boolean. True for QSON fields. False for raw string fields. This applies only to query (root level) fields. (default: all fields are considered QSON)
41
+ - reviver\<function> A json api style reviver function. It is run for each QSON field in query (root) object but not for the query object itself.
42
+ - maxDepth\<number> Maximum nesting depth. Error is thrown if exceeded. (default: 10)
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.qsonQueryParser = exports.qsonMiddleware = void 0;
7
+ var qson_middleware_ts_1 = require("./qson-middleware.js");
8
+ Object.defineProperty(exports, "qsonMiddleware", { enumerable: true, get: function () { return __importDefault(qson_middleware_ts_1).default; } });
9
+ var qson_query_parser_ts_1 = require("./qson-query-parser.js");
10
+ Object.defineProperty(exports, "qsonQueryParser", { enumerable: true, get: function () { return __importDefault(qson_query_parser_ts_1).default; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,2DAAiE;AAAxD,qIAAA,OAAO,OAAkB;AAClC,+DAAoE;AAA3D,wIAAA,OAAO,OAAmB"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = qsonMiddleware;
4
+ const js_1 = require("@qson/js");
5
+ function qsonMiddleware(options = {}) {
6
+ function middleware(request, response, next) {
7
+ try {
8
+ request.qson = {};
9
+ const questionMarkIndex = request.originalUrl.indexOf("?");
10
+ if (questionMarkIndex === -1) {
11
+ next();
12
+ return;
13
+ }
14
+ const rawQuery = request.originalUrl.slice(questionMarkIndex + 1);
15
+ request.qson = (0, js_1.parseQueryString)(rawQuery, options);
16
+ next();
17
+ }
18
+ catch (error) {
19
+ next(error);
20
+ }
21
+ }
22
+ return middleware;
23
+ }
24
+ //# sourceMappingURL=qson-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qson-middleware.js","sourceRoot":"","sources":["../../src/qson-middleware.ts"],"names":[],"mappings":";;AAGA,iCAmBC;AArBD,iCAAqE;AAErE,SAAwB,cAAc,CAAC,UAAkC,EAAE;IAEvE,SAAS,UAAU,CAAC,OAAe,EAAE,QAAiB,EAAE,IAAQ;QAC5D,IAAI,CAAC;YACD,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC;YAClB,MAAM,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAC3D,IAAI,iBAAiB,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,IAAI,EAAE,CAAC;gBACP,OAAO;YACX,CAAC;YACD,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC;YAClE,OAAO,CAAC,IAAI,GAAG,IAAA,qBAAgB,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACnD,IAAI,EAAE,CAAC;QACX,CAAC;QAAC,OAAO,KAAS,EAAE,CAAC;YACjB,IAAI,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC;IACL,CAAC;IAED,OAAO,UAAU,CAAC;AACtB,CAAC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = qsonQueryParser;
4
+ const js_1 = require("@qson/js");
5
+ function qsonQueryParser(options = {}) {
6
+ function queryParser(rawQuery) {
7
+ const query = (0, js_1.parseQueryString)(rawQuery, options);
8
+ return query;
9
+ }
10
+ return queryParser;
11
+ }
12
+ //# sourceMappingURL=qson-query-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qson-query-parser.js","sourceRoot":"","sources":["../../src/qson-query-parser.ts"],"names":[],"mappings":";;AAEA,kCAQC;AAVD,iCAAqE;AAErE,SAAwB,eAAe,CAAC,UAAkC,EAAE;IAExE,SAAS,WAAW,CAAC,QAAe;QAChC,MAAM,KAAK,GAAG,IAAA,qBAAgB,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAClD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,OAAO,WAAW,CAAC;AACvB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { default as qsonMiddleware } from "./qson-middleware.js";
2
+ export { default as qsonQueryParser } from "./qson-query-parser.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { parseQueryString } from "@qson/js";
2
+ export default function qsonMiddleware(options = {}) {
3
+ function middleware(request, response, next) {
4
+ try {
5
+ request.qson = {};
6
+ const questionMarkIndex = request.originalUrl.indexOf("?");
7
+ if (questionMarkIndex === -1) {
8
+ next();
9
+ return;
10
+ }
11
+ const rawQuery = request.originalUrl.slice(questionMarkIndex + 1);
12
+ request.qson = parseQueryString(rawQuery, options);
13
+ next();
14
+ }
15
+ catch (error) {
16
+ next(error);
17
+ }
18
+ }
19
+ return middleware;
20
+ }
21
+ //# sourceMappingURL=qson-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qson-middleware.js","sourceRoot":"","sources":["../../src/qson-middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAA2B,MAAM,UAAU,CAAC;AAErE,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,UAAkC,EAAE;IAEvE,SAAS,UAAU,CAAC,OAAe,EAAE,QAAiB,EAAE,IAAQ;QAC5D,IAAI,CAAC;YACD,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC;YAClB,MAAM,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAC3D,IAAI,iBAAiB,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,IAAI,EAAE,CAAC;gBACP,OAAO;YACX,CAAC;YACD,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC;YAClE,OAAO,CAAC,IAAI,GAAG,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACnD,IAAI,EAAE,CAAC;QACX,CAAC;QAAC,OAAO,KAAS,EAAE,CAAC;YACjB,IAAI,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC;IACL,CAAC;IAED,OAAO,UAAU,CAAC;AACtB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { parseQueryString } from "@qson/js";
2
+ export default function qsonQueryParser(options = {}) {
3
+ function queryParser(rawQuery) {
4
+ const query = parseQueryString(rawQuery, options);
5
+ return query;
6
+ }
7
+ return queryParser;
8
+ }
9
+ //# sourceMappingURL=qson-query-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qson-query-parser.js","sourceRoot":"","sources":["../../src/qson-query-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA2B,MAAM,UAAU,CAAC;AAErE,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,UAAkC,EAAE;IAExE,SAAS,WAAW,CAAC,QAAe;QAChC,MAAM,KAAK,GAAG,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAClD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,OAAO,WAAW,CAAC;AACvB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { default as qsonMiddleware } from "./qson-middleware.ts";
2
+ export { default as qsonQueryParser } from "./qson-query-parser.ts";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { Request, Response } from "express";
2
+ import { ParseQueryStringOptions } from "@qson/js";
3
+ export default function qsonMiddleware(options?: ParseQueryStringOptions): (request: Request, response: Response, next: any) => void;
4
+ declare global {
5
+ namespace Express {
6
+ interface Request {
7
+ qson?: {
8
+ [key: string]: any;
9
+ };
10
+ }
11
+ }
12
+ }
13
+ //# sourceMappingURL=qson-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qson-middleware.d.ts","sourceRoot":"","sources":["../../src/qson-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAoB,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAErE,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,OAAO,GAAC,uBAA4B,aAE3C,OAAO,YAAW,QAAQ,QAAO,GAAG,UAiBnE;AAED,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC;QACd,UAAU,OAAO;YACb,IAAI,CAAC,EAAE;gBAAE,CAAC,GAAG,EAAC,MAAM,GAAE,GAAG,CAAA;aAAE,CAAC;SAC/B;KACJ;CACJ"}
@@ -0,0 +1,7 @@
1
+ import { ParseQueryStringOptions } from "@qson/js";
2
+ export default function qsonQueryParser(options?: ParseQueryStringOptions): (rawQuery: string) => Obj;
3
+ type Obj = {
4
+ [key: string]: any;
5
+ };
6
+ export {};
7
+ //# sourceMappingURL=qson-query-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qson-query-parser.d.ts","sourceRoot":"","sources":["../../src/qson-query-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAErE,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,OAAO,GAAC,uBAA4B,cAE1C,MAAM,KAAE,GAAG,CAM5C;AAED,KAAK,GAAG,GAAG;IAAE,CAAC,GAAG,EAAC,MAAM,GAAE,GAAG,CAAA;CAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@qson/express",
3
+ "version": "0.2.0",
4
+ "description": "",
5
+ "author": "Jarno Parviainen",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/Daaler/qson.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/Daaler/qson/issues"
14
+ },
15
+ "homepage": "https://github.com/Daaler/qson",
16
+ "keywords": [],
17
+ "type": "module",
18
+ "main": "./dist/esm/index.js",
19
+ "types": "./dist/types/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "import": "./dist/esm/index.js",
23
+ "require": "./dist/cjs/index.js",
24
+ "types": "./dist/types/index.d.ts"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "dependencies": {
31
+ "@qson/js": "^0.2.2"
32
+ },
33
+ "peerDependencies": {
34
+ "express": "^5.0.0"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "express": {
38
+ "optional": true
39
+ }
40
+ },
41
+ "devDependencies": {
42
+ "@types/express": "^5.0.6",
43
+ "express": "^5.2.1",
44
+ "@qson/dev": "0.1.0"
45
+ },
46
+ "scripts": {
47
+ "test": "pnpm run test:types && node --test --import @qson/dev/test-setup \"**/*.test.js\"",
48
+ "test:types": "tsc --noEmit",
49
+ "test1": "node --test --import @qson/dev/test-setup",
50
+ "lint": "pnpm exec eslint",
51
+ "build": "pnpm exec qson-build",
52
+ "clean": "pnpm exec qson-clean",
53
+ "release": "pnpm exec qson-release --no-branch-check --no-git-checks"
54
+ }
55
+ }