rpc4next 0.3.4 → 0.3.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.
Files changed (59) hide show
  1. package/dist/rpc/cli/index.js +6 -4
  2. package/dist/rpc/client/http-method.js +1 -88
  3. package/dist/rpc/client/index.js +1 -6
  4. package/dist/rpc/client/match.js +1 -30
  5. package/dist/rpc/client/rpc.js +1 -99
  6. package/dist/rpc/client/types.js +0 -2
  7. package/dist/rpc/client/url.js +1 -57
  8. package/dist/rpc/client/utils.js +1 -31
  9. package/dist/rpc/lib/constants.js +1 -9
  10. package/dist/rpc/lib/content-type-types.js +0 -2
  11. package/dist/rpc/lib/http-request-headers-types.js +0 -2
  12. package/dist/rpc/lib/http-response-headers-types.js +0 -2
  13. package/dist/rpc/lib/http-status-code-types.js +0 -2
  14. package/dist/rpc/lib/types.js +0 -2
  15. package/dist/rpc/server/create-handler.js +1 -10
  16. package/dist/rpc/server/create-route-context.js +1 -25
  17. package/dist/rpc/server/index.js +1 -5
  18. package/dist/rpc/server/route-handler-factory.js +1 -68
  19. package/dist/rpc/server/route-types.js +0 -2
  20. package/dist/rpc/server/search-params-to-object.js +1 -18
  21. package/dist/rpc/server/types.js +0 -2
  22. package/dist/rpc/server/validators/validator-utils.js +1 -31
  23. package/dist/rpc/server/validators/zod/index.js +1 -5
  24. package/dist/rpc/server/validators/zod/zod-validator.js +1 -53
  25. package/package.json +6 -2
  26. package/dist/index.js +0 -18
  27. package/dist/rpc/cli/cli-handler.d.ts +0 -2
  28. package/dist/rpc/cli/cli-handler.js +0 -48
  29. package/dist/rpc/cli/cli.d.ts +0 -2
  30. package/dist/rpc/cli/cli.js +0 -32
  31. package/dist/rpc/cli/constants.d.ts +0 -7
  32. package/dist/rpc/cli/constants.js +0 -9
  33. package/dist/rpc/cli/core/alias.d.ts +0 -1
  34. package/dist/rpc/cli/core/alias.js +0 -16
  35. package/dist/rpc/cli/core/cache.d.ts +0 -14
  36. package/dist/rpc/cli/core/cache.js +0 -30
  37. package/dist/rpc/cli/core/constants.d.ts +0 -11
  38. package/dist/rpc/cli/core/constants.js +0 -19
  39. package/dist/rpc/cli/core/generate-path-structure.d.ts +0 -7
  40. package/dist/rpc/cli/core/generate-path-structure.js +0 -30
  41. package/dist/rpc/cli/core/path-utils.d.ts +0 -3
  42. package/dist/rpc/cli/core/path-utils.js +0 -24
  43. package/dist/rpc/cli/core/route-scanner.d.ts +0 -28
  44. package/dist/rpc/cli/core/route-scanner.js +0 -192
  45. package/dist/rpc/cli/core/scan-utils.d.ts +0 -19
  46. package/dist/rpc/cli/core/scan-utils.js +0 -44
  47. package/dist/rpc/cli/core/type-utils.d.ts +0 -6
  48. package/dist/rpc/cli/core/type-utils.js +0 -26
  49. package/dist/rpc/cli/debounce.d.ts +0 -1
  50. package/dist/rpc/cli/debounce.js +0 -43
  51. package/dist/rpc/cli/generator.d.ts +0 -7
  52. package/dist/rpc/cli/generator.js +0 -28
  53. package/dist/rpc/cli/index.d.ts +0 -2
  54. package/dist/rpc/cli/logger.d.ts +0 -3
  55. package/dist/rpc/cli/logger.js +0 -31
  56. package/dist/rpc/cli/types.d.ts +0 -21
  57. package/dist/rpc/cli/types.js +0 -2
  58. package/dist/rpc/cli/watcher.d.ts +0 -2
  59. package/dist/rpc/cli/watcher.js +0 -67
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.scanRoute = exports.scanQuery = exports.scanFile = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const alias_1 = require("./alias");
9
- const constants_1 = require("./constants");
10
- const path_utils_1 = require("./path-utils");
11
- const type_utils_1 = require("./type-utils");
12
- const scanFile = (outputFile, inputFile, findCallBack, typeCallBack) => {
13
- const fileContents = fs_1.default.readFileSync(inputFile, "utf8");
14
- const type = findCallBack(fileContents);
15
- if (!type)
16
- return;
17
- const relativeImportPath = (0, path_utils_1.createRelativeImportPath)(outputFile, inputFile);
18
- const importAlias = (0, alias_1.createImportAlias)(relativeImportPath, type);
19
- return {
20
- importName: importAlias,
21
- importPath: relativeImportPath,
22
- importStatement: (0, type_utils_1.createImport)(type, relativeImportPath, importAlias),
23
- type: typeCallBack(type, importAlias),
24
- };
25
- };
26
- exports.scanFile = scanFile;
27
- // Create query definitions
28
- const scanQuery = (outputFile, inputFile) => {
29
- return (0, exports.scanFile)(outputFile, inputFile, (fileContents) => {
30
- return constants_1.QUERY_TYPES.find((type) => new RegExp(`export (interface ${type} ?{|type ${type} ?=)`).test(fileContents));
31
- }, (type, importAlias) => type === "Query"
32
- ? (0, type_utils_1.createRecodeType)(constants_1.TYPE_KEY_QUERY, importAlias)
33
- : (0, type_utils_1.createRecodeType)(constants_1.TYPE_KEY_OPTIONAL_QUERY, importAlias));
34
- };
35
- exports.scanQuery = scanQuery;
36
- // Create route definitions
37
- const scanRoute = (outputFile, inputFile, httpMethod) => {
38
- return (0, exports.scanFile)(outputFile, inputFile, (fileContents) => {
39
- return [httpMethod].find((method) => new RegExp(`export (async )?(function ${method} ?\\(|const ${method} ?=|\\{[^}]*\\b${method}\\b[^}]*\\} ?=|const \\{[^}]*\\b${method}\\b[^}]*\\} ?=|\\{[^}]*\\b${method}\\b[^}]*\\} from)`).test(fileContents));
40
- }, (type, importAlias) => (0, type_utils_1.createObjectType)([
41
- { name: `$${type.toLowerCase()}`, type: `typeof ${importAlias}` },
42
- ]));
43
- };
44
- exports.scanRoute = scanRoute;
@@ -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,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createImport = exports.createObjectType = exports.createRecodeType = void 0;
4
- const constants_1 = require("./constants");
5
- const createRecodeType = (key, value) => {
6
- if (!key || !value)
7
- return "";
8
- return `Record<${key}, ${value}>`;
9
- };
10
- exports.createRecodeType = createRecodeType;
11
- const createObjectType = (fields) => {
12
- if (fields.length === 0 || fields.some(({ name, type }) => !name || !type))
13
- return "";
14
- return `{ ${fields
15
- .map(({ name, type }) => `"${name}": ${type}`)
16
- .join(`${constants_1.TYPE_SEPARATOR} `)}${fields.length > 1 ? constants_1.TYPE_SEPARATOR : ""} }`;
17
- };
18
- exports.createObjectType = createObjectType;
19
- const createImport = (type, path, importAlias) => {
20
- if (!type || !path)
21
- return "";
22
- return importAlias
23
- ? `import type { ${type} as ${importAlias} } from "${path}"${constants_1.STATEMENT_TERMINATOR}`
24
- : `import type { ${type} } from "${path}"${constants_1.STATEMENT_TERMINATOR}`;
25
- };
26
- exports.createImport = createImport;
@@ -1 +0,0 @@
1
- export declare const debounceOnceRunningWithTrailing: <T extends (...args: any[]) => Promise<void> | void>(func: T, delay: number) => (...args: Parameters<T>) => void;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.debounceOnceRunningWithTrailing = void 0;
13
- const debounceOnceRunningWithTrailing = (func, delay) => {
14
- let timer = null;
15
- let isRunning = false;
16
- let pendingArgs = null;
17
- const execute = (...args) => __awaiter(void 0, void 0, void 0, function* () {
18
- isRunning = true;
19
- try {
20
- yield func(...args);
21
- }
22
- finally {
23
- isRunning = false;
24
- if (pendingArgs) {
25
- const nextArgs = pendingArgs;
26
- pendingArgs = null;
27
- execute(...nextArgs);
28
- }
29
- }
30
- });
31
- return (...args) => {
32
- if (timer)
33
- clearTimeout(timer);
34
- timer = setTimeout(() => {
35
- if (isRunning) {
36
- pendingArgs = args;
37
- return;
38
- }
39
- execute(...args);
40
- }, delay);
41
- };
42
- };
43
- exports.debounceOnceRunningWithTrailing = debounceOnceRunningWithTrailing;
@@ -1,7 +0,0 @@
1
- import type { Logger } from "./types";
2
- export declare const generate: ({ baseDir, outputPath, paramsFileName, logger, }: {
3
- baseDir: string;
4
- outputPath: string;
5
- paramsFileName: string | null;
6
- logger: Logger;
7
- }) => void;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generate = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const constants_1 = require("./constants");
10
- const generate_path_structure_1 = require("./core/generate-path-structure");
11
- const path_utils_1 = require("./core/path-utils");
12
- const logger_1 = require("./logger");
13
- const generate = ({ baseDir, outputPath, paramsFileName, logger, }) => {
14
- logger.info("Generating types...", { event: "generate" });
15
- const { pathStructure, paramsTypes } = (0, generate_path_structure_1.generatePages)(outputPath, baseDir);
16
- fs_1.default.writeFileSync(outputPath, pathStructure);
17
- logger.success((0, logger_1.padMessage)("Path structure type", (0, path_utils_1.relativeFromRoot)(outputPath), constants_1.SUCCESS_SEPARATOR, constants_1.SUCCESS_PAD_LENGTH), { indentLevel: constants_1.SUCCESS_INDENT_LEVEL });
18
- if (paramsFileName) {
19
- paramsTypes.forEach(({ paramsType, dirPath }) => {
20
- const filePath = path_1.default.join(dirPath, paramsFileName);
21
- fs_1.default.writeFileSync(filePath, paramsType);
22
- });
23
- logger.success((0, logger_1.padMessage)("Params types", paramsFileName, constants_1.SUCCESS_SEPARATOR, constants_1.SUCCESS_PAD_LENGTH), {
24
- indentLevel: constants_1.SUCCESS_INDENT_LEVEL,
25
- });
26
- }
27
- };
28
- exports.generate = generate;
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,3 +0,0 @@
1
- import type { Logger } from "./types";
2
- export declare const padMessage: (label: string, value: string, separator?: string, targetLength?: number) => string;
3
- export declare const createLogger: () => Logger;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createLogger = exports.padMessage = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
8
- const constants_1 = require("./core/constants");
9
- const padMessage = (label, value, separator = "→", targetLength = 24) => {
10
- return label.padEnd(targetLength) + ` ${separator} ${value}`;
11
- };
12
- exports.padMessage = padMessage;
13
- const createIndent = (level = 0) => constants_1.INDENT.repeat(level);
14
- const createLogger = () => {
15
- return {
16
- info: (msg, options = {}) => {
17
- const { indentLevel = 0, event } = options;
18
- const prefix = event ? `${chalk_1.default.cyan(`[${event}]`)} ` : "";
19
- console.log(`${createIndent(indentLevel)}${prefix}${msg}`);
20
- },
21
- success: (msg, options = {}) => {
22
- const { indentLevel = 0 } = options;
23
- console.log(`${createIndent(indentLevel)}${chalk_1.default.green("✓")} ${msg}`);
24
- },
25
- error: (msg, options = {}) => {
26
- const { indentLevel = 0 } = options;
27
- console.error(`${createIndent(indentLevel)}${chalk_1.default.red("✗")} ${chalk_1.default.red(msg)}`);
28
- },
29
- };
30
- };
31
- exports.createLogger = createLogger;
@@ -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 {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- import type { Logger } from "./types";
2
- export declare const setupWatcher: (baseDir: string, onGenerate: () => void, logger: Logger) => void;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.setupWatcher = void 0;
7
- const chokidar_1 = __importDefault(require("chokidar"));
8
- const constants_1 = require("./constants");
9
- const cache_1 = require("./core/cache");
10
- const path_utils_1 = require("./core/path-utils");
11
- const debounce_1 = require("./debounce");
12
- const setupWatcher = (baseDir, onGenerate, logger) => {
13
- logger.info(`${(0, path_utils_1.relativeFromRoot)(baseDir)}`, {
14
- event: "watch",
15
- });
16
- const isTargetFiles = (path) => constants_1.END_POINT_FILE_NAMES.some((fileName) => path.endsWith(fileName));
17
- const changedPaths = new Set();
18
- // Once the debounced function starts executing, no new watcher events will be processed until it completes.
19
- // This is due to JavaScript's single-threaded event loop: the current debounced function runs to completion,
20
- // and any new change events are queued until the execution finishes.
21
- const debouncedGenerate = (0, debounce_1.debounceOnceRunningWithTrailing)(() => {
22
- changedPaths.forEach((path) => {
23
- (0, cache_1.clearVisitedDirsCacheAbove)(path);
24
- (0, cache_1.clearScanAppDirCacheAbove)(path);
25
- });
26
- changedPaths.clear();
27
- onGenerate();
28
- }, 300);
29
- const watcher = chokidar_1.default.watch(baseDir, {
30
- ignoreInitial: true,
31
- // If we exclude everything except files using ignored, the watch mode will terminate, so we added "only files" to the exclusion condition.
32
- ignored: (path, stats) => !!(stats === null || stats === void 0 ? void 0 : stats.isFile()) && !isTargetFiles(path),
33
- });
34
- watcher.on("ready", () => {
35
- // First execution
36
- debouncedGenerate();
37
- watcher.on("all", (event, filePath) => {
38
- if (isTargetFiles(filePath)) {
39
- const relativePath = (0, path_utils_1.relativeFromRoot)(filePath);
40
- logger.info(relativePath, { event });
41
- changedPaths.add(filePath);
42
- debouncedGenerate();
43
- }
44
- });
45
- });
46
- watcher.on("error", (error) => {
47
- if (error instanceof Error) {
48
- logger.error(`Watcher error: ${error.message}`);
49
- }
50
- else {
51
- logger.error(`Unknown watcher error: ${String(error)}`);
52
- }
53
- });
54
- const cleanup = () => {
55
- watcher
56
- .close()
57
- .then(() => {
58
- logger.info("Watcher closed.", { event: "watch" });
59
- })
60
- .catch((err) => {
61
- logger.error(`Failed to close watcher: ${err.message}`);
62
- });
63
- };
64
- process.on("SIGINT", cleanup);
65
- process.on("SIGTERM", cleanup);
66
- };
67
- exports.setupWatcher = setupWatcher;