diesel-core 0.0.21 → 0.0.22
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/CONTRIBUTING.md +2 -2
- package/LICENSE +8 -8
- package/README.md +276 -275
- package/build.js +32 -32
- package/dist/ctx.d.ts +1 -0
- package/dist/ctx.js +1 -1
- package/dist/handleRequest.d.ts +1 -0
- package/dist/handleRequest.js +1 -1
- package/dist/main.d.ts +1 -0
- package/dist/main.js +1 -1
- package/dist/route.d.ts +0 -11
- package/dist/types.d.ts +1 -3
- package/dist/utils.js +1 -1
- package/example/bun.lockb +0 -0
- package/example/index.html +13 -13
- package/example/main.ts +86 -75
- package/example/package-lock.json +177 -177
- package/example/package.json +21 -21
- package/example/route.ts +39 -39
- package/example/test.js +27 -27
- package/example/tester.js +88 -88
- package/example/tsconfig.json +16 -16
- package/index.d.ts +5 -5
- package/index.js +8 -9
- package/jsconfig.json +28 -28
- package/package.json +1 -1
- package/src/ctx.ts +251 -252
- package/src/handleRequest.ts +144 -144
- package/src/main.ts +361 -358
- package/src/trie.ts +148 -148
- package/src/types.ts +157 -157
- package/src/utils.ts +70 -70
- package/test/README.md +15 -15
- package/test/bun.lockb +0 -0
- package/test/index.ts +4 -4
- package/test/package.json +13 -13
- package/test/tsconfig.json +27 -27
- package/tsconfig.json +16 -16
- package/.prettierignore +0 -7
- package/.prettierrc +0 -7
- package/src/route.ts +0 -35
package/example/tester.js
CHANGED
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import Diesel from "../dist/main";
|
|
2
|
-
import jwt from "jsonwebtoken";
|
|
3
|
-
|
|
4
|
-
const app = new Diesel();
|
|
5
|
-
const secret = "secret";
|
|
6
|
-
|
|
7
|
-
// app.filter().permitAll().require()
|
|
8
|
-
|
|
9
|
-
app.get("/r", (xl) => {
|
|
10
|
-
return xl.
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
// app.use((xl) => {
|
|
14
|
-
// const cok = xl.getCookie('accessToken');
|
|
15
|
-
|
|
16
|
-
// if (cok) {
|
|
17
|
-
// try {
|
|
18
|
-
// const vcok = jwt.verify(cok, secret);
|
|
19
|
-
// xl.setAuth(true);
|
|
20
|
-
// xl.set('user',vcok)
|
|
21
|
-
// } catch (error) {
|
|
22
|
-
// // console.log('Token verification failed:', error);
|
|
23
|
-
// xl.setAuth(false);
|
|
24
|
-
// }
|
|
25
|
-
// } else {
|
|
26
|
-
// xl.setAuth(false);
|
|
27
|
-
// }
|
|
28
|
-
|
|
29
|
-
// return null;
|
|
30
|
-
// });
|
|
31
|
-
|
|
32
|
-
// app.use(h)
|
|
33
|
-
// Main route handler for "/"
|
|
34
|
-
|
|
35
|
-
// app.addHooks('onRequest',(xl)=>{
|
|
36
|
-
// console.log('on req hooks');
|
|
37
|
-
// })
|
|
38
|
-
|
|
39
|
-
// app.filter()
|
|
40
|
-
|
|
41
|
-
app.get("/", async (xl) => {
|
|
42
|
-
return xl.
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
app.post("/", async (xl) => {
|
|
46
|
-
const body = await xl.body();
|
|
47
|
-
return new Response(JSON.stringify(body)); // This will log the parsed body content
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
app.get("/c", async(xl) => {
|
|
51
|
-
const user = {
|
|
52
|
-
name: "pk",
|
|
53
|
-
age: 22,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const accessToken = jwt.sign(user, secret, { expiresIn: "1d" });
|
|
57
|
-
const refreshToken = jwt.sign(user, secret, { expiresIn: "10d" });
|
|
58
|
-
const options = {
|
|
59
|
-
httpOnly: true, // Makes cookie accessible only by the web server (not JS)
|
|
60
|
-
secure: true, // Ensures the cookie is sent over HTTPS
|
|
61
|
-
maxAge: 24 * 60 * 60 * 1000, // 1 day in milliseconds
|
|
62
|
-
sameSite: "Strict", // Prevents CSRF (strict origin policy)
|
|
63
|
-
path: "/", // Cookie available for all routes
|
|
64
|
-
};
|
|
65
|
-
await xl.cookie("accessToken", accessToken, options)
|
|
66
|
-
await xl.cookie("refreshToken", refreshToken, options)
|
|
67
|
-
// xl.cookie("refreshToken", refreshToken, options);
|
|
68
|
-
await xl.getCookie()
|
|
69
|
-
return xl.json({msg:"setting cookies"})
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// For "/test", middlewares h, s will run before the handler
|
|
73
|
-
app.get("/test/:id", async (xl) => {
|
|
74
|
-
const q = xl.getQuery();
|
|
75
|
-
const params = xl.getParams('id');
|
|
76
|
-
return new Response(JSON.stringify({ msg: "hello world", q, params }));
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// For "/ok", only middleware h will run before the handler
|
|
80
|
-
app.get("/redirect", (xl) => {
|
|
81
|
-
return xl.redirect("/");
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
import userRoute from "./route.js";
|
|
85
|
-
|
|
86
|
-
app.register("/api/user", userRoute);
|
|
87
|
-
|
|
88
|
-
app.listen(3000);
|
|
1
|
+
import Diesel from "../dist/main";
|
|
2
|
+
import jwt from "jsonwebtoken";
|
|
3
|
+
|
|
4
|
+
const app = new Diesel();
|
|
5
|
+
const secret = "secret";
|
|
6
|
+
|
|
7
|
+
// app.filter().permitAll().require()
|
|
8
|
+
|
|
9
|
+
app.get("/r", (xl) => {
|
|
10
|
+
return xl.file(`${import.meta.dir}/index.html`);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// app.use((xl) => {
|
|
14
|
+
// const cok = xl.getCookie('accessToken');
|
|
15
|
+
|
|
16
|
+
// if (cok) {
|
|
17
|
+
// try {
|
|
18
|
+
// const vcok = jwt.verify(cok, secret);
|
|
19
|
+
// xl.setAuth(true);
|
|
20
|
+
// xl.set('user',vcok)
|
|
21
|
+
// } catch (error) {
|
|
22
|
+
// // console.log('Token verification failed:', error);
|
|
23
|
+
// xl.setAuth(false);
|
|
24
|
+
// }
|
|
25
|
+
// } else {
|
|
26
|
+
// xl.setAuth(false);
|
|
27
|
+
// }
|
|
28
|
+
|
|
29
|
+
// return null;
|
|
30
|
+
// });
|
|
31
|
+
|
|
32
|
+
// app.use(h)
|
|
33
|
+
// Main route handler for "/"
|
|
34
|
+
|
|
35
|
+
// app.addHooks('onRequest',(xl)=>{
|
|
36
|
+
// console.log('on req hooks');
|
|
37
|
+
// })
|
|
38
|
+
|
|
39
|
+
// app.filter()
|
|
40
|
+
|
|
41
|
+
app.get("/", async (xl) => {
|
|
42
|
+
return xl.text("hello d")
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
app.post("/", async (xl) => {
|
|
46
|
+
const body = await xl.body();
|
|
47
|
+
return new Response(JSON.stringify(body)); // This will log the parsed body content
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
app.get("/c", async(xl) => {
|
|
51
|
+
const user = {
|
|
52
|
+
name: "pk",
|
|
53
|
+
age: 22,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const accessToken = jwt.sign(user, secret, { expiresIn: "1d" });
|
|
57
|
+
const refreshToken = jwt.sign(user, secret, { expiresIn: "10d" });
|
|
58
|
+
const options = {
|
|
59
|
+
httpOnly: true, // Makes cookie accessible only by the web server (not JS)
|
|
60
|
+
secure: true, // Ensures the cookie is sent over HTTPS
|
|
61
|
+
maxAge: 24 * 60 * 60 * 1000, // 1 day in milliseconds
|
|
62
|
+
sameSite: "Strict", // Prevents CSRF (strict origin policy)
|
|
63
|
+
path: "/", // Cookie available for all routes
|
|
64
|
+
};
|
|
65
|
+
await xl.cookie("accessToken", accessToken, options)
|
|
66
|
+
await xl.cookie("refreshToken", refreshToken, options)
|
|
67
|
+
// xl.cookie("refreshToken", refreshToken, options);
|
|
68
|
+
await xl.getCookie()
|
|
69
|
+
return xl.json({msg:"setting cookies"})
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// For "/test", middlewares h, s will run before the handler
|
|
73
|
+
app.get("/test/:id", async (xl) => {
|
|
74
|
+
const q = xl.getQuery();
|
|
75
|
+
const params = xl.getParams('id');
|
|
76
|
+
return new Response(JSON.stringify({ msg: "hello world", q, params }));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// For "/ok", only middleware h will run before the handler
|
|
80
|
+
app.get("/redirect", (xl) => {
|
|
81
|
+
return xl.redirect("/");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
import userRoute from "./route.js";
|
|
85
|
+
|
|
86
|
+
app.register("/api/user", userRoute);
|
|
87
|
+
|
|
88
|
+
app.listen(3000);
|
package/example/tsconfig.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES6", // Specify ECMAScript target version
|
|
4
|
-
"module": "commonjs", // Specify module code generation
|
|
5
|
-
"outDir": "./dist", // Redirect output structure to the 'dist' directory
|
|
6
|
-
"rootDir": ".",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
// "emitDeclarationOnly": true, // Specify the root directory of input files
|
|
9
|
-
"strict": true, // Enable all strict type-checking options
|
|
10
|
-
"esModuleInterop": true, // Enables emit interoperability between CommonJS and ES Modules
|
|
11
|
-
"skipLibCheck": true, // Skip type checking of declaration files
|
|
12
|
-
"forceConsistentCasingInFileNames": true // Disallow inconsistently-cased references to the same file
|
|
13
|
-
},
|
|
14
|
-
"include": ["./*.ts"], // Specify the files to include
|
|
15
|
-
"exclude": ["node_modules"] // Exclude the 'node_modules' directory
|
|
16
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES6", // Specify ECMAScript target version
|
|
4
|
+
"module": "commonjs", // Specify module code generation
|
|
5
|
+
"outDir": "./dist", // Redirect output structure to the 'dist' directory
|
|
6
|
+
"rootDir": ".",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
// "emitDeclarationOnly": true, // Specify the root directory of input files
|
|
9
|
+
"strict": true, // Enable all strict type-checking options
|
|
10
|
+
"esModuleInterop": true, // Enables emit interoperability between CommonJS and ES Modules
|
|
11
|
+
"skipLibCheck": true, // Skip type checking of declaration files
|
|
12
|
+
"forceConsistentCasingInFileNames": true // Disallow inconsistently-cased references to the same file
|
|
13
|
+
},
|
|
14
|
+
"include": ["./*.ts"], // Specify the files to include
|
|
15
|
+
"exclude": ["node_modules"] // Exclude the 'node_modules' directory
|
|
16
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './dist/types';
|
|
2
|
-
|
|
3
|
-
export { default as Diesel } from './dist/main';
|
|
4
|
-
export { default as Router } from './dist/route';
|
|
5
|
-
export { default as rateLimit } from './dist/utils';
|
|
1
|
+
export * from './dist/types';
|
|
2
|
+
|
|
3
|
+
export { default as Diesel } from './dist/main';
|
|
4
|
+
export { default as Router } from './dist/route';
|
|
5
|
+
export { default as rateLimit } from './dist/utils';
|
package/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import Diesel from './
|
|
2
|
-
import Router from './src/route'
|
|
3
|
-
import rateLimit from './
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
Diesel,
|
|
8
|
-
|
|
9
|
-
rateLimit
|
|
1
|
+
import Diesel from './dist/main'
|
|
2
|
+
// import Router from './src/route'
|
|
3
|
+
import rateLimit from './dist/utils'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
Diesel,
|
|
8
|
+
rateLimit
|
|
10
9
|
}
|
package/jsconfig.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
// Enable latest features
|
|
4
|
-
"lib": ["ESNext", "DOM"],
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"moduleDetection": "force",
|
|
8
|
-
"jsx": "react-jsx",
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
"outDir":"dist",
|
|
11
|
-
|
|
12
|
-
// Bundler mode
|
|
13
|
-
"moduleResolution": "bundler",
|
|
14
|
-
"allowImportingTsExtensions": true,
|
|
15
|
-
"verbatimModuleSyntax": true,
|
|
16
|
-
"noEmit": true,
|
|
17
|
-
|
|
18
|
-
// Best practices
|
|
19
|
-
"strict": true,
|
|
20
|
-
"skipLibCheck": true,
|
|
21
|
-
"noFallthroughCasesInSwitch": true,
|
|
22
|
-
|
|
23
|
-
// Some stricter flags (disabled by default)
|
|
24
|
-
"noUnusedLocals": false,
|
|
25
|
-
"noUnusedParameters": false,
|
|
26
|
-
"noPropertyAccessFromIndexSignature": false
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Enable latest features
|
|
4
|
+
"lib": ["ESNext", "DOM"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"outDir":"dist",
|
|
11
|
+
|
|
12
|
+
// Bundler mode
|
|
13
|
+
"moduleResolution": "bundler",
|
|
14
|
+
"allowImportingTsExtensions": true,
|
|
15
|
+
"verbatimModuleSyntax": true,
|
|
16
|
+
"noEmit": true,
|
|
17
|
+
|
|
18
|
+
// Best practices
|
|
19
|
+
"strict": true,
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
|
|
23
|
+
// Some stricter flags (disabled by default)
|
|
24
|
+
"noUnusedLocals": false,
|
|
25
|
+
"noUnusedParameters": false,
|
|
26
|
+
"noPropertyAccessFromIndexSignature": false
|
|
27
|
+
}
|
|
28
|
+
}
|