rpc4next 0.3.0 → 0.3.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.
@@ -1,55 +1,10 @@
1
1
  import type { OPTIONAL_CATCH_ALL_PREFIX, CATCH_ALL_PREFIX, DYNAMIC_PREFIX, HTTP_METHOD_FUNC_KEYS } from "../lib/constants";
2
+ import type { ContentType } from "../lib/content-type-types";
3
+ import type { HttpRequestHeaders } from "../lib/http-request-headers-types";
4
+ import type { HttpStatusCode } from "../lib/http-status-code-types";
2
5
  import type { RouteHandlerResponse, RouteResponse, ValidationSchema } from "../server/route-types";
3
- import type { TypedNextResponse, HttpStatusCode, ContentType, ValidationInputFor } from "../server/types";
6
+ import type { TypedNextResponse, ValidationInputFor } from "../server/types";
4
7
  import type { NextResponse } from "next/server";
5
- /**
6
- * Represents HTTP request headers with optional fields.
7
- * This type includes general request headers, CORS/security-related headers, and client-specific headers.
8
- */
9
- type HttpRequestHeaders = Partial<{
10
- Accept: string;
11
- "Accept-Charset": string;
12
- "Accept-Encoding": string;
13
- "Accept-Language": string;
14
- Authorization: string;
15
- "Cache-Control": string;
16
- Connection: string;
17
- "Content-Length": string;
18
- "Content-Type": ContentType;
19
- Cookie: string;
20
- Date: string;
21
- Expect: string;
22
- Forwarded: string;
23
- From: string;
24
- Host: string;
25
- "If-Match": string;
26
- "If-Modified-Since": string;
27
- "If-None-Match": string;
28
- "If-Range": string;
29
- "If-Unmodified-Since": string;
30
- "Max-Forwards": string;
31
- Origin: string;
32
- Pragma: string;
33
- Range: string;
34
- Referer: string;
35
- TE: string;
36
- Trailer: string;
37
- "Transfer-Encoding": string;
38
- Upgrade: string;
39
- "User-Agent": string;
40
- Via: string;
41
- Warning: string;
42
- "Access-Control-Request-Method": string;
43
- "Access-Control-Request-Headers": string;
44
- DNT: string;
45
- "Sec-Fetch-Dest": string;
46
- "Sec-Fetch-Mode": string;
47
- "Sec-Fetch-Site": string;
48
- "Sec-Fetch-User": string;
49
- "Sec-CH-UA": string;
50
- "Sec-CH-UA-Platform": string;
51
- "Sec-CH-UA-Mobile": string;
52
- }>;
53
8
  /**
54
9
  * Extension of the standard `RequestInit` interface with strongly typed headers.
55
10
  */
