@bb-labs/next-router 0.0.4 → 0.0.6

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.
@@ -2,6 +2,7 @@
2
2
  import { useEffect, useRef, useMemo } from "react";
3
3
  import { useParams, useSearchParams as useNextSearchParams, useRouter } from "next/navigation";
4
4
  import { toZodObject } from "../../utils/to-zod-object";
5
+ import { z } from "zod";
5
6
  const defaultOnError = (error, router) => {
6
7
  console.log(error);
7
8
  router.push("/404");
@@ -1 +1,2 @@
1
1
  export * from "./z-page";
2
+ export * from "./z-server-action";
@@ -1 +1,2 @@
1
1
  export * from "./z-page";
2
+ export * from "./z-server-action";
@@ -12,7 +12,7 @@ export declare function zPage<RP extends ZodObjectShape, SP extends ZodObjectSha
12
12
  resolve?: true;
13
13
  onError?: OnZodError;
14
14
  loadingHandler?: React.ReactNode;
15
- handler: (input: {
15
+ handler: (inputs: {
16
16
  routeParams: InferOutput<RP>;
17
17
  searchParams: InferOutput<SP>;
18
18
  }) => React.ReactNode | Promise<React.ReactNode>;
@@ -25,7 +25,7 @@ export declare function zPage<RP extends ZodObjectShape>(cfg: {
25
25
  resolve?: true;
26
26
  onError?: OnZodError;
27
27
  loadingHandler?: React.ReactNode;
28
- handler: (input: {
28
+ handler: (inputs: {
29
29
  routeParams: InferOutput<RP>;
30
30
  }) => React.ReactNode | Promise<React.ReactNode>;
31
31
  }): ZPageReturn;
@@ -37,7 +37,7 @@ export declare function zPage<SP extends ZodObjectShape>(cfg: {
37
37
  resolve?: true;
38
38
  onError?: OnZodError;
39
39
  loadingHandler?: React.ReactNode;
40
- handler: (input: {
40
+ handler: (inputs: {
41
41
  searchParams: InferOutput<SP>;
42
42
  }) => React.ReactNode | Promise<React.ReactNode>;
43
43
  }): ZPageReturn;
@@ -49,7 +49,7 @@ export declare function zPage<RP extends ZodObjectShape, SP extends ZodObjectSha
49
49
  resolve: false;
50
50
  onError?: never;
51
51
  loadingHandler?: never;
52
- handler: (input: {
52
+ handler: (inputs: {
53
53
  routeParams: Promise<InferOutput<RP>>;
54
54
  searchParams: Promise<InferOutput<SP>>;
55
55
  }) => React.ReactNode | Promise<React.ReactNode>;
@@ -62,7 +62,7 @@ export declare function zPage<RP extends ZodObjectShape>(cfg: {
62
62
  resolve: false;
63
63
  onError?: never;
64
64
  loadingHandler?: never;
65
- handler: (input: {
65
+ handler: (inputs: {
66
66
  routeParams: Promise<InferOutput<RP>>;
67
67
  }) => React.ReactNode | Promise<React.ReactNode>;
68
68
  }): ZPageReturn;
@@ -74,7 +74,7 @@ export declare function zPage<SP extends ZodObjectShape>(cfg: {
74
74
  resolve: false;
75
75
  onError?: never;
76
76
  loadingHandler?: never;
77
- handler: (input: {
77
+ handler: (inputs: {
78
78
  searchParams: Promise<InferOutput<SP>>;
79
79
  }) => React.ReactNode | Promise<React.ReactNode>;
80
80
  }): ZPageReturn;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Suspense } from "react";
2
+ import React, { Suspense } from "react";
3
3
  import { setup } from "../utils/setup";
4
4
  // ------------- IMPLEMENTATION -------------
5
5
  export function zPage(cfg) {
@@ -9,10 +9,10 @@ export function zPage(cfg) {
9
9
  return async (props) => cfg.handler(createValidatedPromises(props));
10
10
  }
11
11
  async function Inner({ promises }) {
12
- const input = await resolveParams(promises);
13
- if (!Object.keys(input).length)
12
+ const inputs = await resolveParams(promises);
13
+ if (!Object.keys(inputs).length)
14
14
  return null;
15
- return cfg.handler(input);
15
+ return cfg.handler(inputs);
16
16
  }
17
17
  return (props) => (_jsx(Suspense, { fallback: cfg.loadingHandler ?? null, children: _jsx(Inner, { promises: createValidatedPromises(props) }) }));
18
18
  }
@@ -1 +1 @@
1
- export {};
1
+ import { z } from "zod";
@@ -0,0 +1,5 @@
1
+ import type { ZodObjectShape, InferZodObjectShapeOutput } from "../../../utils/types";
2
+ export declare function zServerAction<P extends ZodObjectShape, R>(cfg: {
3
+ params: P;
4
+ handler: (inputs: InferZodObjectShapeOutput<P>) => Promise<R>;
5
+ }): (inputs: InferZodObjectShapeOutput<P>) => Promise<R>;
@@ -0,0 +1,8 @@
1
+ import { toZodObject } from "../../../utils/to-zod-object";
2
+ export function zServerAction(cfg) {
3
+ const schema = toZodObject(cfg.params);
4
+ return async (inputs) => {
5
+ const parsed = schema.parse(inputs);
6
+ return cfg.handler(parsed);
7
+ };
8
+ }
@@ -0,0 +1 @@
1
+ export * from "./fns/z-server-action";
@@ -0,0 +1 @@
1
+ export * from "./fns/z-server-action";
@@ -1 +1 @@
1
- export {};
1
+ import { z } from "zod";
package/package.json CHANGED
@@ -1,23 +1,13 @@
1
1
  {
2
2
  "name": "@bb-labs/next-router",
3
- "version": "0.0.4",
4
- "author": "Beepbop",
5
- "homepage": "https://github.com/beepbop-labs/next-router",
6
- "keywords": [
7
- "next-router",
8
- "router",
9
- "next",
10
- "nextjs"
11
- ],
12
- "license": "MIT",
3
+ "version": "0.0.6",
13
4
  "repository": {
14
5
  "type": "git",
15
- "url": "https://github.com/beepbop-labs/next-router.git"
6
+ "url": "https://github.com/beepbop-labs/libraries.git"
16
7
  },
17
8
  "description": "A library for routing in Next.js",
18
9
  "files": [
19
- "dist",
20
- "README.md"
10
+ "dist"
21
11
  ],
22
12
  "exports": {
23
13
  ".": "./dist/server/index.js",
@@ -25,16 +15,19 @@
25
15
  "./common": "./dist/common/index.js"
26
16
  },
27
17
  "scripts": {
28
- "clean": "rm -rf dist",
29
- "build": "npm run clean && tsc -p tsconfig.json",
30
- "pack": "npm run build && npm pack --pack-destination ./archive/"
18
+ "build": "bldr",
19
+ "dev": "bldr -w",
20
+ "clean": "rm -rf node_modules bun.lock dist"
31
21
  },
32
22
  "dependencies": {
23
+ "@bb-labs/bldr": "^0.0.16",
24
+ "@bb-labs/tsconfigs": "^0.0.4",
33
25
  "zod": "^4.2.1"
34
26
  },
35
27
  "devDependencies": {
36
28
  "@types/bun": "latest",
37
- "@types/react": "^19.2.7"
29
+ "@types/react": "^19.2.7",
30
+ "tsc-alias": "^1.8.16"
38
31
  },
39
32
  "peerDependencies": {
40
33
  "typescript": "^5",