rpc4next 0.3.4 → 0.3.5
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/dist/rpc/cli/cli-handler.js +1 -48
- package/dist/rpc/cli/cli.js +1 -32
- package/dist/rpc/cli/constants.js +1 -9
- package/dist/rpc/cli/core/alias.js +1 -16
- package/dist/rpc/cli/core/cache.js +1 -30
- package/dist/rpc/cli/core/constants.js +2 -19
- package/dist/rpc/cli/core/generate-path-structure.js +1 -30
- package/dist/rpc/cli/core/path-utils.js +1 -24
- package/dist/rpc/cli/core/route-scanner.js +1 -189
- package/dist/rpc/cli/core/scan-utils.js +1 -44
- package/dist/rpc/cli/core/type-utils.js +1 -26
- package/dist/rpc/cli/debounce.js +1 -43
- package/dist/rpc/cli/generator.js +1 -28
- package/dist/rpc/cli/index.js +1 -4
- package/dist/rpc/cli/logger.js +1 -31
- package/dist/rpc/cli/types.js +0 -2
- package/dist/rpc/cli/watcher.js +1 -67
- package/dist/rpc/client/http-method.js +1 -88
- package/dist/rpc/client/index.js +1 -6
- package/dist/rpc/client/match.js +1 -30
- package/dist/rpc/client/rpc.js +1 -99
- package/dist/rpc/client/types.js +0 -2
- package/dist/rpc/client/url.js +1 -57
- package/dist/rpc/client/utils.js +1 -31
- package/dist/rpc/lib/constants.js +1 -9
- package/dist/rpc/lib/content-type-types.js +0 -2
- package/dist/rpc/lib/http-request-headers-types.js +0 -2
- package/dist/rpc/lib/http-response-headers-types.js +0 -2
- package/dist/rpc/lib/http-status-code-types.js +0 -2
- package/dist/rpc/lib/types.js +0 -2
- package/dist/rpc/server/create-handler.js +1 -10
- package/dist/rpc/server/create-route-context.js +1 -25
- package/dist/rpc/server/index.js +1 -5
- package/dist/rpc/server/route-handler-factory.js +1 -68
- package/dist/rpc/server/route-types.js +0 -2
- package/dist/rpc/server/search-params-to-object.js +1 -18
- package/dist/rpc/server/types.js +0 -2
- package/dist/rpc/server/validators/validator-utils.js +1 -31
- package/dist/rpc/server/validators/zod/index.js +1 -5
- package/dist/rpc/server/validators/zod/zod-validator.js +1 -53
- package/package.json +5 -2
- package/dist/index.js +0 -18
- package/dist/rpc/cli/cli-handler.d.ts +0 -2
- package/dist/rpc/cli/cli.d.ts +0 -2
- package/dist/rpc/cli/constants.d.ts +0 -7
- package/dist/rpc/cli/core/alias.d.ts +0 -1
- package/dist/rpc/cli/core/cache.d.ts +0 -14
- package/dist/rpc/cli/core/constants.d.ts +0 -11
- package/dist/rpc/cli/core/generate-path-structure.d.ts +0 -7
- package/dist/rpc/cli/core/path-utils.d.ts +0 -3
- package/dist/rpc/cli/core/route-scanner.d.ts +0 -28
- package/dist/rpc/cli/core/scan-utils.d.ts +0 -19
- package/dist/rpc/cli/core/type-utils.d.ts +0 -6
- package/dist/rpc/cli/debounce.d.ts +0 -1
- package/dist/rpc/cli/generator.d.ts +0 -7
- package/dist/rpc/cli/index.d.ts +0 -2
- package/dist/rpc/cli/logger.d.ts +0 -3
- package/dist/rpc/cli/types.d.ts +0 -21
- package/dist/rpc/cli/watcher.d.ts +0 -2
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*!
|
|
3
2
|
* Portions of this code are based on the Hono project (https://github.com/honojs/middleware/tree/main/packages/zod-validator),
|
|
4
3
|
* originally created by Yusuke Wada (https://github.com/yusukebe) and developed with
|
|
@@ -6,55 +5,4 @@
|
|
|
6
5
|
* This code has been adapted and modified for this project.
|
|
7
6
|
* Original copyright belongs to Yusuke Wada and the Hono project contributors.
|
|
8
7
|
* Hono is licensed under the MIT License.
|
|
9
|
-
*/
|
|
10
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
11
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
12
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
14
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
15
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
16
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.zodValidator = void 0;
|
|
21
|
-
const create_handler_1 = require("../../create-handler");
|
|
22
|
-
const validator_utils_1 = require("../validator-utils");
|
|
23
|
-
const zodValidator = (target, schema, hook) => {
|
|
24
|
-
const resolvedHook = hook !== null && hook !== void 0 ? hook : ((result, rc) => {
|
|
25
|
-
if (!result.success) {
|
|
26
|
-
return rc.json(result, { status: 400 });
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
return (0, create_handler_1.createHandler)()((rc) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
-
const value = yield (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
if (target === "params") {
|
|
32
|
-
return yield rc.req.params();
|
|
33
|
-
}
|
|
34
|
-
if (target === "query") {
|
|
35
|
-
return rc.req.query();
|
|
36
|
-
}
|
|
37
|
-
if (target === "json") {
|
|
38
|
-
return rc.req.json();
|
|
39
|
-
}
|
|
40
|
-
if (target === "headers") {
|
|
41
|
-
return yield (0, validator_utils_1.getHeadersObject)();
|
|
42
|
-
}
|
|
43
|
-
if (target === "cookies") {
|
|
44
|
-
return yield (0, validator_utils_1.getCookiesObject)();
|
|
45
|
-
}
|
|
46
|
-
}))();
|
|
47
|
-
const result = yield schema.safeParseAsync(value);
|
|
48
|
-
const hookResult = resolvedHook(result, rc);
|
|
49
|
-
if (hookResult instanceof Response) {
|
|
50
|
-
// If it's of type Response, it won't be void, so we're excluding void here
|
|
51
|
-
return hookResult;
|
|
52
|
-
}
|
|
53
|
-
if (!result.success) {
|
|
54
|
-
throw new Error("If you provide a custom hook, you must explicitly return a response when validation fails.");
|
|
55
|
-
}
|
|
56
|
-
// If validation succeeds, register it as validatedData
|
|
57
|
-
rc.req.addValidatedData(target, result.data);
|
|
58
|
-
}));
|
|
59
|
-
};
|
|
60
|
-
exports.zodValidator = zodValidator;
|
|
8
|
+
*/import{createHandler as u}from"../../create-handler";import{getCookiesObject as d,getHeadersObject as T}from"../validator-utils";const m=(a,i,r)=>{const s=r??((e,t)=>{if(!e.success)return t.json(e,{status:400})});return u()(async e=>{const t=await(async()=>{if(a==="params")return await e.req.params();if(a==="query")return e.req.query();if(a==="json")return e.req.json();if(a==="headers")return await T();if(a==="cookies")return await d()})(),o=await i.safeParseAsync(t),n=s(o,e);if(n instanceof Response)return n;if(!o.success)throw new Error("If you provide a custom hook, you must explicitly return a response when validation fails.");e.req.addValidatedData(a,o.data)})};export{m as zodValidator};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rpc4next",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
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",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"typescript",
|
|
19
19
|
"cli"
|
|
20
20
|
],
|
|
21
|
+
"type": "module",
|
|
21
22
|
"module": "dist/index.js",
|
|
22
23
|
"types": "dist/index.d.ts",
|
|
23
24
|
"files": [
|
|
@@ -59,7 +60,8 @@
|
|
|
59
60
|
}
|
|
60
61
|
},
|
|
61
62
|
"scripts": {
|
|
62
|
-
"build": "bun run clean &&
|
|
63
|
+
"build": "bun run clean && bun build.ts && bun run build:types",
|
|
64
|
+
"build:types": "tsc -p tsconfig.build-types.json",
|
|
63
65
|
"clean": "bun -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
64
66
|
"test": "vitest run",
|
|
65
67
|
"test:coverage": "vitest run --coverage.enabled true",
|
|
@@ -77,6 +79,7 @@
|
|
|
77
79
|
"@vitest/coverage-v8": "^3.1.1",
|
|
78
80
|
"@vitest/eslint-plugin": "^1.1.43",
|
|
79
81
|
"@vitest/ui": "^3.1.1",
|
|
82
|
+
"esbuild": "^0.25.2",
|
|
80
83
|
"eslint": "^9.24.0",
|
|
81
84
|
"eslint-config-prettier": "^10.1.2",
|
|
82
85
|
"eslint-plugin-import": "^2.31.0",
|
package/dist/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./rpc/server"), exports);
|
|
18
|
-
__exportStar(require("./rpc/client"), exports);
|
package/dist/rpc/cli/cli.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ErrorExitCode, SuccessExitCode } from "./types";
|
|
2
|
-
export declare const END_POINT_FILE_NAMES: readonly ["page.tsx", "route.ts"];
|
|
3
|
-
export declare const EXIT_SUCCESS: SuccessExitCode;
|
|
4
|
-
export declare const EXIT_FAILURE: ErrorExitCode;
|
|
5
|
-
export declare const SUCCESS_INDENT_LEVEL = 1;
|
|
6
|
-
export declare const SUCCESS_PAD_LENGTH = 20;
|
|
7
|
-
export declare const SUCCESS_SEPARATOR = "\u2192";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const createImportAlias: (path: string, name: string) => string;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const visitedDirsCache: Map<string, boolean>;
|
|
2
|
-
export declare const scanAppDirCache: Map<string, {
|
|
3
|
-
pathStructure: string;
|
|
4
|
-
imports: {
|
|
5
|
-
statement: string;
|
|
6
|
-
path: string;
|
|
7
|
-
}[];
|
|
8
|
-
paramsTypes: {
|
|
9
|
-
paramsType: string;
|
|
10
|
-
dirPath: string;
|
|
11
|
-
}[];
|
|
12
|
-
}>;
|
|
13
|
-
export declare const clearVisitedDirsCacheAbove: (targetPath: string) => void;
|
|
14
|
-
export declare const clearScanAppDirCacheAbove: (targetPath: string) => void;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const QUERY_TYPES: readonly ["Query", "OptionalQuery"];
|
|
2
|
-
export declare const INDENT = " ";
|
|
3
|
-
export declare const NEWLINE = "\n";
|
|
4
|
-
export declare const STATEMENT_TERMINATOR = ";";
|
|
5
|
-
export declare const TYPE_SEPARATOR = ";";
|
|
6
|
-
export declare const TYPE_END_POINT = "Endpoint";
|
|
7
|
-
export declare const TYPE_KEY_QUERY = "QueryKey";
|
|
8
|
-
export declare const TYPE_KEY_OPTIONAL_QUERY = "OptionalQueryKey";
|
|
9
|
-
export declare const TYPE_KEY_PARAMS = "ParamsKey";
|
|
10
|
-
export declare const TYPE_KEYS: string[];
|
|
11
|
-
export declare const RPC4NEXT_CLIENT_IMPORT_PATH = "rpc4next/client";
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Inspired by pathpida (https://github.com/aspida/pathpida),
|
|
3
|
-
* especially the design and UX of its CLI.
|
|
4
|
-
*/
|
|
5
|
-
type ImportObj = {
|
|
6
|
-
statement: string;
|
|
7
|
-
path: string;
|
|
8
|
-
};
|
|
9
|
-
type ParamsType = {
|
|
10
|
-
paramsType: string;
|
|
11
|
-
dirPath: string;
|
|
12
|
-
};
|
|
13
|
-
export declare const hasTargetFiles: (dirPath: string) => boolean;
|
|
14
|
-
export declare const scanAppDir: (output: string, input: string, indent?: string, parentParams?: {
|
|
15
|
-
paramName: string;
|
|
16
|
-
routeType: {
|
|
17
|
-
isDynamic: boolean;
|
|
18
|
-
isCatchAll: boolean;
|
|
19
|
-
isOptionalCatchAll: boolean;
|
|
20
|
-
isGroup: boolean;
|
|
21
|
-
isParallel: boolean;
|
|
22
|
-
};
|
|
23
|
-
}[]) => {
|
|
24
|
-
pathStructure: string;
|
|
25
|
-
imports: ImportObj[];
|
|
26
|
-
paramsTypes: ParamsType[];
|
|
27
|
-
};
|
|
28
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { HttpMethod } from "../../lib/types";
|
|
2
|
-
export declare const scanFile: <T extends string | undefined>(outputFile: string, inputFile: string, findCallBack: (fileContents: string) => T, typeCallBack: (type: NonNullable<T>, importAlias: string) => string) => {
|
|
3
|
-
importName: string;
|
|
4
|
-
importPath: string;
|
|
5
|
-
importStatement: string;
|
|
6
|
-
type: string;
|
|
7
|
-
} | undefined;
|
|
8
|
-
export declare const scanQuery: (outputFile: string, inputFile: string) => {
|
|
9
|
-
importName: string;
|
|
10
|
-
importPath: string;
|
|
11
|
-
importStatement: string;
|
|
12
|
-
type: string;
|
|
13
|
-
} | undefined;
|
|
14
|
-
export declare const scanRoute: (outputFile: string, inputFile: string, httpMethod: HttpMethod) => {
|
|
15
|
-
importName: string;
|
|
16
|
-
importPath: string;
|
|
17
|
-
importStatement: string;
|
|
18
|
-
type: string;
|
|
19
|
-
} | undefined;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const createRecodeType: (key: string, value: string) => string;
|
|
2
|
-
export declare const createObjectType: (fields: {
|
|
3
|
-
name: string;
|
|
4
|
-
type: string;
|
|
5
|
-
}[]) => string;
|
|
6
|
-
export declare const createImport: (type: string, path: string, importAlias?: string) => string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const debounceOnceRunningWithTrailing: <T extends (...args: any[]) => Promise<void> | void>(func: T, delay: number) => (...args: Parameters<T>) => void;
|
package/dist/rpc/cli/index.d.ts
DELETED
package/dist/rpc/cli/logger.d.ts
DELETED
package/dist/rpc/cli/types.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { END_POINT_FILE_NAMES } from "./constants";
|
|
2
|
-
export type EndPointFileNames = (typeof END_POINT_FILE_NAMES)[number];
|
|
3
|
-
export interface CliOptions {
|
|
4
|
-
watch?: boolean;
|
|
5
|
-
paramsFile?: string;
|
|
6
|
-
}
|
|
7
|
-
type LogOptions = {
|
|
8
|
-
indentLevel?: number;
|
|
9
|
-
event?: string;
|
|
10
|
-
};
|
|
11
|
-
export interface Logger {
|
|
12
|
-
info: (msg: string, options?: LogOptions) => void;
|
|
13
|
-
success: (msg: string, options?: Pick<LogOptions, "indentLevel">) => void;
|
|
14
|
-
error: (msg: string, options?: Pick<LogOptions, "indentLevel">) => void;
|
|
15
|
-
}
|
|
16
|
-
type BuildRange<N extends number, Result extends number[] = []> = Result["length"] extends N ? Result : BuildRange<N, [...Result, Result["length"]]>;
|
|
17
|
-
type NumericRange<F extends number, T extends number> = Exclude<BuildRange<T>, BuildRange<F>> | F;
|
|
18
|
-
export type SuccessExitCode = 0;
|
|
19
|
-
export type ErrorExitCode = NumericRange<1, 256>;
|
|
20
|
-
export type ExitCode = SuccessExitCode | ErrorExitCode;
|
|
21
|
-
export {};
|