@@ -0,0 +1,7 @@
1
+ type KnownContentType = "application/json" | "text/html" | "text/plain" | "application/javascript" | "text/css" | "image/png" | "image/jpeg" | "image/svg+xml" | "application/pdf" | "application/octet-stream" | "multipart/form-data" | "application/x-www-form-urlencoded";
2
+ /**
3
+ * A content type that can be either one of the predefined `KnownContentType` values,
4
+ * or any other custom string.
5
+ */
6
+ export type ContentType = KnownContentType | (string & {});
7
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,49 @@
1
+ import type { ContentType } from "../server";
2
+ /**
3
+ * Represents HTTP request headers with optional fields.
4
+ * This type includes general request headers, CORS/security-related headers, and client-specific headers.
5
+ */
6
+ export type HttpRequestHeaders = Partial<{
7
+ Accept: string;
8
+ "Accept-Charset": string;
9
+ "Accept-Encoding": string;
10
+ "Accept-Language": string;
11
+ Authorization: string;
12
+ "Cache-Control": string;
13
+ Connection: string;
14
+ "Content-Length": string;
15
+ "Content-Type": ContentType;
16
+ Cookie: string;
17
+ Date: string;
18
+ Expect: string;
19
+ Forwarded: string;
20
+ From: string;
21
+ Host: string;
22
+ "If-Match": string;
23
+ "If-Modified-Since": string;
24
+ "If-None-Match": string;
25
+ "If-Range": string;
26
+ "If-Unmodified-Since": string;
27
+ "Max-Forwards": string;
28
+ Origin: string;
29
+ Pragma: string;
30
+ Range: string;
31
+ Referer: string;
32
+ TE: string;
33
+ Trailer: string;
34
+ "Transfer-Encoding": string;
35
+ Upgrade: string;
36
+ "User-Agent": string;
37
+ Via: string;
38
+ Warning: string;
39
+ "Access-Control-Request-Method": string;
40
+ "Access-Control-Request-Headers": string;
41
+ DNT: string;
42
+ "Sec-Fetch-Dest": string;
43
+ "Sec-Fetch-Mode": string;
44
+ "Sec-Fetch-Site": string;
45
+ "Sec-Fetch-User": string;
46
+ "Sec-CH-UA": string;
47
+ "Sec-CH-UA-Platform": string;
48
+ "Sec-CH-UA-Mobile": string;
49
+ }>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,46 @@
1
+ import type { ContentType } from "./content-type-types";
2
+ /**
3
+ * Represents HTTP response headers with optional fields, parameterized by the content type.
4
+ * This type includes common headers used for caching, content description, CORS, authentication, security, cookies, redirects, connection, and server information.
5
+ *
6
+ * @template TContentType - The specific content type for the `Content-Type` header.
7
+ */
8
+ export type HttpResponseHeaders<TContentType extends ContentType> = Partial<{
9
+ "Cache-Control": string;
10
+ Expires: string;
11
+ ETag: string;
12
+ "Last-Modified": string;
13
+ "Content-Type": TContentType;
14
+ "Content-Length": string;
15
+ "Content-Encoding": string;
16
+ "Content-Language": string;
17
+ "Content-Location": string;
18
+ "Content-Disposition": string;
19
+ "Access-Control-Allow-Origin": string;
20
+ "Access-Control-Allow-Credentials": string;
21
+ "Access-Control-Allow-Headers": string;
22
+ "Access-Control-Allow-Methods": string;
23
+ "Access-Control-Expose-Headers": string;
24
+ "WWW-Authenticate": string;
25
+ Authorization: string;
26
+ "Strict-Transport-Security": string;
27
+ "Content-Security-Policy": string;
28
+ "X-Content-Type-Options": string;
29
+ "X-Frame-Options": string;
30
+ "X-XSS-Protection": string;
31
+ "Referrer-Policy": string;
32
+ "Permissions-Policy": string;
33
+ "Cross-Origin-Opener-Policy": string;
34
+ "Cross-Origin-Embedder-Policy": string;
35
+ "Cross-Origin-Resource-Policy": string;
36
+ "Set-Cookie": string;
37
+ Location: string;
38
+ Connection: string;
39
+ "Keep-Alive": string;
40
+ "Transfer-Encoding": string;
41
+ Upgrade: string;
42
+ Vary: string;
43
+ Date: string;
44
+ Server: string;
45
+ "X-Powered-By": string;
46
+ }>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Informational responses (100–199)
3
+ */
4
+ type InformationalHttpStatusCode = 100 | 101 | 102 | 103;
5
+ /**
6
+ * Successful responses (200–299)
7
+ */
8
+ export type SuccessfulHttpStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;
9
+ /**
10
+ * Redirection messages (300–399)
11
+ */
12
+ export type RedirectionHttpStatusCode = 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
13
+ /**
14
+ * Client error responses (400–499)
15
+ */
16
+ type ClientErrorHttpStatusCode = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451;
17
+ /**
18
+ * Server error responses (500–599)
19
+ */
20
+ type ServerErrorHttpStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
21
+ /**
22
+ * Http status code (100~599)
23
+ */
24
+ export type HttpStatusCode = InformationalHttpStatusCode | SuccessfulHttpStatusCode | RedirectionHttpStatusCode | ClientErrorHttpStatusCode | ServerErrorHttpStatusCode;
25
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,4 @@
1
1
  export { routeHandlerFactory } from "./route-handler-factory";
2
- export type { ContentType, HttpStatusCode, TypedNextResponse } from "./types";
2
+ export type { TypedNextResponse } from "./types";
3
+ export type { ContentType } from "../lib/content-type-types";
4
+ export type { HttpStatusCode } from "../lib/http-status-code-types";
@@ -35,5 +35,7 @@ export interface MethodRouteDefinition<THttpMethod extends HttpMethod, TBindings
35
35
  <TV1 extends ValidationSchema = ValidationSchema, TV2 extends ValidationSchema = TV1, TR1 extends RouteResponse = RouteResponse, TR2 extends RequiredRouteResponse = RequiredRouteResponse>(handler1: Handler<TParams, TQuery, TV1, TR1>, handler2: Handler<TParams, TQuery, TV2, TR2>): HttpMethodMapping<THttpMethod, TParams, TR1 | TR2 | TOnErrorResponse, TV2>;
