elysia-autoload 1.0.0 → 1.1.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 +49 -6
- package/dist/index.d.ts +3 -3
- package/dist/index.js +51 -33
- package/package.json +17 -13
- package/dist/index.cjs +0 -150
- package/dist/index.d.cts +0 -47
package/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# elysia-autoload
|
2
2
|
|
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`](
|
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
5
|
**Currently, Eden types generation is broken!!**
|
6
6
|
|
@@ -28,11 +28,16 @@ bun install elysia-autoload
|
|
28
28
|
import { Elysia } from "elysia";
|
29
29
|
import { autoload } from "elysia-autoload";
|
30
30
|
|
31
|
-
const app = new Elysia().use(autoload()).listen(3000);
|
31
|
+
const app = new Elysia().use(await autoload()).listen(3000);
|
32
32
|
|
33
33
|
export type ElysiaApp = typeof app;
|
34
34
|
```
|
35
35
|
|
36
|
+
> [!IMPORTANT]
|
37
|
+
> We strictly recommend use `await` when registering plugin
|
38
|
+
>
|
39
|
+
> Read more about [Lazy-load plugins](https://elysiajs.com/patterns/lazy-loading-module.html)
|
40
|
+
|
36
41
|
## Create route
|
37
42
|
|
38
43
|
```ts
|
@@ -99,7 +104,7 @@ import { autoload } from "elysia-autoload";
|
|
99
104
|
|
100
105
|
const app = new Elysia()
|
101
106
|
.use(
|
102
|
-
autoload({
|
107
|
+
await autoload({
|
103
108
|
types: {
|
104
109
|
output: "./routes.ts",
|
105
110
|
typeName: "Routes",
|
@@ -129,11 +134,28 @@ const { data } = await app.test["some-path-param"].get({
|
|
129
134
|
console.log(data);
|
130
135
|
```
|
131
136
|
|
137
|
+
`routes.ts` will be:
|
138
|
+
|
139
|
+
```ts
|
140
|
+
// @filename: routes.ts
|
141
|
+
|
142
|
+
import type { ElysiaWithBaseUrl } from "elysia-autoload";
|
143
|
+
import type Route0 from "./routes/index";
|
144
|
+
import type Route1 from "./routes/test/[some]/index";
|
145
|
+
|
146
|
+
declare global {
|
147
|
+
export type Routes = ElysiaWithBaseUrl<"/api", ReturnType<typeof Route0>> &
|
148
|
+
ElysiaWithBaseUrl<"/api/test/:some", ReturnType<typeof Route1>>;
|
149
|
+
}
|
150
|
+
```
|
151
|
+
|
132
152
|
Example of app with types code-generation you can see in [example](https://github.com/kravetsone/elysia-autoload/tree/main/example)
|
133
153
|
|
134
|
-
|
154
|
+
**Currently, Eden types generation is broken!!**
|
155
|
+
|
156
|
+
### [Bun build](https://bun.sh/docs/bundler) usage
|
135
157
|
|
136
|
-
You can use this plugin with `Bun.build
|
158
|
+
You can use this plugin with [`Bun.build`](https://bun.sh/docs/bundler), thanks to [esbuild-plugin-autoload](https://github.com/kravetsone/esbuild-plugin-autoload)!
|
137
159
|
|
138
160
|
```ts
|
139
161
|
// @filename: build.ts
|
@@ -141,6 +163,7 @@ import { autoload } from "esbuild-plugin-autoload"; // default import also suppo
|
|
141
163
|
|
142
164
|
await Bun.build({
|
143
165
|
entrypoints: ["src/index.ts"],
|
166
|
+
target: "bun",
|
144
167
|
outdir: "out",
|
145
168
|
plugins: [autoload()],
|
146
169
|
}).then(console.log);
|
@@ -148,6 +171,26 @@ await Bun.build({
|
|
148
171
|
|
149
172
|
Then, build it with `bun build.ts` and run with `bun out/index.ts`.
|
150
173
|
|
174
|
+
### [Bun compile](https://bun.sh/docs/bundler/executables) usage
|
175
|
+
|
176
|
+
You can bundle and then compile it into a [single executable binary file](https://bun.sh/docs/bundler/executables)
|
177
|
+
|
178
|
+
```ts
|
179
|
+
import { autoload } from "esbuild-plugin-autoload"; // default import also supported
|
180
|
+
|
181
|
+
await Bun.build({
|
182
|
+
entrypoints: ["src/index.ts"],
|
183
|
+
target: "bun",
|
184
|
+
outdir: "out",
|
185
|
+
plugins: [autoload()],
|
186
|
+
}).then(console.log);
|
187
|
+
|
188
|
+
await Bun.$`bun build --compile out/index.js`;
|
189
|
+
```
|
190
|
+
|
191
|
+
> [!WARNING]
|
192
|
+
> You cannot use it in `bun build --compile` mode without extra step ([Feature issue](https://github.com/oven-sh/bun/issues/11895))
|
193
|
+
|
151
194
|
[Read more](https://github.com/kravetsone/esbuild-plugin-autoload)
|
152
195
|
|
153
196
|
### Usage of schema handler
|
@@ -159,7 +202,7 @@ import { autoload } from "elysia-autoload";
|
|
159
202
|
|
160
203
|
const app = new Elysia()
|
161
204
|
.use(
|
162
|
-
autoload({
|
205
|
+
await autoload({
|
163
206
|
schema: ({ path, url }) => {
|
164
207
|
const tag = url.split("/").at(1)!;
|
165
208
|
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import Elysia, { RouteBase,
|
2
|
-
import { BaseMacro } from 'elysia/dist/types';
|
1
|
+
import Elysia, { RouteBase, LocalHook, InputSchema, RouteSchema, SingletonBase, BaseMacro, Elysia as Elysia$1 } from 'elysia';
|
3
2
|
|
4
3
|
type RemoveLastChar<T extends string> = T extends `${infer V}/` ? V : T;
|
5
4
|
type RoutesWithPrefix<Routes extends RouteBase, Prefix extends string> = {
|
@@ -34,6 +33,7 @@ declare function autoload(options?: IAutoloadOptions): Promise<Elysia$1<string,
|
|
34
33
|
}, {
|
35
34
|
schema: {};
|
36
35
|
macro: {};
|
36
|
+
macroFn: {};
|
37
37
|
}, {}, {
|
38
38
|
derive: {};
|
39
39
|
resolve: {};
|
@@ -44,4 +44,4 @@ declare function autoload(options?: IAutoloadOptions): Promise<Elysia$1<string,
|
|
44
44
|
schema: {};
|
45
45
|
}>>;
|
46
46
|
|
47
|
-
export { type ElysiaWithBaseUrl, type IAutoloadOptions, type ITypesOptions, autoload };
|
47
|
+
export { type ElysiaWithBaseUrl, type IAutoloadOptions, type ITypesOptions, type TSchemaHandler, autoload };
|
package/dist/index.js
CHANGED
@@ -1,19 +1,15 @@
|
|
1
|
-
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import {
|
5
|
-
Elysia
|
6
|
-
} from "elysia";
|
1
|
+
import fs from 'node:fs';
|
2
|
+
import path from 'node:path';
|
3
|
+
import { Elysia } from 'elysia';
|
7
4
|
|
8
|
-
// src/utils.ts
|
9
|
-
import path from "node:path";
|
10
5
|
function getPath(dir) {
|
11
|
-
if (path.isAbsolute(dir))
|
6
|
+
if (path.isAbsolute(dir))
|
7
|
+
return dir;
|
12
8
|
if (path.isAbsolute(process.argv[1]))
|
13
9
|
return path.join(process.argv[1], "..", dir);
|
14
10
|
return path.join(process.cwd(), process.argv[1], "..", dir);
|
15
11
|
}
|
16
|
-
function transformToUrl(
|
12
|
+
function transformToUrl(path2) {
|
17
13
|
const replacements = [
|
18
14
|
// Clean the url extensions
|
19
15
|
{ regex: /\.(ts|tsx|js|jsx|mjs|cjs)$/u, replacement: "" },
|
@@ -35,30 +31,46 @@ function transformToUrl(path3) {
|
|
35
31
|
// remove index from end of path
|
36
32
|
{ regex: /\/?index$/, replacement: "" }
|
37
33
|
];
|
38
|
-
let url =
|
34
|
+
let url = path2;
|
39
35
|
for (const { regex, replacement } of replacements) {
|
40
36
|
url = url.replace(regex, replacement);
|
41
37
|
}
|
42
38
|
return url;
|
43
39
|
}
|
44
|
-
function getParamsCount(
|
45
|
-
return
|
40
|
+
function getParamsCount(path2) {
|
41
|
+
return path2.match(/\[(.*?)\]/gu)?.length || 0;
|
46
42
|
}
|
47
43
|
function sortByNestedParams(routes) {
|
48
44
|
return routes.sort((a, b) => getParamsCount(a) - getParamsCount(b));
|
49
45
|
}
|
50
46
|
function fixSlashes(prefix) {
|
51
|
-
if (!prefix?.endsWith("/"))
|
47
|
+
if (!prefix?.endsWith("/"))
|
48
|
+
return prefix;
|
52
49
|
return prefix.slice(0, -1);
|
53
50
|
}
|
51
|
+
function addRelativeIfNotDot(path2) {
|
52
|
+
if (path2.at(0) !== ".")
|
53
|
+
return `./${path2}`;
|
54
|
+
return path2;
|
55
|
+
}
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
57
|
+
const DIR_ROUTES_DEFAULT = "./routes";
|
58
|
+
const TYPES_OUTPUT_DEFAULT = "./routes-types.ts";
|
59
|
+
const TYPES_TYPENAME_DEFAULT = "Routes";
|
60
|
+
const TYPES_OBJECT_DEFAULT = {
|
61
|
+
output: [TYPES_OUTPUT_DEFAULT],
|
62
|
+
typeName: TYPES_TYPENAME_DEFAULT
|
63
|
+
};
|
58
64
|
async function autoload(options = {}) {
|
59
|
-
const
|
60
|
-
const
|
61
|
-
const
|
65
|
+
const { pattern, prefix, schema } = options;
|
66
|
+
const dir = options.dir ?? DIR_ROUTES_DEFAULT;
|
67
|
+
const types = options.types ? options.types !== true ? {
|
68
|
+
...TYPES_OBJECT_DEFAULT,
|
69
|
+
...options.types,
|
70
|
+
// This code allows you to omit the output data or specify it as an string[] or string.
|
71
|
+
output: !options.types.output ? [TYPES_OUTPUT_DEFAULT] : Array.isArray(options.types.output) ? options.types.output : [options.types.output]
|
72
|
+
} : TYPES_OBJECT_DEFAULT : false;
|
73
|
+
const directoryPath = getPath(dir);
|
62
74
|
if (!fs.existsSync(directoryPath))
|
63
75
|
throw new Error(`Directory ${directoryPath} doesn't exists`);
|
64
76
|
if (!fs.statSync(directoryPath).isDirectory())
|
@@ -81,37 +93,43 @@ async function autoload(options = {}) {
|
|
81
93
|
);
|
82
94
|
const paths = [];
|
83
95
|
for await (const filePath of sortByNestedParams(files)) {
|
84
|
-
const fullPath =
|
96
|
+
const fullPath = path.join(directoryPath, filePath);
|
85
97
|
const file = await import(fullPath);
|
86
98
|
if (!file.default)
|
87
99
|
throw new Error(`${filePath} doesn't provide default export`);
|
88
100
|
const url = transformToUrl(filePath);
|
89
101
|
const groupOptions = schema ? schema({ path: filePath, url }) : {};
|
90
102
|
plugin.group(url, groupOptions, file.default);
|
91
|
-
if (types)
|
103
|
+
if (types)
|
104
|
+
paths.push(fullPath.replace(directoryPath, ""));
|
92
105
|
}
|
93
106
|
if (types) {
|
94
|
-
const
|
95
|
-
|
96
|
-
|
97
|
-
|
107
|
+
for await (const outputPath of types.output) {
|
108
|
+
const outputAbsolutePath = getPath(outputPath);
|
109
|
+
const imports = paths.map(
|
110
|
+
(x, index) => `import type Route${index} from "${addRelativeIfNotDot(
|
111
|
+
path.relative(
|
112
|
+
path.dirname(outputAbsolutePath),
|
113
|
+
directoryPath + x.replace(".ts", "").replace(".tsx", "")
|
114
|
+
).replace(/\\/gu, "/")
|
115
|
+
)}";`
|
116
|
+
);
|
98
117
|
await Bun.write(
|
99
|
-
|
118
|
+
outputAbsolutePath,
|
100
119
|
[
|
101
120
|
`import type { ElysiaWithBaseUrl } from "elysia-autoload";`,
|
102
121
|
imports.join("\n"),
|
103
122
|
"",
|
104
|
-
|
105
|
-
` export type ${types
|
123
|
+
!types.useExport ? "declare global {" : "",
|
124
|
+
` export type ${types.typeName} = ${paths.map(
|
106
125
|
(x, index) => `ElysiaWithBaseUrl<"${((prefix?.endsWith("/") ? prefix.slice(0, -1) : prefix) ?? "") + transformToUrl(x) || "/"}", ReturnType<typeof Route${index}>>`
|
107
126
|
).join("\n & ")}`,
|
108
|
-
|
127
|
+
!types.useExport ? "}" : ""
|
109
128
|
].join("\n")
|
110
129
|
);
|
111
130
|
}
|
112
131
|
}
|
113
132
|
return plugin;
|
114
133
|
}
|
115
|
-
|
116
|
-
|
117
|
-
};
|
134
|
+
|
135
|
+
export { autoload };
|
package/package.json
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
{
|
2
2
|
"name": "elysia-autoload",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.1.0",
|
4
4
|
"author": "kravetsone",
|
5
5
|
"type": "module",
|
6
6
|
"types": "./dist/index.d.ts",
|
7
|
-
"main": "./dist/index.cjs",
|
8
7
|
"module": "./dist/index.js",
|
9
|
-
"
|
8
|
+
"exports": {
|
9
|
+
".": {
|
10
|
+
"types": "./dist/index.d.ts",
|
11
|
+
"import": "./dist/index.js"
|
12
|
+
}
|
13
|
+
},
|
14
|
+
"description": "Plugin for Elysia which autoload all routes in directory and code-generate types for Eden with Bun.build support",
|
10
15
|
"homepage": "https://github.com/kravetsone/elysia-autoload",
|
11
16
|
"keywords": [
|
12
17
|
"bun",
|
@@ -22,7 +27,7 @@
|
|
22
27
|
"codegeneration"
|
23
28
|
],
|
24
29
|
"scripts": {
|
25
|
-
"prepublishOnly": "bun test && bunx
|
30
|
+
"prepublishOnly": "bun test && bunx pkgroll",
|
26
31
|
"lint": "bunx @biomejs/biome check src",
|
27
32
|
"lint:fix": "bun lint --apply",
|
28
33
|
"prepare": "bunx husky"
|
@@ -31,16 +36,15 @@
|
|
31
36
|
"dist"
|
32
37
|
],
|
33
38
|
"devDependencies": {
|
34
|
-
"@biomejs/biome": "1.
|
35
|
-
"@elysiajs/eden": "^1.0
|
36
|
-
"@elysiajs/swagger": "^1.0
|
37
|
-
"@types/bun": "^1.1.
|
38
|
-
"elysia": "^1.
|
39
|
-
"
|
40
|
-
"
|
41
|
-
"typescript": "^5.4.5"
|
39
|
+
"@biomejs/biome": "1.8.3",
|
40
|
+
"@elysiajs/eden": "^1.1.0",
|
41
|
+
"@elysiajs/swagger": "^1.1.0",
|
42
|
+
"@types/bun": "^1.1.6",
|
43
|
+
"elysia": "^1.1.2",
|
44
|
+
"pkgroll": "^2.1.1",
|
45
|
+
"typescript": "^5.5.3"
|
42
46
|
},
|
43
47
|
"peerDependencies": {
|
44
|
-
"elysia": "^1.
|
48
|
+
"elysia": "^1.1.0"
|
45
49
|
}
|
46
50
|
}
|
package/dist/index.cjs
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
|
30
|
-
// src/index.ts
|
31
|
-
var src_exports = {};
|
32
|
-
__export(src_exports, {
|
33
|
-
autoload: () => autoload
|
34
|
-
});
|
35
|
-
module.exports = __toCommonJS(src_exports);
|
36
|
-
var import_node_fs = __toESM(require("fs"), 1);
|
37
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
38
|
-
var import_elysia = require("elysia");
|
39
|
-
|
40
|
-
// src/utils.ts
|
41
|
-
var import_node_path = __toESM(require("path"), 1);
|
42
|
-
function getPath(dir) {
|
43
|
-
if (import_node_path.default.isAbsolute(dir)) return dir;
|
44
|
-
if (import_node_path.default.isAbsolute(process.argv[1]))
|
45
|
-
return import_node_path.default.join(process.argv[1], "..", dir);
|
46
|
-
return import_node_path.default.join(process.cwd(), process.argv[1], "..", dir);
|
47
|
-
}
|
48
|
-
function transformToUrl(path3) {
|
49
|
-
const replacements = [
|
50
|
-
// Clean the url extensions
|
51
|
-
{ regex: /\.(ts|tsx|js|jsx|mjs|cjs)$/u, replacement: "" },
|
52
|
-
// Fix windows slashes
|
53
|
-
{ regex: /\\/gu, replacement: "/" },
|
54
|
-
// Handle wild card based routes - users/[...id]/profile.ts -> users/*/profile
|
55
|
-
{ regex: /\[\.\.\..*\]/gu, replacement: "*" },
|
56
|
-
// Handle generic square bracket based routes - users/[id]/index.ts -> users/:id
|
57
|
-
{
|
58
|
-
regex: /\[(.*?)\]/gu,
|
59
|
-
replacement: (_, match) => `:${match}`
|
60
|
-
},
|
61
|
-
// Handle the case when multiple parameters are present in one file
|
62
|
-
// users / [id] - [name].ts to users /: id -:name and users / [id] - [name] / [age].ts to users /: id -: name /: age
|
63
|
-
{ regex: /\]-\[/gu, replacement: "-:" },
|
64
|
-
{ regex: /\]\//gu, replacement: "/" },
|
65
|
-
{ regex: /\[/gu, replacement: "" },
|
66
|
-
{ regex: /\]/gu, replacement: "" },
|
67
|
-
// remove index from end of path
|
68
|
-
{ regex: /\/?index$/, replacement: "" }
|
69
|
-
];
|
70
|
-
let url = path3;
|
71
|
-
for (const { regex, replacement } of replacements) {
|
72
|
-
url = url.replace(regex, replacement);
|
73
|
-
}
|
74
|
-
return url;
|
75
|
-
}
|
76
|
-
function getParamsCount(path3) {
|
77
|
-
return path3.match(/\[(.*?)\]/gu)?.length || 0;
|
78
|
-
}
|
79
|
-
function sortByNestedParams(routes) {
|
80
|
-
return routes.sort((a, b) => getParamsCount(a) - getParamsCount(b));
|
81
|
-
}
|
82
|
-
function fixSlashes(prefix) {
|
83
|
-
if (!prefix?.endsWith("/")) return prefix;
|
84
|
-
return prefix.slice(0, -1);
|
85
|
-
}
|
86
|
-
|
87
|
-
// src/index.ts
|
88
|
-
var TYPES_OUTPUT_DEFAULT = "./routes-types.ts";
|
89
|
-
var TYPES_TYPENAME_DEFAULT = "Routes";
|
90
|
-
async function autoload(options = {}) {
|
91
|
-
const fileSources = {};
|
92
|
-
const { pattern, dir, prefix, schema, types } = options;
|
93
|
-
const directoryPath = getPath(dir || "./routes");
|
94
|
-
if (!import_node_fs.default.existsSync(directoryPath))
|
95
|
-
throw new Error(`Directory ${directoryPath} doesn't exists`);
|
96
|
-
if (!import_node_fs.default.statSync(directoryPath).isDirectory())
|
97
|
-
throw new Error(`${directoryPath} isn't a directory`);
|
98
|
-
const plugin = new import_elysia.Elysia({
|
99
|
-
name: "elysia-autoload",
|
100
|
-
prefix: fixSlashes(prefix),
|
101
|
-
seed: {
|
102
|
-
pattern,
|
103
|
-
dir,
|
104
|
-
prefix,
|
105
|
-
types
|
106
|
-
}
|
107
|
-
});
|
108
|
-
const glob = new Bun.Glob(pattern || "**/*.{ts,tsx,js,jsx,mjs,cjs}");
|
109
|
-
const files = await Array.fromAsync(
|
110
|
-
glob.scan({
|
111
|
-
cwd: directoryPath
|
112
|
-
})
|
113
|
-
);
|
114
|
-
const paths = [];
|
115
|
-
for await (const filePath of sortByNestedParams(files)) {
|
116
|
-
const fullPath = import_node_path2.default.join(directoryPath, filePath);
|
117
|
-
const file = await import(fullPath);
|
118
|
-
if (!file.default)
|
119
|
-
throw new Error(`${filePath} doesn't provide default export`);
|
120
|
-
const url = transformToUrl(filePath);
|
121
|
-
const groupOptions = schema ? schema({ path: filePath, url }) : {};
|
122
|
-
plugin.group(url, groupOptions, file.default);
|
123
|
-
if (types) paths.push(fullPath.replace(directoryPath, ""));
|
124
|
-
}
|
125
|
-
if (types) {
|
126
|
-
const imports = paths.map(
|
127
|
-
(x, index) => `import type Route${index} from "${(directoryPath + x.replace(".ts", "").replace(".tsx", "")).replace(/\\/gu, "/")}";`
|
128
|
-
);
|
129
|
-
for await (const outputPath of types === true || !types.output ? [TYPES_OUTPUT_DEFAULT] : Array.isArray(types.output) ? types.output : [types.output]) {
|
130
|
-
await Bun.write(
|
131
|
-
getPath(outputPath),
|
132
|
-
[
|
133
|
-
`import type { ElysiaWithBaseUrl } from "elysia-autoload";`,
|
134
|
-
imports.join("\n"),
|
135
|
-
"",
|
136
|
-
types === true || !types.useExport ? "declare global {" : "",
|
137
|
-
` export type ${types === true || !types.typeName ? TYPES_TYPENAME_DEFAULT : types.typeName} = ${paths.map(
|
138
|
-
(x, index) => `ElysiaWithBaseUrl<"${((prefix?.endsWith("/") ? prefix.slice(0, -1) : prefix) ?? "") + transformToUrl(x) || "/"}", ReturnType<typeof Route${index}>>`
|
139
|
-
).join("\n & ")}`,
|
140
|
-
types === true || !types.useExport ? "}" : ""
|
141
|
-
].join("\n")
|
142
|
-
);
|
143
|
-
}
|
144
|
-
}
|
145
|
-
return plugin;
|
146
|
-
}
|
147
|
-
// Annotate the CommonJS export names for ESM import in node:
|
148
|
-
0 && (module.exports = {
|
149
|
-
autoload
|
150
|
-
});
|
package/dist/index.d.cts
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
import Elysia, { RouteBase, Elysia as Elysia$1, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
|
2
|
-
import { BaseMacro } from 'elysia/dist/types';
|
3
|
-
|
4
|
-
type RemoveLastChar<T extends string> = T extends `${infer V}/` ? V : T;
|
5
|
-
type RoutesWithPrefix<Routes extends RouteBase, Prefix extends string> = {
|
6
|
-
[K in keyof Routes as `${Prefix}${RemoveLastChar<K & string>}`]: Routes[K];
|
7
|
-
};
|
8
|
-
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, RoutesWithPrefix<Routes, BaseUrl>, Ephemeral, Volatile> : never;
|
9
|
-
|
10
|
-
type TSchemaHandler = ({ path, url, }: {
|
11
|
-
path: string;
|
12
|
-
url: string;
|
13
|
-
}) => LocalHook<InputSchema, RouteSchema, SingletonBase, Record<string, Error>, BaseMacro, "">;
|
14
|
-
interface ITypesOptions {
|
15
|
-
output?: string | string[];
|
16
|
-
typeName?: string;
|
17
|
-
useExport?: boolean;
|
18
|
-
}
|
19
|
-
interface IAutoloadOptions {
|
20
|
-
pattern?: string;
|
21
|
-
dir?: string;
|
22
|
-
prefix?: string;
|
23
|
-
schema?: TSchemaHandler;
|
24
|
-
types?: ITypesOptions | true;
|
25
|
-
}
|
26
|
-
declare function autoload(options?: IAutoloadOptions): Promise<Elysia$1<string, false, {
|
27
|
-
decorator: {};
|
28
|
-
store: {};
|
29
|
-
derive: {};
|
30
|
-
resolve: {};
|
31
|
-
}, {
|
32
|
-
type: {};
|
33
|
-
error: {};
|
34
|
-
}, {
|
35
|
-
schema: {};
|
36
|
-
macro: {};
|
37
|
-
}, {}, {
|
38
|
-
derive: {};
|
39
|
-
resolve: {};
|
40
|
-
schema: {};
|
41
|
-
}, {
|
42
|
-
derive: {};
|
43
|
-
resolve: {};
|
44
|
-
schema: {};
|
45
|
-
}>>;
|
46
|
-
|
47
|
-
export { type ElysiaWithBaseUrl, type IAutoloadOptions, type ITypesOptions, autoload };
|