Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
ee87a6269e | |||
2d76e799a4 | |||
f24520ea89 | |||
5072728118 | |||
bb4df0c47f | |||
101533cddd | |||
3b31f88b0c | |||
daeaac2367 | |||
9b9675bd96 | |||
e7d7865750 | |||
b7feb5098b | |||
76fcf14831 |
@ -19,23 +19,35 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
audit:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm audit --audit-level=high
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -50,9 +62,7 @@ testStable:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
@ -63,9 +73,7 @@ testBuild:
|
|||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@ -85,6 +93,8 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"projectType": {
|
"projectType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["website", "element", "service", "npm"]
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22286
package-lock.json
generated
22286
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartrouter",
|
"name": "@pushrocks/smartrouter",
|
||||||
"version": "1.0.5",
|
"version": "1.0.11",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a router for routing on websites",
|
"description": "a router for routing on websites",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -13,16 +13,16 @@
|
|||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.27",
|
||||||
"@gitzone/tsbundle": "^1.0.72",
|
"@gitzone/tsbundle": "^1.0.87",
|
||||||
"@gitzone/tstest": "^1.0.43",
|
"@gitzone/tstest": "^1.0.57",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"@types/node": "^14.0.23",
|
"@types/node": "^16.7.13",
|
||||||
"tslint": "^6.1.2",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"path-to-regexp": "^6.1.0"
|
"path-to-regexp": "^6.2.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
@ -8,8 +8,8 @@ tap.test('first test', async () => {
|
|||||||
expect(testrouter).to.be.instanceOf(smartrouter.SmartRouter);
|
expect(testrouter).to.be.instanceOf(smartrouter.SmartRouter);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should handle a route change', async (tools) => {
|
tap.test('should handle a route change', async (toolsArg) => {
|
||||||
const done = tools.defer();
|
const done = toolsArg.defer();
|
||||||
testrouter.on('/myawesomeroute/:any', async (routeInfoArg) => {
|
testrouter.on('/myawesomeroute/:any', async (routeInfoArg) => {
|
||||||
expect(routeInfoArg.params.any).to.equal('hello');
|
expect(routeInfoArg.params.any).to.equal('hello');
|
||||||
done.resolve();
|
done.resolve();
|
||||||
@ -18,8 +18,8 @@ tap.test('should handle a route change', async (tools) => {
|
|||||||
await done.promise;
|
await done.promise;
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should handle a route change', async (tools) => {
|
tap.test('should handle a route change', async (toolsArg) => {
|
||||||
const done = tools.defer();
|
const done = toolsArg.defer();
|
||||||
testrouter.on('/myawesomeroute2/:wow', async (routeInfoArg) => {
|
testrouter.on('/myawesomeroute2/:wow', async (routeInfoArg) => {
|
||||||
expect(routeInfoArg.params.wow).to.equal('hello2');
|
expect(routeInfoArg.params.wow).to.equal('hello2');
|
||||||
done.resolve();
|
done.resolve();
|
||||||
@ -29,4 +29,18 @@ tap.test('should handle a route change', async (tools) => {
|
|||||||
expect(window.location.href).to.equal('http://localhost:3007/myawesomeroute2/hello2');
|
expect(window.location.href).to.equal('http://localhost:3007/myawesomeroute2/hello2');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should find a query param', async (toolsArg) => {
|
||||||
|
const done = toolsArg.defer();
|
||||||
|
testrouter.on('/myawesomeroute2/:wow', async (routeInfoArg) => {
|
||||||
|
expect(routeInfoArg.params.wow).to.equal('hello2');
|
||||||
|
expect(routeInfoArg.queryParams.aparam).to.equal('Yes');
|
||||||
|
console.log('Here is what queryParams looks like');
|
||||||
|
console.log(JSON.stringify(routeInfoArg.queryParams));
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
testrouter.pushUrl('/myawesomeroute2/hello2?aparam=Yes');
|
||||||
|
await done.promise;
|
||||||
|
expect(window.location.href).to.equal('http://localhost:3007/myawesomeroute2/hello2?aparam=Yes');
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
13
ts/index.ts
13
ts/index.ts
@ -11,8 +11,9 @@ export interface IRouterOptions {
|
|||||||
export type THandlerFunction = <T extends object>(routeArg: IRouteInfo) => Promise<any>;
|
export type THandlerFunction = <T extends object>(routeArg: IRouteInfo) => Promise<any>;
|
||||||
export interface IRouteInfo {
|
export interface IRouteInfo {
|
||||||
path: string;
|
path: string;
|
||||||
index:number;
|
index: number;
|
||||||
params: {[key: string]: string};
|
params: { [key: string]: string };
|
||||||
|
queryParams: { [key: string]: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,13 +81,19 @@ export class SmartRouter {
|
|||||||
*/
|
*/
|
||||||
async _handleRouteState() {
|
async _handleRouteState() {
|
||||||
const currentLocation = window.location.pathname;
|
const currentLocation = window.location.pathname;
|
||||||
|
const urlSearchParams = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
|
// lets find all wanted routes.
|
||||||
const wantedRoutes = this.routes.filter((routeArg) => {
|
const wantedRoutes = this.routes.filter((routeArg) => {
|
||||||
return !!routeArg.matchFunction(currentLocation);
|
return !!routeArg.matchFunction(currentLocation);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const wantedRoute of wantedRoutes) {
|
for (const wantedRoute of wantedRoutes) {
|
||||||
const routeResult = wantedRoute.matchFunction(currentLocation);
|
const routeResult = wantedRoute.matchFunction(currentLocation);
|
||||||
await wantedRoute.handler(routeResult.valueOf() as IRouteInfo);
|
wantedRoute.handler({
|
||||||
|
...(routeResult.valueOf() as Object),
|
||||||
|
queryParams: Object.fromEntries((urlSearchParams as any).entries()), // TODO check wether entries is supported in typings
|
||||||
|
} as IRouteInfo); // not waiting here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user