36
36
  <TV1 extends ValidationSchema = ValidationSchema, TV2 extends ValidationSchema = TV1, TV3 extends ValidationSchema = TV1 & TV2, TR1 extends RouteResponse = RouteResponse, TR2 extends RouteResponse = RouteResponse, TR3 extends RequiredRouteResponse = RequiredRouteResponse>(handler1: Handler<TParams, TQuery, TV1, TR1>, handler2: Handler<TParams, TQuery, TV2, TR2>, handler3: Handler<TParams, TQuery, TV3, TR3>): HttpMethodMapping<THttpMethod, TParams, TR1 | TR2 | TR3 | TOnErrorResponse, TV3>;
37
37
  <TV1 extends ValidationSchema = ValidationSchema, TV2 extends ValidationSchema = TV1, TV3 extends ValidationSchema = TV1 & TV2, TV4 extends ValidationSchema = TV1 & TV2 & TV3, TR1 extends RouteResponse = RouteResponse, TR2 extends RouteResponse = RouteResponse, TR3 extends RouteResponse = RouteResponse, TR4 extends RequiredRouteResponse = RequiredRouteResponse>(handler1: Handler<TParams, TQuery, TV1, TR1>, handler2: Handler<TParams, TQuery, TV2, TR2>, handler3: Handler<TParams, TQuery, TV3, TR3>, handler4: Handler<TParams, TQuery, TV4, TR4>): HttpMethodMapping<THttpMethod, TParams, TR1 | TR2 | TR3 | TR4 | TOnErrorResponse, TV4>;
38
+ <TV1 extends ValidationSchema = ValidationSchema, TV2 extends ValidationSchema = TV1, TV3 extends ValidationSchema = TV1 & TV2, TV4 extends ValidationSchema = TV1 & TV2 & TV3, TV5 extends ValidationSchema = TV1 & TV2 & TV3 & TV4, TR1 extends RouteResponse = RouteResponse, TR2 extends RouteResponse = RouteResponse, TR3 extends RouteResponse = RouteResponse, TR4 extends RouteResponse = RouteResponse, TR5 extends RequiredRouteResponse = RequiredRouteResponse>(handler1: Handler<TParams, TQuery, TV1, TR1>, handler2: Handler<TParams, TQuery, TV2, TR2>, handler3: Handler<TParams, TQuery, TV3, TR3>, handler4: Handler<TParams, TQuery, TV4, TR4>, handler5: Handler<TParams, TQuery, TV5, TR5>): HttpMethodMapping<THttpMethod, TParams, TR1 | TR2 | TR3 | TR4 | TR5 | TOnErrorResponse, TV5>;
39
+ <TV1 extends ValidationSchema = ValidationSchema, TV2 extends ValidationSchema = TV1, TV3 extends ValidationSchema = TV1 & TV2, TV4 extends ValidationSchema = TV1 & TV2 & TV3, TV5 extends ValidationSchema = TV1 & TV2 & TV3 & TV4, TV6 extends ValidationSchema = TV1 & TV2 & TV3 & TV4 & TV5, TR1 extends RouteResponse = RouteResponse, TR2 extends RouteResponse = RouteResponse, TR3 extends RouteResponse = RouteResponse, TR4 extends RouteResponse = RouteResponse, TR5 extends RouteResponse = RouteResponse, TR6 extends RequiredRouteResponse = RequiredRouteResponse>(handler1: Handler<TParams, TQuery, TV1, TR1>, handler2: Handler<TParams, TQuery, TV2, TR2>, handler3: Handler<TParams, TQuery, TV3, TR3>, handler4: Handler<TParams, TQuery, TV4, TR4>, handler5: Handler<TParams, TQuery, TV5, TR5>, handler6: Handler<TParams, TQuery, TV6, TR6>): HttpMethodMapping<THttpMethod, TParams, TR1 | TR2 | TR3 | TR4 | TR5 | TR6 | TOnErrorResponse, TV6>;
38
40
  }
39
41
  export {};
