elysia-autoload 1.2.0 → 1.3.0
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 +6 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -6
- package/package.json +1 -1
package/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Plugin for [Elysia](https://elysiajs.com/) which autoload all routes in directory and code-generate types for [Eden](https://elysiajs.com/eden/overview.html) with [`Bun.build`](#bun-build-usage) support!
|
4
4
|
|
5
|
-
**Currently, Eden types generation is broken!!**
|
5
|
+
**Currently, Eden types generation is broken!!** Feels free to send PR
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -65,6 +65,9 @@ Guide how `elysia-autoload` match routes
|
|
65
65
|
└──index.ts
|
66
66
|
├── frontend
|
67
67
|
└──index.tsx // usage of tsx extension
|
68
|
+
├── events
|
69
|
+
└──(post).ts // post and get will not be in the link
|
70
|
+
└──(get).ts
|
68
71
|
└── users.ts
|
69
72
|
└── package.json
|
70
73
|
```
|
@@ -76,6 +79,8 @@ Guide how `elysia-autoload` match routes
|
|
76
79
|
- /routes/likes/[...].ts → /likes/\*
|
77
80
|
- /routes/domains/@[...]/index.ts → /domains/@\*
|
78
81
|
- /routes/frontend/index.tsx → /frontend
|
82
|
+
- /routes/events/(post).ts → /events
|
83
|
+
- /routes/events/(get).ts → /events
|
79
84
|
|
80
85
|
## Options
|
81
86
|
|
package/dist/index.d.ts
CHANGED
@@ -16,7 +16,7 @@ type FlattenIndexRoutes<T> = T extends object ? {
|
|
16
16
|
[K in keyof T as K extends "index" ? T[K] extends RouteEndType ? never : K : K]: FlattenIndexRoutes<T[K]>;
|
17
17
|
} & (T extends {
|
18
18
|
index: infer I;
|
19
|
-
} ? I extends RouteEndType ? FlattenIndexRoutes<I> :
|
19
|
+
} ? I extends RouteEndType ? FlattenIndexRoutes<I> : T : T) : T;
|
20
20
|
type ElysiaWithBaseUrl<BaseUrl extends string, ElysiaType extends Elysia<any, any, any, any, any, any, any, any>> = ElysiaType extends Elysia<infer BasePath, infer Scoped, infer Singleton, infer Definitions, infer Metadata, infer Routes, infer Ephemeral, infer Volatile> ? Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, FlattenIndexRoutes<PathToObject<BaseUrl, Routes>>, Ephemeral, Volatile> : never;
|
21
21
|
type SoftString<T extends string> = T | (string & {});
|
22
22
|
|
package/dist/index.js
CHANGED
@@ -22,6 +22,10 @@ function transformToUrl(path2) {
|
|
22
22
|
regex: /\[(.*?)\]/gu,
|
23
23
|
replacement: (_, match) => `:${match}`
|
24
24
|
},
|
25
|
+
{
|
26
|
+
regex: /\/?\((.*)\)/,
|
27
|
+
replacement: ""
|
28
|
+
},
|
25
29
|
// Handle the case when multiple parameters are present in one file
|
26
30
|
// users / [id] - [name].ts to users /: id -:name and users / [id] - [name] / [age].ts to users /: id -: name /: age
|
27
31
|
{ regex: /\]-\[/gu, replacement: "-:" },
|
@@ -109,12 +113,6 @@ async function autoload(options = {}) {
|
|
109
113
|
const url = transformToUrl(filePath);
|
110
114
|
const groupOptions = schema ? schema({ path: filePath, url }) : {};
|
111
115
|
const importedValue = file[importName];
|
112
|
-
console.log(
|
113
|
-
importedValue.toString(),
|
114
|
-
importedValue.length,
|
115
|
-
typeof importedValue === "function" && !importedValue.length,
|
116
|
-
importedValue instanceof Elysia
|
117
|
-
);
|
118
116
|
if (typeof importedValue === "function" && importedValue.length)
|
119
117
|
plugin.group(url, groupOptions, importedValue);
|
120
118
|
if (typeof importedValue === "function" && !importedValue.length)
|