@queryweave/node 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +14 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 QueryWeave 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,14 @@
|
|
|
1
|
+
# `@queryweave/node`
|
|
2
|
+
|
|
3
|
+
Node.js request adapters that bridge into `@queryweave/server`.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { readNodeQuery, resolveNodeRequestUrl } from "@queryweave/node";
|
|
7
|
+
|
|
8
|
+
readNodeQuery(request, productFilters);
|
|
9
|
+
resolveNodeRequestUrl(request, { trustForwardedHeaders: true });
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Decoding lives in one place: this package only translates Node primitives. Forwarded headers are
|
|
13
|
+
ignored unless you opt in. No Express, Fastify, NestJS, Hono, or frontend framework dependency is
|
|
14
|
+
included.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IncomingMessage } from "node:http";
|
|
2
|
+
import { DecodeResult, QueryModel, QueryModelValues, QueryParamDefinitions, QuerySource } from "@queryweave/core";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Node.js request adapters.
|
|
6
|
+
*
|
|
7
|
+
* This package only bridges Node primitives into `@queryweave/server`; decoding stays in one
|
|
8
|
+
* place, and no HTTP framework is required.
|
|
9
|
+
*/
|
|
10
|
+
/** Options accepted by {@link resolveNodeRequestUrl}. */
|
|
11
|
+
interface ResolveNodeRequestUrlOptions {
|
|
12
|
+
/** Explicit authority, overriding request headers. */
|
|
13
|
+
readonly host?: string | undefined;
|
|
14
|
+
/** Explicit scheme without `:`, overriding request headers. */
|
|
15
|
+
readonly protocol?: string | undefined;
|
|
16
|
+
/** Read `x-forwarded-host` and `x-forwarded-proto` when present. Off by default. */
|
|
17
|
+
readonly trustForwardedHeaders?: boolean | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** A read-only source backed by a Node request. */
|
|
20
|
+
interface NodeRequestQuerySource extends QuerySource {
|
|
21
|
+
readonly request: IncomingMessage;
|
|
22
|
+
}
|
|
23
|
+
/** Resolve the absolute URL a Node request was made against. */
|
|
24
|
+
declare function resolveNodeRequestUrl(request: IncomingMessage, options?: ResolveNodeRequestUrlOptions): URL;
|
|
25
|
+
/** Decode the query of a Node request with a model. */
|
|
26
|
+
declare function readNodeQuery<TDefs extends QueryParamDefinitions>(request: IncomingMessage, model: QueryModel<TDefs>, options?: ResolveNodeRequestUrlOptions): DecodeResult<QueryModelValues<TDefs>>;
|
|
27
|
+
/** Decode the query of a Node request, awaiting asynchronous validation. */
|
|
28
|
+
declare function readNodeQueryAsync<TDefs extends QueryParamDefinitions>(request: IncomingMessage, model: QueryModel<TDefs>, options?: ResolveNodeRequestUrlOptions): Promise<DecodeResult<QueryModelValues<TDefs>>>;
|
|
29
|
+
/** Create a request-scoped read-only source for a Node request. */
|
|
30
|
+
declare function createNodeQuerySource(request: IncomingMessage, options?: ResolveNodeRequestUrlOptions): NodeRequestQuerySource;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { NodeRequestQuerySource, ResolveNodeRequestUrlOptions, createNodeQuerySource, readNodeQuery, readNodeQueryAsync, resolveNodeRequestUrl };
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;UAmBiB;;WAEN;;WAEA;;WAEA;;;UAIM,+BAA+B;WACrC,SAAS;;;iBAkBJ,sBACd,SAAS,iBACT,UAAS,+BACR;;iBAmBa,cAAc,cAAc,uBAC1C,SAAS,iBACT,OAAO,WAAW,QAClB,UAAS,+BACR,aAAa,iBAAiB;;iBAKX,mBAAmB,cAAc,uBACrD,SAAS,iBACT,OAAO,WAAW,QAClB,UAAS,+BACR,QAAQ,aAAa,iBAAiB;;iBAKzB,sBACd,SAAS,iBACT,UAAS,+BACR"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { readUrlQuery, readUrlQueryAsync } from "@queryweave/server";
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
const fallbackHost = "queryweave.invalid";
|
|
5
|
+
function firstHeaderValue(value) {
|
|
6
|
+
if (value === void 0) return;
|
|
7
|
+
const raw = typeof value === "string" ? value : value[0];
|
|
8
|
+
if (raw === void 0) return;
|
|
9
|
+
const first = raw.split(",")[0]?.trim();
|
|
10
|
+
return first === void 0 || first === "" ? void 0 : first;
|
|
11
|
+
}
|
|
12
|
+
/** Resolve the absolute URL a Node request was made against. */
|
|
13
|
+
function resolveNodeRequestUrl(request, options = {}) {
|
|
14
|
+
const headers = request.headers;
|
|
15
|
+
const trusted = options.trustForwardedHeaders === true;
|
|
16
|
+
const host = options.host ?? (trusted ? firstHeaderValue(headers["x-forwarded-host"]) : void 0) ?? firstHeaderValue(headers.host) ?? fallbackHost;
|
|
17
|
+
const protocol = options.protocol ?? (trusted ? firstHeaderValue(headers["x-forwarded-proto"]) : void 0) ?? "http";
|
|
18
|
+
return new URL(request.url ?? "/", `${protocol}://${host}`);
|
|
19
|
+
}
|
|
20
|
+
/** Decode the query of a Node request with a model. */
|
|
21
|
+
function readNodeQuery(request, model, options = {}) {
|
|
22
|
+
return readUrlQuery(resolveNodeRequestUrl(request, options), model);
|
|
23
|
+
}
|
|
24
|
+
/** Decode the query of a Node request, awaiting asynchronous validation. */
|
|
25
|
+
async function readNodeQueryAsync(request, model, options = {}) {
|
|
26
|
+
return readUrlQueryAsync(resolveNodeRequestUrl(request, options), model);
|
|
27
|
+
}
|
|
28
|
+
/** Create a request-scoped read-only source for a Node request. */
|
|
29
|
+
function createNodeQuerySource(request, options = {}) {
|
|
30
|
+
return {
|
|
31
|
+
request,
|
|
32
|
+
read: () => resolveNodeRequestUrl(request, options).search
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { createNodeQuerySource, readNodeQuery, readNodeQueryAsync, resolveNodeRequestUrl };
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { IncomingMessage } from \"node:http\";\n\nimport type {\n DecodeResult,\n QueryModel,\n QueryModelValues,\n QueryParamDefinitions,\n QuerySource,\n} from \"@queryweave/core\";\nimport { readUrlQuery, readUrlQueryAsync } from \"@queryweave/server\";\n\n/**\n * Node.js request adapters.\n *\n * This package only bridges Node primitives into `@queryweave/server`; decoding stays in one\n * place, and no HTTP framework is required.\n */\n\n/** Options accepted by {@link resolveNodeRequestUrl}. */\nexport interface ResolveNodeRequestUrlOptions {\n /** Explicit authority, overriding request headers. */\n readonly host?: string | undefined;\n /** Explicit scheme without `:`, overriding request headers. */\n readonly protocol?: string | undefined;\n /** Read `x-forwarded-host` and `x-forwarded-proto` when present. Off by default. */\n readonly trustForwardedHeaders?: boolean | undefined;\n}\n\n/** A read-only source backed by a Node request. */\nexport interface NodeRequestQuerySource extends QuerySource {\n readonly request: IncomingMessage;\n}\n\nconst fallbackHost = \"queryweave.invalid\";\n\nfunction firstHeaderValue(value: string | readonly string[] | undefined): string | undefined {\n if (value === undefined) {\n return undefined;\n }\n const raw = typeof value === \"string\" ? value : value[0];\n if (raw === undefined) {\n return undefined;\n }\n const first = raw.split(\",\")[0]?.trim();\n return first === undefined || first === \"\" ? undefined : first;\n}\n\n/** Resolve the absolute URL a Node request was made against. */\nexport function resolveNodeRequestUrl(\n request: IncomingMessage,\n options: ResolveNodeRequestUrlOptions = {},\n): URL {\n const headers = request.headers;\n const trusted = options.trustForwardedHeaders === true;\n\n const host =\n options.host ??\n (trusted ? firstHeaderValue(headers[\"x-forwarded-host\"]) : undefined) ??\n firstHeaderValue(headers.host) ??\n fallbackHost;\n\n const protocol =\n options.protocol ??\n (trusted ? firstHeaderValue(headers[\"x-forwarded-proto\"]) : undefined) ??\n \"http\";\n\n return new URL(request.url ?? \"/\", `${protocol}://${host}`);\n}\n\n/** Decode the query of a Node request with a model. */\nexport function readNodeQuery<TDefs extends QueryParamDefinitions>(\n request: IncomingMessage,\n model: QueryModel<TDefs>,\n options: ResolveNodeRequestUrlOptions = {},\n): DecodeResult<QueryModelValues<TDefs>> {\n return readUrlQuery(resolveNodeRequestUrl(request, options), model);\n}\n\n/** Decode the query of a Node request, awaiting asynchronous validation. */\nexport async function readNodeQueryAsync<TDefs extends QueryParamDefinitions>(\n request: IncomingMessage,\n model: QueryModel<TDefs>,\n options: ResolveNodeRequestUrlOptions = {},\n): Promise<DecodeResult<QueryModelValues<TDefs>>> {\n return readUrlQueryAsync(resolveNodeRequestUrl(request, options), model);\n}\n\n/** Create a request-scoped read-only source for a Node request. */\nexport function createNodeQuerySource(\n request: IncomingMessage,\n options: ResolveNodeRequestUrlOptions = {},\n): NodeRequestQuerySource {\n return {\n request,\n read: () => resolveNodeRequestUrl(request, options).search,\n };\n}\n"],"mappings":";;;AAiCA,MAAM,eAAe;AAErB,SAAS,iBAAiB,OAAmE;CAC3F,IAAI,UAAU,QACZ;CAEF,MAAM,MAAM,OAAO,UAAU,WAAW,QAAQ,MAAM;CACtD,IAAI,QAAQ,QACV;CAEF,MAAM,QAAQ,IAAI,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK;CACtC,OAAO,UAAU,UAAa,UAAU,KAAK,SAAY;AAC3D;;AAGA,SAAgB,sBACd,SACA,UAAwC,CAAC,GACpC;CACL,MAAM,UAAU,QAAQ;CACxB,MAAM,UAAU,QAAQ,0BAA0B;CAElD,MAAM,OACJ,QAAQ,SACP,UAAU,iBAAiB,QAAQ,mBAAmB,IAAI,WAC3D,iBAAiB,QAAQ,IAAI,KAC7B;CAEF,MAAM,WACJ,QAAQ,aACP,UAAU,iBAAiB,QAAQ,oBAAoB,IAAI,WAC5D;CAEF,OAAO,IAAI,IAAI,QAAQ,OAAO,KAAK,GAAG,SAAS,KAAK,MAAM;AAC5D;;AAGA,SAAgB,cACd,SACA,OACA,UAAwC,CAAC,GACF;CACvC,OAAO,aAAa,sBAAsB,SAAS,OAAO,GAAG,KAAK;AACpE;;AAGA,eAAsB,mBACpB,SACA,OACA,UAAwC,CAAC,GACO;CAChD,OAAO,kBAAkB,sBAAsB,SAAS,OAAO,GAAG,KAAK;AACzE;;AAGA,SAAgB,sBACd,SACA,UAAwC,CAAC,GACjB;CACxB,OAAO;EACL;EACA,YAAY,sBAAsB,SAAS,OAAO,CAAC,CAAC;CACtD;AACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@queryweave/node",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "Node.js request contracts for QueryWeave.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"node",
|
|
7
|
+
"query",
|
|
8
|
+
"server",
|
|
9
|
+
"state",
|
|
10
|
+
"url"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/boussadjra/queryweave#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/boussadjra/queryweave/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/boussadjra/queryweave.git",
|
|
20
|
+
"directory": "packages/node"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"provenance": true
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@queryweave/core": "0.1.0-alpha.1",
|
|
42
|
+
"@queryweave/server": "0.1.0-alpha.1"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "26.1.1",
|
|
46
|
+
"@queryweave/typescript-config": "0.0.0"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=24.18.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsdown",
|
|
53
|
+
"dev": "tsdown --watch",
|
|
54
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
55
|
+
"test:types": "tsc -p tsconfig.json",
|
|
56
|
+
"package:check": "publint --strict && attw --pack . --profile esm-only",
|
|
57
|
+
"clean": "node ../../scripts/clean-package.mjs"
|
|
58
|
+
}
|
|
59
|
+
}
|