@stacksjs/router 0.58.73 → 0.59.2
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/dist/index.d.ts +4 -0
- package/dist/index.js +11018 -750
- package/dist/middleware.d.ts +8 -0
- package/dist/request.d.ts +16 -0
- package/dist/router.d.ts +32 -0
- package/dist/server.d.ts +9 -0
- package/package.json +5 -5
- package/src/middleware.ts +3 -4
- package/src/router.ts +1 -21
- package/src/server.ts +3 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MiddlewareOptions } from '@stacksjs/types';
|
|
2
|
+
export declare class Middleware implements MiddlewareOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
priority: number;
|
|
5
|
+
handle: Function;
|
|
6
|
+
constructor(data: MiddlewareOptions);
|
|
7
|
+
}
|
|
8
|
+
export declare const middlewares: string[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface RequestData {
|
|
2
|
+
[key: string]: string;
|
|
3
|
+
}
|
|
4
|
+
export declare class Request {
|
|
5
|
+
private query;
|
|
6
|
+
private params;
|
|
7
|
+
addQuery(url: URL): void;
|
|
8
|
+
get(element: string): string | number | undefined;
|
|
9
|
+
all(): RequestData;
|
|
10
|
+
has(element: string): boolean;
|
|
11
|
+
isEmpty(): boolean;
|
|
12
|
+
extractParamsFromRoute(routePattern: string, pathname: string): void;
|
|
13
|
+
getParams(key: string): number | string | null;
|
|
14
|
+
}
|
|
15
|
+
export declare const request: Request;
|
|
16
|
+
export {};
|
package/dist/router.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RedirectCode, Route, RouteGroupOptions, RouterInterface } from '@stacksjs/types';
|
|
2
|
+
export declare class Router implements RouterInterface {
|
|
3
|
+
private routes;
|
|
4
|
+
private apiPrefix;
|
|
5
|
+
private groupPrefix;
|
|
6
|
+
private path;
|
|
7
|
+
private addRoute;
|
|
8
|
+
get(path: Route['url'], callback: Route['callback']): Promise<this>;
|
|
9
|
+
email(path: Route['url']): Promise<this>;
|
|
10
|
+
health(): Promise<this>;
|
|
11
|
+
job(path: Route['url']): Promise<this>;
|
|
12
|
+
action(path: Route['url']): Promise<this>;
|
|
13
|
+
post(path: Route['url'], callback: Route['callback']): this;
|
|
14
|
+
view(path: Route['url'], callback: Route['callback']): this;
|
|
15
|
+
redirect(path: Route['url'], callback: Route['callback'], _status?: RedirectCode): this;
|
|
16
|
+
delete(path: Route['url'], callback: Route['callback']): this;
|
|
17
|
+
patch(path: Route['url'], callback: Route['callback']): this;
|
|
18
|
+
put(path: Route['url'], callback: Route['callback']): this;
|
|
19
|
+
group(options: string | RouteGroupOptions, callback?: () => void): this;
|
|
20
|
+
name(name: string): this;
|
|
21
|
+
middleware(middleware: Route['middleware']): this;
|
|
22
|
+
prefix(prefix: string): this;
|
|
23
|
+
getRoutes(): Promise<Route[]>;
|
|
24
|
+
private setGroupPrefix;
|
|
25
|
+
private prepareGroupPrefix;
|
|
26
|
+
private resolveCallback;
|
|
27
|
+
private importCallbackFromPath;
|
|
28
|
+
private normalizePath;
|
|
29
|
+
prepareUri(path: string): string;
|
|
30
|
+
private updatePathIfNeeded;
|
|
31
|
+
}
|
|
32
|
+
export declare const route: Router;
|
package/dist/server.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/router",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.59.2",
|
|
5
5
|
"description": "The Stacks framework router.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"license": "MIT",
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@stacksjs/config": "latest",
|
|
52
|
-
"unplugin-vue-router": "^0.
|
|
53
|
-
"vue-router": "^4.
|
|
52
|
+
"unplugin-vue-router": "^0.8.4",
|
|
53
|
+
"vue-router": "^4.3.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@stacksjs/config": "latest",
|
|
57
57
|
"@stacksjs/logging": "latest",
|
|
58
|
-
"unplugin-vue-router": "^0.
|
|
59
|
-
"vue-router": "^4.
|
|
58
|
+
"unplugin-vue-router": "^0.8.4",
|
|
59
|
+
"vue-router": "^4.3.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@stacksjs/development": "latest"
|
package/src/middleware.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { appPath } from '@stacksjs/path'
|
|
2
|
-
import type {
|
|
2
|
+
import type { MiddlewareOptions } from '@stacksjs/types'
|
|
3
3
|
|
|
4
|
-
export class Middleware implements
|
|
4
|
+
export class Middleware implements MiddlewareOptions {
|
|
5
5
|
name: string
|
|
6
6
|
priority: number
|
|
7
|
-
|
|
8
7
|
handle: Function
|
|
9
8
|
|
|
10
|
-
constructor(data:
|
|
9
|
+
constructor(data: MiddlewareOptions) {
|
|
11
10
|
this.name = data.name
|
|
12
11
|
this.priority = data.priority
|
|
13
12
|
this.handle = data.handle
|
package/src/router.ts
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
|
-
import type { RedirectCode, Route, RouteGroupOptions, StatusCode } from '@stacksjs/types'
|
|
1
|
+
import type { RedirectCode, Route, RouteGroupOptions, RouterInterface, StatusCode } from '@stacksjs/types'
|
|
2
2
|
import { path as p, routesPath } from '@stacksjs/path'
|
|
3
3
|
import { log } from '@stacksjs/logging'
|
|
4
4
|
import { pascalCase } from '@stacksjs/strings'
|
|
5
5
|
|
|
6
|
-
type Prefix = string
|
|
7
|
-
|
|
8
|
-
export interface RouterInterface {
|
|
9
|
-
get: (url: Route['url'], callback: Route['callback']) => Promise<this>
|
|
10
|
-
post: (url: Route['url'], callback: Route['callback']) => this
|
|
11
|
-
view: (url: Route['url'], callback: Route['callback']) => this
|
|
12
|
-
redirect: (url: Route['url'], callback: Route['callback'], status?: RedirectCode) => this
|
|
13
|
-
delete: (url: Route['url'], callback: Route['callback']) => this
|
|
14
|
-
patch: (url: Route['url'], callback: Route['callback']) => this
|
|
15
|
-
put: (url: Route['url'], callback: Route['callback']) => this
|
|
16
|
-
email: (url: Route['url']) => Promise<this>
|
|
17
|
-
health: () => Promise<this>
|
|
18
|
-
job: (url: Route['url']) => Promise<this>
|
|
19
|
-
action: (url: Route['url']) => Promise<this>
|
|
20
|
-
group: (options: Prefix | RouteGroupOptions, callback: () => void) => this
|
|
21
|
-
name: (name: string) => this
|
|
22
|
-
middleware: (middleware: Route['middleware']) => this
|
|
23
|
-
getRoutes: () => Promise<Route[]>
|
|
24
|
-
}
|
|
25
|
-
|
|
26
6
|
export class Router implements RouterInterface {
|
|
27
7
|
private routes: Route[] = []
|
|
28
8
|
private apiPrefix = '/api'
|
package/src/server.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { URL } from 'node:url'
|
|
2
2
|
import process from 'node:process'
|
|
3
3
|
import { log } from '@stacksjs/logging'
|
|
4
|
-
import type {
|
|
4
|
+
import type { MiddlewareOptions, Route, StatusCode } from '@stacksjs/types'
|
|
5
5
|
import { middlewares } from './middleware'
|
|
6
6
|
import { request } from './request'
|
|
7
7
|
import { route } from '.'
|
|
@@ -83,7 +83,7 @@ function executeMiddleware(route: Route): void {
|
|
|
83
83
|
|
|
84
84
|
if (middleware && middlewares && isObjectNotEmpty(middlewares)) {
|
|
85
85
|
if (isString(middleware)) {
|
|
86
|
-
const middlewareItem:
|
|
86
|
+
const middlewareItem: MiddlewareOptions = middlewares.find((middlewareItem: MiddlewareOptions) => {
|
|
87
87
|
return middlewareItem.name === middleware
|
|
88
88
|
})
|
|
89
89
|
|
|
@@ -92,7 +92,7 @@ function executeMiddleware(route: Route): void {
|
|
|
92
92
|
}
|
|
93
93
|
else {
|
|
94
94
|
middleware.forEach((m) => {
|
|
95
|
-
const middlewareItem:
|
|
95
|
+
const middlewareItem: MiddlewareOptions = middlewares.find((middlewareItem: MiddlewareOptions) => {
|
|
96
96
|
return middlewareItem.name === m
|
|
97
97
|
})
|
|
98
98
|
|