orpc-file-based-router 0.1.0 → 0.1.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.
- package/README.md +23 -13
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# orpc-file-based-router
|
|
2
2
|
|
|
3
|
-
A plugin for [oRPC](https://orpc.unnoq.com) that automatically
|
|
4
|
-
structure,
|
|
3
|
+
A plugin for [oRPC](https://orpc.unnoq.com) that automatically generates an oRPC router configuration based on your file
|
|
4
|
+
structure, inspired by Next.js and express-file-routing approaches.
|
|
5
5
|
|
|
6
|
-
## Highlights
|
|
6
|
+
## ✨ Highlights
|
|
7
7
|
|
|
8
|
-
- 📁 **File-based
|
|
9
|
-
- 🔄 **Zero
|
|
10
|
-
- ⚡️ **Development
|
|
11
|
-
- 🔍 **Dynamic
|
|
12
|
-
- 📑 **Index
|
|
8
|
+
- 📁 **File-based Structure**: Organize your API endpoints intuitively through your filesystem
|
|
9
|
+
- 🔄 **Zero Configuration**: Generate routes automatically based on your directory structure
|
|
10
|
+
- ⚡️ **Development Speed**: Eliminate boilerplate code and reduce maintenance overhead
|
|
11
|
+
- 🔍 **Dynamic Routing**: Support for path parameters using `{param}` syntax in file names
|
|
12
|
+
- 📑 **Index Routes**: Support for index routes via `index.ts` files
|
|
13
13
|
|
|
14
14
|
> ⚠️ **IMPORTANT:** At this time, the plugin's functionality is only guaranteed
|
|
15
15
|
> in nodejs runtime
|
|
@@ -72,11 +72,11 @@ const handler = new RPCHandler(router);
|
|
|
72
72
|
> startServer();
|
|
73
73
|
> ```
|
|
74
74
|
|
|
75
|
-
## Type-Safe Client Configuration (Optional)
|
|
75
|
+
## 🔒 Type-Safe Client Configuration (Optional)
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
For users of the [oRPC client](https://orpc.unnoq.com/docs/client/client-side), we provide automatic configuration generation for enhanced type safety and improved developer experience.
|
|
78
78
|
|
|
79
|
-
1. Add the following code to your main server file (e.g., `server.ts` or `main.ts`)
|
|
79
|
+
1. Add the following code to your main server file (e.g., `server.ts` or `main.ts`). This will automatically regenerate the router configuration each time your server starts:
|
|
80
80
|
|
|
81
81
|
```typescript
|
|
82
82
|
import { generateRouter } from "orpc-file-based-router";
|
|
@@ -121,6 +121,16 @@ const client: RouterClient<typeof router> = createORPCClient(link)
|
|
|
121
121
|
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
##
|
|
124
|
+
## 🛠 Configuration Options
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
When using `generateRouter`, you can provide additional options to customize the output:
|
|
127
|
+
|
|
128
|
+
| Field | Type | Required | Default Value | Description |
|
|
129
|
+
|-------------------|----------|--------------|-----------------------|------------------------------------------------------------------------------------------------------------------------------|
|
|
130
|
+
| `importExtension` | string | false | `""`(No extension) | File extension to append to import statements in the generated router. Useful when your build setup requires specific extensions. <br>Example: `.js` → `import { me } from "./routes/auth/me.js"` |
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
## 📄 License
|
|
135
|
+
|
|
136
|
+
MIT License - feel free to use this in your own projects!
|
package/dist/index.cjs
CHANGED
|
@@ -43,7 +43,7 @@ async function generateRouter(routesDir, outputFile, options) {
|
|
|
43
43
|
const exports = await generateRoutes(files);
|
|
44
44
|
const importPaths = exports.map((x) => path.relative(path.dirname(outputFile), routesDir).concat(x.path));
|
|
45
45
|
const content = buildRouter(exports, (r, e) => {
|
|
46
|
-
return `${e}.route({ path: '${r.path}' })`;
|
|
46
|
+
return `${e}.route({ path: '${r.path.replace(/\/{0,1}index$/, "")}' })`;
|
|
47
47
|
});
|
|
48
48
|
let routerContent = `// This file is auto-generated
|
|
49
49
|
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
declare function createRouter(routesDir: string): Promise<Router>;
|
|
2
2
|
type GeneratorOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* File extension to append to import statements in the generated router.
|
|
5
|
+
* Useful when your build setup requires specific extensions.
|
|
6
|
+
* @example ".js" will generate imports like: import { me } from "./routes/auth/me.js"
|
|
7
|
+
* @default "" (no extension)
|
|
8
|
+
*/
|
|
3
9
|
importExtension?: string;
|
|
4
10
|
};
|
|
5
11
|
declare function generateRouter(routesDir: string, outputFile: string, options?: GeneratorOptions): Promise<void>;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
declare function createRouter(routesDir: string): Promise<Router>;
|
|
2
2
|
type GeneratorOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* File extension to append to import statements in the generated router.
|
|
5
|
+
* Useful when your build setup requires specific extensions.
|
|
6
|
+
* @example ".js" will generate imports like: import { me } from "./routes/auth/me.js"
|
|
7
|
+
* @default "" (no extension)
|
|
8
|
+
*/
|
|
3
9
|
importExtension?: string;
|
|
4
10
|
};
|
|
5
11
|
declare function generateRouter(routesDir: string, outputFile: string, options?: GeneratorOptions): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
declare function createRouter(routesDir: string): Promise<Router>;
|
|
2
2
|
type GeneratorOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* File extension to append to import statements in the generated router.
|
|
5
|
+
* Useful when your build setup requires specific extensions.
|
|
6
|
+
* @example ".js" will generate imports like: import { me } from "./routes/auth/me.js"
|
|
7
|
+
* @default "" (no extension)
|
|
8
|
+
*/
|
|
3
9
|
importExtension?: string;
|
|
4
10
|
};
|
|
5
11
|
declare function generateRouter(routesDir: string, outputFile: string, options?: GeneratorOptions): Promise<void>;
|
package/dist/index.mjs
CHANGED
|
@@ -37,7 +37,7 @@ async function generateRouter(routesDir, outputFile, options) {
|
|
|
37
37
|
const exports = await generateRoutes(files);
|
|
38
38
|
const importPaths = exports.map((x) => relative(dirname(outputFile), routesDir).concat(x.path));
|
|
39
39
|
const content = buildRouter(exports, (r, e) => {
|
|
40
|
-
return `${e}.route({ path: '${r.path}' })`;
|
|
40
|
+
return `${e}.route({ path: '${r.path.replace(/\/{0,1}index$/, "")}' })`;
|
|
41
41
|
});
|
|
42
42
|
let routerContent = `// This file is auto-generated
|
|
43
43
|
|
package/package.json
CHANGED