paramour 0.0.0 → 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.
@@ -0,0 +1,77 @@
1
+ import { SearchSourceError } from "./errors.js";
2
+ import { safeDecodeSearch } from "./safe-decode.js";
3
+ import { isRawSearch, requireSearchConfig, } from "./search.js";
4
+ /**
5
+ * Exports a route's `search:` config as the URL wire contract in Standard
6
+ * Schema form (design-08 STD1/STD5), for consumers like tRPC inputs or
7
+ * TanStack `validateSearch`. Semantics are byte-identical to `decodeSearch`
8
+ * (STD6): defaults apply, `.catch()` recovers parse failures — invalid API
9
+ * input silently coerces to the fallback — unknown keys strip (P8), and
10
+ * duplicate values on a scalar codec reject (P5). No coercion, ever (STD2):
11
+ * the schema accepts wire strings (`"42"`), not decoded values (`42`).
12
+ */
13
+ export function standardSearchSchema(route) {
14
+ const config = route["~search"];
15
+ // A missing/malformed config is a programming error and stays loud (STD7);
16
+ // checking eagerly fails at construction, not at first validate().
17
+ requireSearchConfig(config);
18
+ // A config's raw/codec-map shape is fixed at construction; hoisted so the
19
+ // sentinel un-mapping below never touches a codec map's keyed issues.
20
+ const raw = isRawSearch(config);
21
+ return {
22
+ "~standard": {
23
+ validate: (value) => {
24
+ try {
25
+ const result = safeDecodeSearch(route, value);
26
+ if (result.status === "error") {
27
+ return {
28
+ issues: result.error.issues.map((issue) => toStandardIssue(issue, raw)),
29
+ };
30
+ }
31
+ return { value: result.data };
32
+ }
33
+ catch (error) {
34
+ // STD7: validate() receives genuinely untrusted input, so the
35
+ // source-shape contract the read layer enforces with loud throws
36
+ // softens to issues at this one boundary — SearchSourceError exists
37
+ // as its own branded class exactly so this catch can't swallow
38
+ // config-contract violations or rebranded validator throws.
39
+ if (error instanceof SearchSourceError) {
40
+ return { issues: [toSourceIssue(error)] };
41
+ }
42
+ // Async raw schema (design-02 D7), throwing raw validators, and
43
+ // throwing .default()/.catch() factories are true programming
44
+ // errors: loud (STD7).
45
+ throw error;
46
+ }
47
+ },
48
+ vendor: "paramour",
49
+ version: 1,
50
+ },
51
+ };
52
+ }
53
+ /**
54
+ * Maps a source-shape violation to spec shape (STD7): keyed where the read
55
+ * layer could attribute it, root-level (absent path) for a malformed source.
56
+ */
57
+ function toSourceIssue(error) {
58
+ return error.key === null
59
+ ? { message: error.message }
60
+ : { message: error.message, path: [error.key] };
61
+ }
62
+ /**
63
+ * Maps a decode issue to spec shape. decodeRawSearch collapses a root-level
64
+ * schema issue to the "<search>" sentinel key (SS3/SS4); a Standard Schema
65
+ * expresses "root" as an ABSENT path, so the sentinel un-maps here (STD7
66
+ * "root-level otherwise") — for raw configs only, since a codec map's issues
67
+ * are always keyed and a param may literally be named "<search>". (A raw
68
+ * vendor issue whose real path is ["<search>"] still collides with the
69
+ * sentinel — indistinguishable after the flat-key collapse.) Nested
70
+ * raw-schema paths were already dot-joined into the key and re-emit as ONE
71
+ * segment — keys may contain dots, so splitting back would be unsound.
72
+ */
73
+ function toStandardIssue(issue, raw) {
74
+ return raw && issue.key === "<search>"
75
+ ? { message: issue.message }
76
+ : { message: issue.message, path: [issue.key] };
77
+ }
package/package.json CHANGED
@@ -1,7 +1,18 @@
1
1
  {
2
2
  "name": "paramour",
3
- "version": "0.0.0",
4
- "description": "Type-safe routing companion for the Next.js App Router: validated route params and search params, typed path building, and explicit URL serialization. Placeholder release — under active development.",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "default": "./dist/index.js"
9
+ }
10
+ },
11
+ "scripts": {
12
+ "build": "tsc -p tsconfig.build.json",
13
+ "typecheck": "tsc --noEmit"
14
+ },
15
+ "description": "Type-safe routing companion for the Next.js App Router: validated route params and search params, typed path building, and explicit URL serialization.",
5
16
  "keywords": [
6
17
  "nextjs",
7
18
  "app-router",
@@ -16,11 +27,24 @@
16
27
  "license": "MIT",
17
28
  "repository": {
18
29
  "type": "git",
19
- "url": "git+https://github.com/JasonPaff/paramour.git"
30
+ "url": "git+https://github.com/JasonPaff/paramour.git",
31
+ "directory": "packages/core"
20
32
  },
21
33
  "homepage": "https://github.com/JasonPaff/paramour#readme",
22
34
  "bugs": {
23
35
  "url": "https://github.com/JasonPaff/paramour/issues"
24
36
  },
25
- "files": []
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "dependencies": {
41
+ "@standard-schema/spec": "^1.1.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^24.0.0",
45
+ "arktype": "^2.2.3",
46
+ "fast-check": "^4.8.0",
47
+ "valibot": "^1.4.2",
48
+ "zod": "^4.4.3"
49
+ }
26
50
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Jason Paff
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 DELETED
@@ -1,28 +0,0 @@
1
- # paramour
2
-
3
- > *paramour* — "param" + "amour": a library that loves your params.
4
-
5
- A fully type-safe routing companion for the Next.js App Router: validated, typed
6
- route params and search params, type-checked path building, and a predictable,
7
- human-readable URL wire format — with your choice of validation library via
8
- [Standard Schema](https://github.com/standard-schema/standard-schema).
9
-
10
- ## Status
11
-
12
- **This is a name-reservation placeholder.** The library is under active design
13
- and development — nothing here is usable yet.
14
-
15
- - Design document and progress: [github.com/JasonPaff/paramour](https://github.com/JasonPaff/paramour)
16
- - Companion packages will live under the [`@paramour-js`](https://www.npmjs.com/org/paramour-js) scope.
17
-
18
- ## Why
19
-
20
- Born from lessons learned maintaining and contributing to
21
- [`next-typesafe-url`](https://www.npmjs.com/package/next-typesafe-url), which is
22
- effectively unmaintained. Paramour aims to be a documented, tested,
23
- community-maintained answer to typed routing in Next.js, with a migration path
24
- from `next-typesafe-url`.
25
-
26
- ## License
27
-
28
- MIT © Jason Paff