@mhbdev/next-safe-route 0.0.37 → 0.0.38
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/README.md +163 -2
- package/dist/hooks.d.mts +71 -0
- package/dist/hooks.d.ts +71 -0
- package/dist/hooks.js +2 -0
- package/dist/hooks.js.map +1 -0
- package/dist/hooks.mjs +2 -0
- package/dist/hooks.mjs.map +1 -0
- package/dist/index.d.mts +59 -8
- package/dist/index.d.ts +59 -8
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/safeActionTypes-ClmL2Zxu.d.ts +60 -0
- package/dist/safeActionTypes-DfvihJur.d.mts +60 -0
- package/dist/{types-UXG9BoMB.d.mts → types-DYbZEItT.d.mts} +3 -2
- package/dist/{types-UXG9BoMB.d.ts → types-DYbZEItT.d.ts} +3 -2
- package/dist/valibot.d.mts +1 -1
- package/dist/valibot.d.ts +1 -1
- package/dist/yup.d.mts +1 -1
- package/dist/yup.d.ts +1 -1
- package/package.json +20 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { S as Schema, I as InferIn, a as Infer, V as ValidationAdapter } from './types-DYbZEItT.mjs';
|
|
2
|
+
|
|
3
|
+
type Awaitable<T> = T | Promise<T>;
|
|
4
|
+
type ActionInputArgs<TInput> = [TInput] extends [void] ? [] | [TInput] : [input: TInput];
|
|
5
|
+
type InferActionInput<TSchema extends Schema | undefined> = TSchema extends Schema ? InferIn<TSchema> : void;
|
|
6
|
+
type InferParsedActionInput<TSchema extends Schema | undefined> = TSchema extends Schema ? Infer<TSchema> : undefined;
|
|
7
|
+
type SafeActionValidationErrors = {
|
|
8
|
+
fieldErrors: Record<string, string[]>;
|
|
9
|
+
formErrors: string[];
|
|
10
|
+
};
|
|
11
|
+
type SafeActionSuccessResult<TData> = {
|
|
12
|
+
data: TData;
|
|
13
|
+
validationErrors?: undefined;
|
|
14
|
+
serverError?: undefined;
|
|
15
|
+
};
|
|
16
|
+
type SafeActionValidationErrorResult = {
|
|
17
|
+
data?: undefined;
|
|
18
|
+
validationErrors: SafeActionValidationErrors;
|
|
19
|
+
serverError?: undefined;
|
|
20
|
+
};
|
|
21
|
+
type SafeActionServerErrorResult = {
|
|
22
|
+
data?: undefined;
|
|
23
|
+
validationErrors?: undefined;
|
|
24
|
+
serverError: string;
|
|
25
|
+
};
|
|
26
|
+
type SafeActionResult<TData> = SafeActionSuccessResult<TData> | SafeActionValidationErrorResult | SafeActionServerErrorResult;
|
|
27
|
+
type SafeActionFn<TInput, TData> = (...args: ActionInputArgs<TInput>) => Promise<SafeActionResult<TData>>;
|
|
28
|
+
type SafeActionMiddlewareNext<TCtxPatch extends Record<string, unknown>, TData> = (options?: {
|
|
29
|
+
ctx?: TCtxPatch;
|
|
30
|
+
}) => Promise<SafeActionResult<TData>>;
|
|
31
|
+
type SafeActionMiddleware<TParsedInput, TCtx extends Record<string, unknown>, TMetadata extends Record<string, unknown>, TCtxPatch extends Record<string, unknown> = Record<string, unknown>, TData = unknown> = (args: {
|
|
32
|
+
parsedInput: TParsedInput;
|
|
33
|
+
ctx: TCtx;
|
|
34
|
+
metadata: TMetadata;
|
|
35
|
+
next: SafeActionMiddlewareNext<TCtxPatch, TData>;
|
|
36
|
+
}) => Awaitable<SafeActionResult<TData>>;
|
|
37
|
+
type AnySafeActionMiddleware = SafeActionMiddleware<unknown, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, unknown>;
|
|
38
|
+
type SafeActionHandler<TParsedInput, TCtx extends Record<string, unknown>, TMetadata, TData> = (args: {
|
|
39
|
+
parsedInput: TParsedInput;
|
|
40
|
+
ctx: TCtx;
|
|
41
|
+
metadata: TMetadata;
|
|
42
|
+
}) => Awaitable<TData>;
|
|
43
|
+
type SafeActionClientOptions<TContext extends Record<string, unknown>> = {
|
|
44
|
+
validationAdapter?: ValidationAdapter;
|
|
45
|
+
baseContext?: TContext;
|
|
46
|
+
defaultServerError?: string;
|
|
47
|
+
handleServerError?: (error: unknown) => string;
|
|
48
|
+
};
|
|
49
|
+
type SafeActionBuilderConfig<TInputSchema extends Schema | undefined, TOutputSchema extends Schema | undefined, TContext extends Record<string, unknown>, TMetadata extends Record<string, unknown>> = {
|
|
50
|
+
inputSchema?: TInputSchema;
|
|
51
|
+
outputSchema?: TOutputSchema;
|
|
52
|
+
validationAdapter: ValidationAdapter;
|
|
53
|
+
baseContext: TContext;
|
|
54
|
+
metadata: TMetadata;
|
|
55
|
+
middlewares: AnySafeActionMiddleware[];
|
|
56
|
+
defaultServerError: string;
|
|
57
|
+
handleServerError?: (error: unknown) => string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type { InferParsedActionInput as I, SafeActionValidationErrors as S, SafeActionResult as a, SafeActionBuilderConfig as b, SafeActionMiddleware as c, SafeActionHandler as d, SafeActionFn as e, InferActionInput as f, SafeActionClientOptions as g, SafeActionMiddlewareNext as h, SafeActionServerErrorResult as i, SafeActionSuccessResult as j, SafeActionValidationErrorResult as k };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { TSchema, Static } from '@sinclair/typebox';
|
|
2
|
-
import { GenericSchema, GenericSchemaAsync, InferOutput } from 'valibot';
|
|
2
|
+
import { GenericSchema, GenericSchemaAsync, InferOutput, InferInput } from 'valibot';
|
|
3
3
|
import { Schema as Schema$1, InferType } from 'yup';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
6
6
|
type IfInstalled<T> = any extends T ? never : T;
|
|
7
7
|
type Schema = IfInstalled<z.ZodTypeAny> | IfInstalled<GenericSchema> | IfInstalled<GenericSchemaAsync> | IfInstalled<Schema$1> | IfInstalled<TSchema>;
|
|
8
8
|
type Infer<S extends Schema> = S extends IfInstalled<z.ZodTypeAny> ? z.infer<S> : S extends IfInstalled<GenericSchema> ? InferOutput<S> : S extends IfInstalled<GenericSchemaAsync> ? InferOutput<S> : S extends IfInstalled<Schema$1> ? InferType<S> : S extends IfInstalled<TSchema> ? Static<S> : never;
|
|
9
|
+
type InferIn<S extends Schema> = S extends IfInstalled<z.ZodTypeAny> ? z.input<S> : S extends IfInstalled<GenericSchema> ? InferInput<S> : S extends IfInstalled<GenericSchemaAsync> ? InferInput<S> : S extends IfInstalled<Schema$1> ? InferType<S> : S extends IfInstalled<TSchema> ? Static<S> : never;
|
|
9
10
|
type ValidationIssue = {
|
|
10
11
|
message: string;
|
|
11
12
|
path?: Array<string | number | symbol>;
|
|
@@ -55,4 +56,4 @@ interface ValidationAdapter {
|
|
|
55
56
|
}>;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
export type {
|
|
59
|
+
export type { InferIn as I, Schema as S, ValidationAdapter as V, Infer as a, ValidationIssue as b, IfInstalled as c };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { TSchema, Static } from '@sinclair/typebox';
|
|
2
|
-
import { GenericSchema, GenericSchemaAsync, InferOutput } from 'valibot';
|
|
2
|
+
import { GenericSchema, GenericSchemaAsync, InferOutput, InferInput } from 'valibot';
|
|
3
3
|
import { Schema as Schema$1, InferType } from 'yup';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
6
6
|
type IfInstalled<T> = any extends T ? never : T;
|
|
7
7
|
type Schema = IfInstalled<z.ZodTypeAny> | IfInstalled<GenericSchema> | IfInstalled<GenericSchemaAsync> | IfInstalled<Schema$1> | IfInstalled<TSchema>;
|
|
8
8
|
type Infer<S extends Schema> = S extends IfInstalled<z.ZodTypeAny> ? z.infer<S> : S extends IfInstalled<GenericSchema> ? InferOutput<S> : S extends IfInstalled<GenericSchemaAsync> ? InferOutput<S> : S extends IfInstalled<Schema$1> ? InferType<S> : S extends IfInstalled<TSchema> ? Static<S> : never;
|
|
9
|
+
type InferIn<S extends Schema> = S extends IfInstalled<z.ZodTypeAny> ? z.input<S> : S extends IfInstalled<GenericSchema> ? InferInput<S> : S extends IfInstalled<GenericSchemaAsync> ? InferInput<S> : S extends IfInstalled<Schema$1> ? InferType<S> : S extends IfInstalled<TSchema> ? Static<S> : never;
|
|
9
10
|
type ValidationIssue = {
|
|
10
11
|
message: string;
|
|
11
12
|
path?: Array<string | number | symbol>;
|
|
@@ -55,4 +56,4 @@ interface ValidationAdapter {
|
|
|
55
56
|
}>;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
export type {
|
|
59
|
+
export type { InferIn as I, Schema as S, ValidationAdapter as V, Infer as a, ValidationIssue as b, IfInstalled as c };
|
package/dist/valibot.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GenericSchema, GenericSchemaAsync } from 'valibot';
|
|
2
|
-
import {
|
|
2
|
+
import { V as ValidationAdapter, c as IfInstalled, a as Infer } from './types-DYbZEItT.mjs';
|
|
3
3
|
import '@sinclair/typebox';
|
|
4
4
|
import 'yup';
|
|
5
5
|
import 'zod';
|
package/dist/valibot.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GenericSchema, GenericSchemaAsync } from 'valibot';
|
|
2
|
-
import {
|
|
2
|
+
import { V as ValidationAdapter, c as IfInstalled, a as Infer } from './types-DYbZEItT.js';
|
|
3
3
|
import '@sinclair/typebox';
|
|
4
4
|
import 'yup';
|
|
5
5
|
import 'zod';
|
package/dist/yup.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from 'yup';
|
|
2
|
-
import {
|
|
2
|
+
import { V as ValidationAdapter, c as IfInstalled, a as Infer, b as ValidationIssue } from './types-DYbZEItT.mjs';
|
|
3
3
|
import '@sinclair/typebox';
|
|
4
4
|
import 'valibot';
|
|
5
5
|
import 'zod';
|
package/dist/yup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from 'yup';
|
|
2
|
-
import {
|
|
2
|
+
import { V as ValidationAdapter, c as IfInstalled, a as Infer, b as ValidationIssue } from './types-DYbZEItT.js';
|
|
3
3
|
import '@sinclair/typebox';
|
|
4
4
|
import 'valibot';
|
|
5
5
|
import 'zod';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mhbdev/next-safe-route",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"description": "A safer way to define route handlers in Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"next",
|
|
@@ -45,6 +45,11 @@
|
|
|
45
45
|
"require": "./dist/yup.js",
|
|
46
46
|
"types": "./dist/yup.d.ts"
|
|
47
47
|
},
|
|
48
|
+
"./hooks": {
|
|
49
|
+
"import": "./dist/hooks.mjs",
|
|
50
|
+
"require": "./dist/hooks.js",
|
|
51
|
+
"types": "./dist/hooks.d.ts"
|
|
52
|
+
},
|
|
48
53
|
"./package.json": "./package.json"
|
|
49
54
|
},
|
|
50
55
|
"files": [
|
|
@@ -70,6 +75,8 @@
|
|
|
70
75
|
},
|
|
71
76
|
"peerDependencies": {
|
|
72
77
|
"@sinclair/typebox": "^0.33.7",
|
|
78
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
79
|
+
"react-dom": "^18.2.0 || ^19.0.0",
|
|
73
80
|
"valibot": "^0.39.0",
|
|
74
81
|
"yup": "^1.4.0",
|
|
75
82
|
"zod": "^4.3.5"
|
|
@@ -81,20 +88,32 @@
|
|
|
81
88
|
"valibot": {
|
|
82
89
|
"optional": true
|
|
83
90
|
},
|
|
91
|
+
"react": {
|
|
92
|
+
"optional": true
|
|
93
|
+
},
|
|
94
|
+
"react-dom": {
|
|
95
|
+
"optional": true
|
|
96
|
+
},
|
|
84
97
|
"yup": {
|
|
85
98
|
"optional": true
|
|
86
99
|
}
|
|
87
100
|
},
|
|
88
101
|
"devDependencies": {
|
|
89
102
|
"@sinclair/typebox": "^0.33.7",
|
|
103
|
+
"@testing-library/react": "^16.1.0",
|
|
104
|
+
"@types/react": "^18.3.12",
|
|
105
|
+
"@types/react-dom": "^18.3.1",
|
|
90
106
|
"@swc/core": "^1.5.29",
|
|
91
107
|
"@tronite/style-guide": "^0.0.13",
|
|
92
108
|
"@types/node": "^20.14.2",
|
|
93
109
|
"@vitest/coverage-v8": "^1.6.0",
|
|
94
110
|
"eslint": "^8.57.0",
|
|
95
111
|
"husky": "^9.0.11",
|
|
112
|
+
"jsdom": "^25.0.1",
|
|
96
113
|
"lint-staged": "^15.2.7",
|
|
97
114
|
"prettier": "^3.3.2",
|
|
115
|
+
"react": "^18.3.1",
|
|
116
|
+
"react-dom": "^18.3.1",
|
|
98
117
|
"release-it": "^17.3.0",
|
|
99
118
|
"tsup": "^8.1.0",
|
|
100
119
|
"typescript": "^5.4.5",
|