rpc4next 0.3.3 → 0.3.4

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.
@@ -125,9 +125,8 @@ const scanAppDir = (output, input, indent = "", parentParams = []) => {
125
125
  if (isSkipDir) {
126
126
  // Extract only the inner part inside `{}` from the child output
127
127
  const match = childPathStructure.match(/^\s*\{([\s\S]*)\}\s*$/);
128
- const childContent = match ? match[1].trim() : "";
129
- if (childContent) {
130
- pathStructures.push(`${currentIndent}${childContent}`);
128
+ if (match) {
129
+ pathStructures.push(`${currentIndent}${match[1].trim()}`);
131
130
  }
132
131
  }
133
132
  else {
@@ -33,10 +33,10 @@ const debounceOnceRunningWithTrailing = (func, delay) => {
33
33
  clearTimeout(timer);
34
34
  timer = setTimeout(() => {
35
35
  if (isRunning) {
36
- pendingArgs = args !== null && args !== void 0 ? args : [];
36
+ pendingArgs = args;
37
37
  return;
38
38
  }
39
- execute(...(args !== null && args !== void 0 ? args : []));
39
+ execute(...args);
40
40
  }, delay);
41
41
  };
42
42
  };
@@ -12,16 +12,16 @@ const url_1 = require("./url");
12
12
  const utils_1 = require("./utils");
13
13
  const createRpcProxy = (options, paths = [], params = {}, dynamicKeys = []) => {
14
14
  const proxy = new Proxy((value) => {
15
- var _a, _b;
15
+ const pathKey = paths.at(-1);
16
+ const paramKey = dynamicKeys.at(-1);
16
17
  if (value === undefined) {
17
- return (0, exports.createRpcProxy)(options, [...paths], params, dynamicKeys);
18
+ throw new Error(`An argument is required when calling the function for paramKey: ${paramKey}`);
18
19
  }
19
- const newKey = (_a = paths.at(-1)) !== null && _a !== void 0 ? _a : "";
20
- if ((0, utils_1.isDynamic)(newKey)) {
20
+ if (pathKey && paramKey && (0, utils_1.isDynamic)(pathKey)) {
21
21
  // Treat as a dynamic parameter
22
- return (0, exports.createRpcProxy)(options, [...paths], Object.assign(Object.assign({}, params), { [(_b = dynamicKeys.at(-1)) !== null && _b !== void 0 ? _b : ""]: value }), dynamicKeys);
22
+ return (0, exports.createRpcProxy)(options, [...paths], Object.assign(Object.assign({}, params), { [paramKey]: value }), dynamicKeys);
23
23
  }
24
- return (0, exports.createRpcProxy)(options, [...paths], params, dynamicKeys);
24
+ throw new Error(`paramKey: ${pathKey} is not a dynamic parameter and cannot be called as a function`);
25
25
  }, {
26
26
  get: (_, key) => {
27
27
  if (key === "$url") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rpc4next",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
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",
@@ -59,11 +59,11 @@
59
59
  }
60
60
  },
61
61
  "scripts": {
62
- "build": "npm run clean && tsc -p tsconfig.build.json",
63
- "build:bun": "npm run clean:bun && tsc -p tsconfig.build.json",
64
- "clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
65
- "clean:bun": "bun -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
62
+ "build": "bun run clean && tsc -p tsconfig.build.json",
63
+ "clean": "bun -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
66
64
  "test": "vitest run",
65
+ "test:coverage": "vitest run --coverage.enabled true",
66
+ "test:ui": "vitest --ui --coverage.enabled true",
67
67
  "test:watch": "vitest --watch",
68
68
  "lint": "eslint \"**/*.ts\"",
69
69
  "lint:fix": "eslint \"**/*.ts\" --fix"
@@ -74,7 +74,9 @@
74
74
  },
75
75
  "devDependencies": {
76
76
  "@types/node": "^22.14.1",
77
+ "@vitest/coverage-v8": "^3.1.1",
77
78
  "@vitest/eslint-plugin": "^1.1.43",
79
+ "@vitest/ui": "^3.1.1",
78
80
  "eslint": "^9.24.0",
79
81
  "eslint-config-prettier": "^10.1.2",
80
82
  "eslint-plugin-import": "^2.31.0",