orpc-file-based-router 0.1.4 → 0.1.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/README.md +4 -4
- package/dist/index.cjs +4 -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 +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,10 +9,6 @@ structure, inspired by Next.js and express-file-routing approaches.
|
|
|
9
9
|
- 🔄 **Zero Configuration**: Generate routes automatically based on your directory structure
|
|
10
10
|
- ⚡️ **Development Speed**: Eliminate boilerplate code and reduce maintenance overhead
|
|
11
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
|
-
|
|
14
|
-
> ⚠️ **IMPORTANT:** At this time, the plugin's functionality is only guaranteed
|
|
15
|
-
> in nodejs runtime
|
|
16
12
|
|
|
17
13
|
## Quickstart
|
|
18
14
|
|
|
@@ -103,6 +99,8 @@ generateRouter(routesDir, outputFile);
|
|
|
103
99
|
|
|
104
100
|
2. Generated router is ready to use in client:
|
|
105
101
|
|
|
102
|
+
> ⚠️ If you don't want plugin to generate openapi `route({})` suffix, just set parameter `includeRoute` to `false`
|
|
103
|
+
|
|
106
104
|
```typescript
|
|
107
105
|
// router.ts
|
|
108
106
|
import { me } from "./routes/auth/me";
|
|
@@ -131,6 +129,7 @@ export const router = {
|
|
|
131
129
|
sse: sse.route({ path: "/sse" }),
|
|
132
130
|
};
|
|
133
131
|
|
|
132
|
+
|
|
134
133
|
// lib/orpc.ts
|
|
135
134
|
const client: RouterClient<typeof router> = createORPCClient(link)
|
|
136
135
|
|
|
@@ -143,6 +142,7 @@ When using `generateRouter`, you can provide additional options to customize the
|
|
|
143
142
|
| Field | Type | Required | Default Value | Description |
|
|
144
143
|
|-------------------|----------|--------------|-----------------------|------------------------------------------------------------------------------------------------------------------------------|
|
|
145
144
|
| `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"` |
|
|
145
|
+
| `includeRoute` | boolean | false | `true` | When set to true, each route will be wrapped with openapi `.route({ path: '...' })` call |
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
|
package/dist/index.cjs
CHANGED
|
@@ -56,7 +56,10 @@ async function generateRouter(routesDir, outputFile, options) {
|
|
|
56
56
|
const exports = await generateRoutes(files);
|
|
57
57
|
const importPaths = exports.map((x) => path.relative(path.dirname(outputFile), routesDir).concat(x.path));
|
|
58
58
|
const content = buildRouter(exports, (r, e) => {
|
|
59
|
-
|
|
59
|
+
if (options?.includeRoute ?? true) {
|
|
60
|
+
return `${e}.route({ path: '${r.path.replace(/\/{0,1}index$/, "")}' })`;
|
|
61
|
+
}
|
|
62
|
+
return e;
|
|
60
63
|
});
|
|
61
64
|
let routerContent = `// This file is auto-generated
|
|
62
65
|
|
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,12 @@ type GeneratorOptions = {
|
|
|
11
11
|
* @default "" (no extension)
|
|
12
12
|
*/
|
|
13
13
|
importExtension?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Include openapi route paths in the generated router.
|
|
16
|
+
* When set to true, each route will have its openapi path
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
includeRoute?: boolean;
|
|
14
20
|
};
|
|
15
21
|
declare function generateRouter(routesDir: string, outputFile: string, options?: GeneratorOptions): Promise<void>;
|
|
16
22
|
type Router = Record<string, any>;
|
package/dist/index.d.mts
CHANGED
|
@@ -11,6 +11,12 @@ type GeneratorOptions = {
|
|
|
11
11
|
* @default "" (no extension)
|
|
12
12
|
*/
|
|
13
13
|
importExtension?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Include openapi route paths in the generated router.
|
|
16
|
+
* When set to true, each route will have its openapi path
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
includeRoute?: boolean;
|
|
14
20
|
};
|
|
15
21
|
declare function generateRouter(routesDir: string, outputFile: string, options?: GeneratorOptions): Promise<void>;
|
|
16
22
|
type Router = Record<string, any>;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ type GeneratorOptions = {
|
|
|
11
11
|
* @default "" (no extension)
|
|
12
12
|
*/
|
|
13
13
|
importExtension?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Include openapi route paths in the generated router.
|
|
16
|
+
* When set to true, each route will have its openapi path
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
includeRoute?: boolean;
|
|
14
20
|
};
|
|
15
21
|
declare function generateRouter(routesDir: string, outputFile: string, options?: GeneratorOptions): Promise<void>;
|
|
16
22
|
type Router = Record<string, any>;
|
package/dist/index.mjs
CHANGED
|
@@ -50,7 +50,10 @@ async function generateRouter(routesDir, outputFile, options) {
|
|
|
50
50
|
const exports = await generateRoutes(files);
|
|
51
51
|
const importPaths = exports.map((x) => relative(dirname(outputFile), routesDir).concat(x.path));
|
|
52
52
|
const content = buildRouter(exports, (r, e) => {
|
|
53
|
-
|
|
53
|
+
if (options?.includeRoute ?? true) {
|
|
54
|
+
return `${e}.route({ path: '${r.path.replace(/\/{0,1}index$/, "")}' })`;
|
|
55
|
+
}
|
|
56
|
+
return e;
|
|
54
57
|
});
|
|
55
58
|
let routerContent = `// This file is auto-generated
|
|
56
59
|
|
package/package.json
CHANGED