@queryweave/server 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 +15 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -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,15 @@
|
|
|
1
|
+
# `@queryweave/server`
|
|
2
|
+
|
|
3
|
+
Web-standard helpers for request-scoped query state.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createQueryUrl, encodeQuery, readRequestQuery, readUrlQuery } from "@queryweave/server";
|
|
7
|
+
|
|
8
|
+
readUrlQuery("https://example.test/products?page=3", productFilters);
|
|
9
|
+
readRequestQuery(request, productFilters);
|
|
10
|
+
encodeQuery(productFilters, values);
|
|
11
|
+
createQueryUrl("https://example.test/products", productFilters, values);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Every helper is a pure function over `URL` and `Request`. There is no stored state, so request data
|
|
15
|
+
cannot leak between calls, and no Node.js built-in, browser history, or frontend framework is used.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { DecodeResult, QueryModel, QueryModelValues, QueryParamDefinitions, QuerySource } from "@queryweave/core";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Web-standard helpers for request-scoped query state.
|
|
5
|
+
*
|
|
6
|
+
* Everything here is a pure function over `URL` and `Request`. There is no runtime state, no
|
|
7
|
+
* navigation, and no framework coupling, so the same helpers work in Node.js, edge, and worker
|
|
8
|
+
* runtimes.
|
|
9
|
+
*/
|
|
10
|
+
/** Base used when a relative URL string is supplied. */
|
|
11
|
+
declare const relativeUrlBase = "http://queryweave.invalid";
|
|
12
|
+
/** A read-only source backed by a web-standard `Request`. */
|
|
13
|
+
interface WebRequestQuerySource extends QuerySource {
|
|
14
|
+
readonly request: Request;
|
|
15
|
+
}
|
|
16
|
+
/** Decode the query of a URL or URL-like string with a model. */
|
|
17
|
+
declare function readUrlQuery<TDefs extends QueryParamDefinitions>(url: string | URL, model: QueryModel<TDefs>): DecodeResult<QueryModelValues<TDefs>>;
|
|
18
|
+
/** Decode the query of a URL or URL-like string, awaiting asynchronous validation. */
|
|
19
|
+
declare function readUrlQueryAsync<TDefs extends QueryParamDefinitions>(url: string | URL, model: QueryModel<TDefs>): Promise<DecodeResult<QueryModelValues<TDefs>>>;
|
|
20
|
+
/** Decode the query of a web-standard request with a model. */
|
|
21
|
+
declare function readRequestQuery<TDefs extends QueryParamDefinitions>(request: Request, model: QueryModel<TDefs>): DecodeResult<QueryModelValues<TDefs>>;
|
|
22
|
+
/** Decode the query of a web-standard request, awaiting asynchronous validation. */
|
|
23
|
+
declare function readRequestQueryAsync<TDefs extends QueryParamDefinitions>(request: Request, model: QueryModel<TDefs>): Promise<DecodeResult<QueryModelValues<TDefs>>>;
|
|
24
|
+
/** Create a request-scoped read-only source for a web-standard request. */
|
|
25
|
+
declare function createRequestQuerySource(request: Request): WebRequestQuerySource;
|
|
26
|
+
/** Encode typed state into a canonical query string without a leading `?`. */
|
|
27
|
+
declare function encodeQuery<TDefs extends QueryParamDefinitions>(model: QueryModel<TDefs>, value: QueryModelValues<TDefs>): string;
|
|
28
|
+
/**
|
|
29
|
+
* Build a URL that carries the model's canonical query.
|
|
30
|
+
*
|
|
31
|
+
* Query keys the model does not manage are preserved from `base`, in their original order, after
|
|
32
|
+
* the managed keys.
|
|
33
|
+
*/
|
|
34
|
+
declare function createQueryUrl<TDefs extends QueryParamDefinitions>(base: string | URL, model: QueryModel<TDefs>, value: QueryModelValues<TDefs>): URL;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { WebRequestQuerySource, createQueryUrl, createRequestQuerySource, encodeQuery, readRequestQuery, readRequestQueryAsync, readUrlQuery, readUrlQueryAsync, relativeUrlBase };
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;cAqBa;;UAGI,8BAA8B;WACpC,SAAS;;;iBAeJ,aAAa,cAAc,uBACzC,cAAc,KACd,OAAO,WAAW,SACjB,aAAa,iBAAiB;;iBAKX,kBAAkB,cAAc,uBACpD,cAAc,KACd,OAAO,WAAW,SACjB,QAAQ,aAAa,iBAAiB;;iBAKzB,iBAAiB,cAAc,uBAC7C,SAAS,SACT,OAAO,WAAW,SACjB,aAAa,iBAAiB;;iBAKX,sBAAsB,cAAc,uBACxD,SAAS,SACT,OAAO,WAAW,SACjB,QAAQ,aAAa,iBAAiB;;iBAKzB,yBAAyB,SAAS,UAAU;;iBAQ5C,YAAY,cAAc,uBACxC,OAAO,WAAW,QAClB,OAAO,iBAAiB;;;;;;;iBAWV,eAAe,cAAc,uBAC3C,eAAe,KACf,OAAO,WAAW,QAClB,OAAO,iBAAiB,SACvB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { formatQueryString, normalizeQueryEntries } from "@queryweave/core";
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Web-standard helpers for request-scoped query state.
|
|
6
|
+
*
|
|
7
|
+
* Everything here is a pure function over `URL` and `Request`. There is no runtime state, no
|
|
8
|
+
* navigation, and no framework coupling, so the same helpers work in Node.js, edge, and worker
|
|
9
|
+
* runtimes.
|
|
10
|
+
*/
|
|
11
|
+
/** Base used when a relative URL string is supplied. */
|
|
12
|
+
const relativeUrlBase = "http://queryweave.invalid";
|
|
13
|
+
function toUrl(url) {
|
|
14
|
+
if (typeof url !== "string") return url;
|
|
15
|
+
try {
|
|
16
|
+
return new URL(url);
|
|
17
|
+
} catch {
|
|
18
|
+
return new URL(url, relativeUrlBase);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Decode the query of a URL or URL-like string with a model. */
|
|
22
|
+
function readUrlQuery(url, model) {
|
|
23
|
+
return model.decode(toUrl(url).search);
|
|
24
|
+
}
|
|
25
|
+
/** Decode the query of a URL or URL-like string, awaiting asynchronous validation. */
|
|
26
|
+
async function readUrlQueryAsync(url, model) {
|
|
27
|
+
return model.decodeAsync(toUrl(url).search);
|
|
28
|
+
}
|
|
29
|
+
/** Decode the query of a web-standard request with a model. */
|
|
30
|
+
function readRequestQuery(request, model) {
|
|
31
|
+
return readUrlQuery(request.url, model);
|
|
32
|
+
}
|
|
33
|
+
/** Decode the query of a web-standard request, awaiting asynchronous validation. */
|
|
34
|
+
async function readRequestQueryAsync(request, model) {
|
|
35
|
+
return readUrlQueryAsync(request.url, model);
|
|
36
|
+
}
|
|
37
|
+
/** Create a request-scoped read-only source for a web-standard request. */
|
|
38
|
+
function createRequestQuerySource(request) {
|
|
39
|
+
return {
|
|
40
|
+
request,
|
|
41
|
+
read: () => toUrl(request.url).search
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Encode typed state into a canonical query string without a leading `?`. */
|
|
45
|
+
function encodeQuery(model, value) {
|
|
46
|
+
return formatQueryString(model.encode(value));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build a URL that carries the model's canonical query.
|
|
50
|
+
*
|
|
51
|
+
* Query keys the model does not manage are preserved from `base`, in their original order, after
|
|
52
|
+
* the managed keys.
|
|
53
|
+
*/
|
|
54
|
+
function createQueryUrl(base, model, value) {
|
|
55
|
+
const target = new URL(toUrl(base).href);
|
|
56
|
+
const managedKeys = new Set(model.keys());
|
|
57
|
+
const unmanaged = normalizeQueryEntries(target.search).filter(([key]) => !managedKeys.has(key));
|
|
58
|
+
target.search = formatQueryString([...model.encode(value), ...unmanaged]);
|
|
59
|
+
return target;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { createQueryUrl, createRequestQuerySource, encodeQuery, readRequestQuery, readRequestQueryAsync, readUrlQuery, readUrlQueryAsync, relativeUrlBase };
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n formatQueryString,\n normalizeQueryEntries,\n type DecodeResult,\n type QueryEntry,\n type QueryModel,\n type QueryModelValues,\n type QueryOutput,\n type QueryParamDefinitions,\n type QuerySource,\n} from \"@queryweave/core\";\n\n/**\n * Web-standard helpers for request-scoped query state.\n *\n * Everything here is a pure function over `URL` and `Request`. There is no runtime state, no\n * navigation, and no framework coupling, so the same helpers work in Node.js, edge, and worker\n * runtimes.\n */\n\n/** Base used when a relative URL string is supplied. */\nexport const relativeUrlBase = \"http://queryweave.invalid\";\n\n/** A read-only source backed by a web-standard `Request`. */\nexport interface WebRequestQuerySource extends QuerySource {\n readonly request: Request;\n}\n\nfunction toUrl(url: string | URL): URL {\n if (typeof url !== \"string\") {\n return url;\n }\n try {\n return new URL(url);\n } catch {\n return new URL(url, relativeUrlBase);\n }\n}\n\n/** Decode the query of a URL or URL-like string with a model. */\nexport function readUrlQuery<TDefs extends QueryParamDefinitions>(\n url: string | URL,\n model: QueryModel<TDefs>,\n): DecodeResult<QueryModelValues<TDefs>> {\n return model.decode(toUrl(url).search);\n}\n\n/** Decode the query of a URL or URL-like string, awaiting asynchronous validation. */\nexport async function readUrlQueryAsync<TDefs extends QueryParamDefinitions>(\n url: string | URL,\n model: QueryModel<TDefs>,\n): Promise<DecodeResult<QueryModelValues<TDefs>>> {\n return model.decodeAsync(toUrl(url).search);\n}\n\n/** Decode the query of a web-standard request with a model. */\nexport function readRequestQuery<TDefs extends QueryParamDefinitions>(\n request: Request,\n model: QueryModel<TDefs>,\n): DecodeResult<QueryModelValues<TDefs>> {\n return readUrlQuery(request.url, model);\n}\n\n/** Decode the query of a web-standard request, awaiting asynchronous validation. */\nexport async function readRequestQueryAsync<TDefs extends QueryParamDefinitions>(\n request: Request,\n model: QueryModel<TDefs>,\n): Promise<DecodeResult<QueryModelValues<TDefs>>> {\n return readUrlQueryAsync(request.url, model);\n}\n\n/** Create a request-scoped read-only source for a web-standard request. */\nexport function createRequestQuerySource(request: Request): WebRequestQuerySource {\n return {\n request,\n read: () => toUrl(request.url).search,\n };\n}\n\n/** Encode typed state into a canonical query string without a leading `?`. */\nexport function encodeQuery<TDefs extends QueryParamDefinitions>(\n model: QueryModel<TDefs>,\n value: QueryModelValues<TDefs>,\n): string {\n return formatQueryString(model.encode(value));\n}\n\n/**\n * Build a URL that carries the model's canonical query.\n *\n * Query keys the model does not manage are preserved from `base`, in their original order, after\n * the managed keys.\n */\nexport function createQueryUrl<TDefs extends QueryParamDefinitions>(\n base: string | URL,\n model: QueryModel<TDefs>,\n value: QueryModelValues<TDefs>,\n): URL {\n const target = new URL(toUrl(base).href);\n const managedKeys = new Set<string>(model.keys());\n const unmanaged: QueryEntry[] = normalizeQueryEntries(target.search).filter(\n ([key]) => !managedKeys.has(key),\n );\n const output: QueryOutput = [...model.encode(value), ...unmanaged];\n target.search = formatQueryString(output);\n return target;\n}\n"],"mappings":";;;;;;;;;;;AAqBA,MAAa,kBAAkB;AAO/B,SAAS,MAAM,KAAwB;CACrC,IAAI,OAAO,QAAQ,UACjB,OAAO;CAET,IAAI;EACF,OAAO,IAAI,IAAI,GAAG;CACpB,QAAQ;EACN,OAAO,IAAI,IAAI,KAAK,eAAe;CACrC;AACF;;AAGA,SAAgB,aACd,KACA,OACuC;CACvC,OAAO,MAAM,OAAO,MAAM,GAAG,CAAC,CAAC,MAAM;AACvC;;AAGA,eAAsB,kBACpB,KACA,OACgD;CAChD,OAAO,MAAM,YAAY,MAAM,GAAG,CAAC,CAAC,MAAM;AAC5C;;AAGA,SAAgB,iBACd,SACA,OACuC;CACvC,OAAO,aAAa,QAAQ,KAAK,KAAK;AACxC;;AAGA,eAAsB,sBACpB,SACA,OACgD;CAChD,OAAO,kBAAkB,QAAQ,KAAK,KAAK;AAC7C;;AAGA,SAAgB,yBAAyB,SAAyC;CAChF,OAAO;EACL;EACA,YAAY,MAAM,QAAQ,GAAG,CAAC,CAAC;CACjC;AACF;;AAGA,SAAgB,YACd,OACA,OACQ;CACR,OAAO,kBAAkB,MAAM,OAAO,KAAK,CAAC;AAC9C;;;;;;;AAQA,SAAgB,eACd,MACA,OACA,OACK;CACL,MAAM,SAAS,IAAI,IAAI,MAAM,IAAI,CAAC,CAAC,IAAI;CACvC,MAAM,cAAc,IAAI,IAAY,MAAM,KAAK,CAAC;CAChD,MAAM,YAA0B,sBAAsB,OAAO,MAAM,CAAC,CAAC,QAClE,CAAC,SAAS,CAAC,YAAY,IAAI,GAAG,CACjC;CAEA,OAAO,SAAS,kBAAkB,CADL,GAAG,MAAM,OAAO,KAAK,GAAG,GAAG,SACjB,CAAC;CACxC,OAAO;AACT"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@queryweave/server",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "Web-standard server contracts for QueryWeave.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"query",
|
|
7
|
+
"server",
|
|
8
|
+
"state",
|
|
9
|
+
"url",
|
|
10
|
+
"web-standard"
|
|
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/server"
|
|
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
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@queryweave/typescript-config": "0.0.0"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=24.18.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsdown",
|
|
51
|
+
"dev": "tsdown --watch",
|
|
52
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
53
|
+
"test:types": "tsc -p tsconfig.json",
|
|
54
|
+
"package:check": "publint --strict && attw --pack . --profile esm-only",
|
|
55
|
+
"clean": "node ../../scripts/clean-package.mjs"
|
|
56
|
+
}
|
|
57
|
+
}
|