@@ -1,35 +1,8 @@
1
1
  import type { ValidationSchema } from "./route-types";
2
+ import type { ContentType } from "../lib/content-type-types";
3
+ import type { HttpResponseHeaders } from "../lib/http-response-headers-types";
4
+ import type { HttpStatusCode, RedirectionHttpStatusCode, SuccessfulHttpStatusCode } from "../lib/http-status-code-types";
2
5
  import type { NextResponse, NextRequest } from "next/server";
3
- type KnownContentType = "application/json" | "text/html" | "text/plain" | "application/javascript" | "text/css" | "image/png" | "image/jpeg" | "image/svg+xml" | "application/pdf" | "application/octet-stream" | "multipart/form-data" | "application/x-www-form-urlencoded";
4
- /**
5
- * A content type that can be either one of the predefined `KnownContentType` values,
6
- * or any other custom string.
7
- */
8
- export type ContentType = KnownContentType | (string & {});
9
- /**
10
- * Informational responses (100–199)
11
- */
12
- type InformationalHttpStatusCode = 100 | 101 | 102 | 103;
13
- /**
14
- * Successful responses (200–299)
15
- */
16
- type SuccessfulHttpStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;
17
- /**
18
- * Redirection messages (300–399)
19
- */
20
- export type RedirectionHttpStatusCode = 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
21
- /**
22
- * Client error responses (400–499)
23
- */
24
- type ClientErrorHttpStatusCode = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451;
25
- /**
26
- * Server error responses (500–599)
27
- */
28
- type ServerErrorHttpStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
29
- /**
30
- * Http status code (100~599)
31
- */
32
- export type HttpStatusCode = InformationalHttpStatusCode | SuccessfulHttpStatusCode | RedirectionHttpStatusCode | ClientErrorHttpStatusCode | ServerErrorHttpStatusCode;
33
6
  /**
34
7
  * Represents the result of an HTTP response status check.
35
8
  *
@@ -48,51 +21,6 @@ type HttpStatus<T extends HttpStatusCode> = T extends SuccessfulHttpStatusCode ?
48
21
  ok: false;
49
22
  status: Exclude<T, SuccessfulHttpStatusCode>;
50
23
  };
51
- /**
52
- * Represents HTTP response headers with optional fields, parameterized by the content type.
53
- * This type includes common headers used for caching, content description, CORS, authentication, security, cookies, redirects, connection, and server information.
54
- *
55
- * @template TContentType - The specific content type for the `Content-Type` header.
56
- */
57
- type HttpResponseHeaders<TContentType extends ContentType> = Partial<{
58
- "Cache-Control": string;
59
- Expires: string;
60
- ETag: string;
61
- "Last-Modified": string;
62
- "Content-Type": TContentType;
63
- "Content-Length": string;
64
- "Content-Encoding": string;
65
- "Content-Language": string;
66
- "Content-Location": string;
67
- "Content-Disposition": string;
68
- "Access-Control-Allow-Origin": string;
69
- "Access-Control-Allow-Credentials": string;
70
- "Access-Control-Allow-Headers": string;
71
- "Access-Control-Allow-Methods": string;
72
- "Access-Control-Expose-Headers": string;
73
- "WWW-Authenticate": string;
74
- Authorization: string;
75
- "Strict-Transport-Security": string;
76
- "Content-Security-Policy": string;
77
- "X-Content-Type-Options": string;
78
- "X-Frame-Options": string;
79
- "X-XSS-Protection": string;
80
- "Referrer-Policy": string;
81
- "Permissions-Policy": string;
82
- "Cross-Origin-Opener-Policy": string;
83
- "Cross-Origin-Embedder-Policy": string;
84
- "Cross-Origin-Resource-Policy": string;
85
- "Set-Cookie": string;
86
- Location: string;
87
- Connection: string;
88
- "Keep-Alive": string;
89
- "Transfer-Encoding": string;
90
- Upgrade: string;
91
- Vary: string;
92
- Date: string;
93
- Server: string;
94
- "X-Powered-By": string;
95
- }>;
96
24
  /**
97
25
  * Extension of the standard `ResponseInit` interface with strongly typed status and headers.
98
26
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rpc4next",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Inspired by Hono RPC and Pathpida, rpc4next brings a lightweight and intuitive RPC solution to Next.js, making server-client communication seamless",
5
5
  "author": "watanabe-1",
6
6
  "license": "MIT",