@hyperspan/framework 1.0.0-alpha.0 → 1.0.0-alpha.10
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/package.json +8 -8
- package/src/actions.test.ts +147 -0
- package/src/actions.ts +118 -0
- package/src/client/_hs/hyperspan-actions.client.ts +98 -0
- package/src/client/_hs/hyperspan-scripts.client.ts +31 -0
- package/src/client/_hs/hyperspan-streaming.client.ts +94 -0
- package/src/client/js.ts +0 -21
- package/src/cookies.ts +234 -0
- package/src/index.ts +2 -0
- package/src/plugins.ts +2 -4
- package/src/server.test.ts +141 -17
- package/src/server.ts +50 -71
- package/src/types.ts +52 -2
- package/src/utils.test.ts +196 -0
- package/src/utils.ts +135 -1
- package/tsconfig.json +1 -1
- package/src/clientjs/hyperspan-client.ts +0 -224
- package/src/middleware/zod.ts +0 -46
- /package/src/{clientjs → client/_hs}/idiomorph.ts +0 -0
package/src/middleware/zod.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { Hyperspan as HS } from '../types';
|
|
2
|
-
import type { ZodAny, ZodObject, ZodError } from 'zod/v4';
|
|
3
|
-
import { flattenError } from 'zod/v4';
|
|
4
|
-
|
|
5
|
-
export class ZodValidationError extends Error {
|
|
6
|
-
constructor(flattened: ReturnType<typeof flattenError>) {
|
|
7
|
-
super('Input validation error(s)');
|
|
8
|
-
this.name = 'ZodValidationError';
|
|
9
|
-
|
|
10
|
-
// Copy all properties from flattened error
|
|
11
|
-
Object.assign(this, flattened);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function validateQuery(schema: ZodObject): HS.MiddlewareFunction {
|
|
16
|
-
return async (context: HS.Context, next: HS.NextFunction) => {
|
|
17
|
-
const query: Record<string, string> = Object.fromEntries(context.req.query.entries());
|
|
18
|
-
const validated = schema.safeParse(query);
|
|
19
|
-
|
|
20
|
-
if (!validated.success) {
|
|
21
|
-
const err = formatZodError(validated.error);
|
|
22
|
-
return context.res.error(err, { status: 400 });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return next();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function validateBody(schema: ZodObject | ZodAny): HS.MiddlewareFunction {
|
|
30
|
-
return async (context: HS.Context, next: HS.NextFunction) => {
|
|
31
|
-
const body = await context.req.body;
|
|
32
|
-
const validated = schema.safeParse(body);
|
|
33
|
-
|
|
34
|
-
if (!validated.success) {
|
|
35
|
-
const err = formatZodError(validated.error);
|
|
36
|
-
return context.res.error(err, { status: 400 });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return next();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function formatZodError(error: ZodError): ZodValidationError {
|
|
44
|
-
const zodError = flattenError(error);
|
|
45
|
-
return new ZodValidationError(zodError);
|
|
46
|
-
}
|
|
File without changes
|