simple-boot-core
Advanced tools
Comparing version 1.0.21 to 1.0.22
@@ -5,7 +5,9 @@ import { ConstructorType, GenericClassDecorator } from '../types/Types'; | ||
} | ||
export declare type RouteProperty = ConstructorType<Object> | [ConstructorType<Object>, any] | string; | ||
export declare type Route = { | ||
[name: string]: RouteProperty; | ||
}; | ||
export interface RouterConfig { | ||
path: string; | ||
route: { | ||
[name: string]: ConstructorType<Object>; | ||
}; | ||
route: Route; | ||
routers?: ConstructorType<Object>[]; | ||
@@ -12,0 +14,0 @@ } |
@@ -36,3 +36,3 @@ "use strict"; | ||
else { | ||
(_b = orNewSim === null || orNewSim === void 0 ? void 0 : orNewSim.subscribe) === null || _b === void 0 ? void 0 : _b.call(orNewSim, intent); | ||
(_b = orNewSim === null || orNewSim === void 0 ? void 0 : orNewSim.intentSubscribe) === null || _b === void 0 ? void 0 : _b.call(orNewSim, intent); | ||
} | ||
@@ -39,0 +39,0 @@ } |
{ | ||
"name": "simple-boot-core", | ||
"version": "1.0.21", | ||
"version": "1.0.22", | ||
"main": "SimpleApplication.js", | ||
@@ -52,2 +52,3 @@ "license": "MIT", | ||
"tsc": "tsc", | ||
"tsc:watch": "rm -rf ./dist && mkdir dist && cp package.json dist && tsc --watch --sourceMap true", | ||
"test": "jest --detectOpenHandles --forceExit" | ||
@@ -54,0 +55,0 @@ }, |
@@ -5,16 +5,17 @@ SIMPLE-BOOT-CORE | ||
## Sim LifeCycle | ||
* onCreate: Object create | ||
OnSimCreate | ||
* onSimCreate: Object create | ||
```typescript | ||
const option = new CustomSimOption([GlobalAdvice]); | ||
const option = new SimOption([GlobalAdvice]); | ||
const simpleApplication = new SimpleApplication(AppRouter, option); | ||
simpleApplication.run(); | ||
const url = '/users/d51515dd'; | ||
simpleApplication.routing<SimAtomic<any>, any>(new Intent(url)).then(it => { | ||
console.log('--->', it.pathData); | ||
const intent = new Intent('/b/asd/vv'); | ||
simpleApplication.routing<SimAtomic<any>, any>(intent).then(it => { | ||
console.log('--->', it.pathData, it.routerChains); | ||
let moduleInstance = it.getModuleInstance<User>(); | ||
moduleInstance.print(); | ||
console.log('-22->', moduleInstance); | ||
moduleInstance?.print(); | ||
console.log('------->' , simpleApplication.routerManager.activeRouterModule) | ||
}); | ||
``` | ||
@@ -24,17 +25,9 @@ | ||
```typescript | ||
import { A } from './A'; | ||
import { B } from './B'; | ||
import { Router, RouterConfig, Sim, SimConfig } from 'simple-boot-core/decorators/SimDecorator'; | ||
import { Intent } from 'simple-boot-core/intent/Intent'; | ||
import { ConstructorType } from 'simple-boot-core/types/Types'; | ||
import { UserRouter } from './users/UserRouter'; | ||
@Sim() | ||
@Router({ | ||
route: { | ||
'': A, | ||
'/': A, | ||
'': '/', | ||
'/': [A, {a: 123}], | ||
'/b': B, | ||
'/b/:aa/vv': B | ||
'/b/:aa/vv': [B, {b:'zzzzz'}] | ||
}, | ||
@@ -44,3 +37,3 @@ path: '', | ||
}) | ||
export class AppRouter { | ||
export class AppRouter implements RouterAction { | ||
@@ -51,22 +44,16 @@ | ||
notFound(url: Intent): ConstructorType<Object> | undefined { | ||
console.log('notfound--->'); | ||
return undefined | ||
canActivate(url: Intent, module: any): void { | ||
console.log('AppRouter canActivate->>>>>', url, module) | ||
} | ||
} | ||
``` | ||
# router | ||
- RouterAction | ||
- canActivate(url: Intent, module: any): void | ||
```typescript | ||
import {Sim} from "simple-boot-core/decorators/SimDecorator"; | ||
import {Intent} from "simple-boot-core/intent/Intent"; | ||
import {CustomModule} from "./CustomModule"; | ||
@Sim({scheme: 'A'}) | ||
export class A extends CustomModule { | ||
export class A { | ||
constructor() { | ||
super(); | ||
console.log('--->aA') | ||
@@ -82,22 +69,14 @@ } | ||
} | ||
} | ||
import {Sim} from "simple-boot-core/decorators/SimDecorator"; | ||
import {A} from "./A"; | ||
import {UserNotFound} from "./exceptions/UserNotFound"; | ||
import {Intent} from "simple-boot-core/intent/Intent"; | ||
import {CustomSimOption} from "./CustomSimOption"; | ||
import {CustomModule} from "./CustomModule"; | ||
import {RouterManager} from "simple-boot-core/route/RouterManager"; | ||
import {SimstanceManager} from "simple-boot-core/simstance/SimstanceManager"; | ||
``` | ||
# intent subscribe | ||
- IntentSubscribe | ||
- intentSubscribe(intent: Intent): void; | ||
```typescript | ||
@Sim() | ||
export class B extends CustomModule { | ||
constructor(private a: A, private option: CustomSimOption, private routerManager: RouterManager, private simstanceManager: SimstanceManager) { | ||
super(); | ||
export class B { | ||
constructor(private a: A, private routerManager: RouterManager, private simstanceManager: SimstanceManager) { | ||
} | ||
@@ -110,10 +89,11 @@ | ||
intentSubscribe(intent: Intent) { | ||
//receive | ||
} | ||
err() { | ||
// this.publish(new Intent('A://gogo?a=55', 'ddddddddddd')); | ||
// this.publish(new Intent('A://gogo?bb=44&ff=44', '444')); | ||
// this.publish(new Intent('A://gogo?gg=55&sadfsdf=444', '55')); | ||
throw new UserNotFound('good'); | ||
} | ||
} | ||
} | ||
``` |
@@ -1,4 +0,4 @@ | ||
import { Intent } from 'intent/Intent'; | ||
import { Intent } from '../intent/Intent'; | ||
export interface RouterAction { | ||
canActivate(url: Intent, module: any): void; | ||
} |
@@ -9,6 +9,7 @@ import 'reflect-metadata'; | ||
constructor(rootRouter: ConstructorType<any>); | ||
routing(intent: Intent): Promise<RouterModule<any, any> | undefined>; | ||
routing(intent: Intent): Promise<RouterModule<any, any>>; | ||
private getExecuteModule; | ||
private isRootUrl; | ||
private findRouting; | ||
private findRouteProperty; | ||
} |
@@ -49,5 +49,6 @@ "use strict"; | ||
RouterManager.prototype.routing = function (intent) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var routers, routerAtomic, rootRouterData, rootRouter, executeModule, notFound, _i, _a, route, nf; | ||
return __generator(this, function (_b) { | ||
var routers, routerAtomic, rootRouterData, rootRouter, executeModule, date, routerChain, lastRouter; | ||
return __generator(this, function (_o) { | ||
routers = []; | ||
@@ -58,22 +59,33 @@ routerAtomic = new SimAtomic_1.SimAtomic(this.rootRouter); | ||
executeModule = this.getExecuteModule(routerAtomic, intent, routers); | ||
if (!executeModule) { | ||
notFound = void 0; | ||
for (_i = 0, _a = routers.slice().reverse(); _i < _a.length; _i++) { | ||
route = _a[_i]; | ||
if (route !== rootRouter && route.notFound) { | ||
nf = route.notFound(intent); | ||
if (nf) { | ||
notFound = nf; | ||
break; | ||
} | ||
} | ||
date = new Date().getTime(); | ||
if (executeModule === null || executeModule === void 0 ? void 0 : executeModule.router) { | ||
executeModule.routerChains = routers; | ||
if (((_a = executeModule.routerChains) === null || _a === void 0 ? void 0 : _a.length) && ((_b = executeModule.routerChains) === null || _b === void 0 ? void 0 : _b.length) > 0) { | ||
(_d = (_c = executeModule.routerChains) === null || _c === void 0 ? void 0 : _c.reduce) === null || _d === void 0 ? void 0 : _d.call(_c, function (a, b) { | ||
var _a; | ||
var value = a.value; | ||
(_a = value === null || value === void 0 ? void 0 : value.canActivate) === null || _a === void 0 ? void 0 : _a.call(value, intent, b.value); | ||
return b; | ||
}); | ||
} | ||
return [2, this.activeRouterModule = new RouterModule_1.RouterModule(rootRouter, notFound, routers)]; | ||
} | ||
if (executeModule.router) { | ||
executeModule.routerChains = routers; | ||
if (!(executeModule === null || executeModule === void 0 ? void 0 : executeModule.module)) { | ||
routerChain = executeModule.routerChains[executeModule.routerChains.length - 1]; | ||
(_f = (_e = routerChain === null || routerChain === void 0 ? void 0 : routerChain.value) === null || _e === void 0 ? void 0 : _e.canActivate) === null || _f === void 0 ? void 0 : _f.call(_e, intent, executeModule.getModuleInstance()); | ||
} | ||
else { | ||
(_j = (_h = (_g = executeModule.router) === null || _g === void 0 ? void 0 : _g.value) === null || _h === void 0 ? void 0 : _h.canActivate) === null || _j === void 0 ? void 0 : _j.call(_h, intent, executeModule.getModuleInstance()); | ||
} | ||
return [2, this.activeRouterModule = executeModule]; | ||
} | ||
else { | ||
return [2, undefined]; | ||
if (routers.length && routers.length > 0) { | ||
lastRouter = (_k = routers.reduce) === null || _k === void 0 ? void 0 : _k.call(routers, function (a, b) { | ||
var _a; | ||
var value = a.value; | ||
(_a = value === null || value === void 0 ? void 0 : value.canActivate) === null || _a === void 0 ? void 0 : _a.call(value, intent, b.value); | ||
return b; | ||
}); | ||
(_m = (_l = lastRouter.value) === null || _l === void 0 ? void 0 : _l.canActivate) === null || _m === void 0 ? void 0 : _m.call(_l, intent, null); | ||
} | ||
return [2, this.activeRouterModule = new RouterModule_1.RouterModule(rootRouter, undefined, routers)]; | ||
} | ||
@@ -121,3 +133,5 @@ return [2]; | ||
if (pathnameData) { | ||
var rm = new RouterModule_1.RouterModule(router, routerData.route[it_1]); | ||
var _b = this.findRouteProperty(routerData.route, it_1), child = _b.child, data = _b.data; | ||
var rm = new RouterModule_1.RouterModule(router, child); | ||
rm.data = data; | ||
rm.pathData = pathnameData; | ||
@@ -128,4 +142,23 @@ return rm; | ||
}; | ||
RouterManager.prototype.findRouteProperty = function (route, propertyName) { | ||
var child; | ||
var data; | ||
var routeElement = route[propertyName]; | ||
if (typeof routeElement === 'function') { | ||
child = routeElement; | ||
} | ||
else if (typeof routeElement === 'string') { | ||
return this.findRouteProperty(route, routeElement); | ||
} | ||
else { | ||
child = routeElement[0]; | ||
data = routeElement[1]; | ||
} | ||
return { | ||
child: child, | ||
data: data | ||
}; | ||
}; | ||
return RouterManager; | ||
}()); | ||
exports.RouterManager = RouterManager; |
@@ -10,4 +10,5 @@ import { ConstructorType } from '../types/Types'; | ||
}; | ||
data?: any; | ||
constructor(router?: R | undefined, module?: ConstructorType<M> | undefined, routerChains?: R[]); | ||
getModuleInstance<T = M>(): T; | ||
} |
import { Runnable } from './run/Runnable'; | ||
import { SimstanceManager } from './simstance/SimstanceManager'; | ||
import { SimOption } from './SimOption'; | ||
import { IntentManager } from './intent/IntentManager'; | ||
import { RouterManager } from './route/RouterManager'; | ||
import { Intent } from './intent/Intent'; | ||
@@ -12,8 +14,8 @@ import { ConstructorType } from './types/Types'; | ||
simstanceManager: SimstanceManager; | ||
private intentManager; | ||
private routerManager; | ||
intentManager: IntentManager; | ||
routerManager: RouterManager; | ||
constructor(rootRouter: ConstructorType<Object>, option?: SimOption); | ||
run(): void; | ||
publishIntent(i: Intent): void; | ||
routing<R = SimAtomic, M = any>(i: Intent): Promise<RouterModule<R, M> | undefined>; | ||
routing<R = SimAtomic, M = any>(i: Intent): Promise<RouterModule<any, any>>; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -65,13 +29,3 @@ exports.SimpleApplication = void 0; | ||
SimpleApplication.prototype.routing = function (i) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var promise; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, this.routerManager.routing(i)]; | ||
case 1: | ||
promise = _a.sent(); | ||
return [2, promise]; | ||
} | ||
}); | ||
}); | ||
return this.routerManager.routing(i); | ||
}; | ||
@@ -78,0 +32,0 @@ return SimpleApplication; |
@@ -79,2 +79,3 @@ "use strict"; | ||
var _this = this; | ||
var _a; | ||
var registed = this._storage.get(target); | ||
@@ -86,5 +87,3 @@ if (registed) { | ||
var newSim = this.newSim(target, function (data) { return _this._storage.set(target, data); }); | ||
if (newSim && newSim.onCreate) { | ||
newSim.onCreate(); | ||
} | ||
(_a = newSim === null || newSim === void 0 ? void 0 : newSim.onSimCreate) === null || _a === void 0 ? void 0 : _a.call(newSim); | ||
return newSim; | ||
@@ -91,0 +90,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68
72414
1631
94