simple-boot-core
Advanced tools
Comparing version 1.0.27 to 1.0.28
@@ -0,0 +0,0 @@ import 'reflect-metadata'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import 'reflect-metadata'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import 'reflect-metadata'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import 'reflect-metadata'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import "reflect-metadata"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ReflectMethod } from '../../types/Types'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import "reflect-metadata"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ReflectMethod, ConstructorType } from '../../types/Types'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -28,4 +28,4 @@ import { ConstructorType, GenericClassDecorator, ReflectMethod } from '../../types/Types'; | ||
export declare const Route: (config: RouteConfig) => ReflectMethod; | ||
export declare const getRoute: (target: any, propertyKey: string) => RouteConfig | undefined; | ||
export declare const getRoute: (target: any, propertyKey: string | symbol) => RouteConfig | undefined; | ||
export declare const getRoutes: (target: any) => SaveRouteConfig[] | undefined; | ||
export {}; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import "reflect-metadata"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ConstructorType, MethodParameter, ReflectField } from '../../types/Types'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ValidationResult } from '../decorators/validate/Validation'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare enum PublishType { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Intent } from './Intent'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -0,0 +0,0 @@ import { Intent } from './Intent'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Intent } from './Intent'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
export interface OnSimCreate { | ||
onSimCreate(): void; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
{ | ||
"name": "simple-boot-core", | ||
"version": "1.0.27", | ||
"version": "1.0.28", | ||
"main": "SimpleApplication.js", | ||
@@ -58,2 +58,5 @@ "license": "MIT", | ||
}, | ||
"dependencies": { | ||
"reflect-metadata": "^0.1.13" | ||
}, | ||
"devDependencies": { | ||
@@ -71,3 +74,2 @@ "@types/jest": "^26.0.22", | ||
"mkdirp": "^1.0.4", | ||
"reflect-metadata": "^0.1.13", | ||
"supertest": "^6.1.3", | ||
@@ -74,0 +76,0 @@ "ts-jest": "^26.5.4", |
@@ -0,0 +0,0 @@ import { SimstanceManager } from '../simstance/SimstanceManager'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare class AsyncBlockingQueue<T> { |
@@ -0,0 +0,0 @@ "use strict"; |
385
README.MD
SIMPLE-BOOT-CORE | ||
=== | ||
It provides convenience in service development. | ||
![typescript](https://img.shields.io/badge/-typescript-black?logo=typescript) [![typescript](https://img.shields.io/badge/-npm-black?logo=npm)](https://www.npmjs.com/package/simple-boot-core) [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE.md) | ||
## Sim LifeCycle | ||
OnSimCreate | ||
* onSimCreate: Object create | ||
* Object management. | ||
* Dependency Injection (DI) | ||
* Life cycle provided. | ||
* Aspect Oriented Programming (AOP) | ||
* ExceptionHandler (Global or Local) | ||
* Router System | ||
* Intent Event System | ||
## 🚀 Quick start | ||
```shell | ||
npm init -y | ||
npm install simple-boot-core | ||
npm install ts-node --save-dev | ||
tsc --init --experimentalDecorators --emitDecoratorMetadata | ||
``` | ||
```json | ||
// package.json add scripts ts-node | ||
{ | ||
// ... | ||
"scripts": { | ||
"start": "ts-node index.ts", | ||
} | ||
} | ||
``` | ||
```typescript | ||
const option = new SimOption([GlobalAdvice]); | ||
const simpleApplication = new SimpleApplication(AppRouter, option); | ||
simpleApplication.run(); | ||
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>(); | ||
console.log('-22->', moduleInstance); | ||
moduleInstance?.print(); | ||
console.log('------->' , simpleApplication.routerManager.activeRouterModule) | ||
}); | ||
// index.ts | ||
import {SimpleApplication} from 'simple-boot-core'; | ||
import {Router} from 'simple-boot-core/decorators/route/Router'; | ||
import {Sim} from 'simple-boot-core/decorators/SimDecorator'; | ||
@Sim() | ||
class User { | ||
say() { | ||
console.log('say~ hello'); | ||
} | ||
} | ||
@Sim() @Router({ path: '', route: {'/user': User}}) | ||
class AppRouter {} | ||
new SimpleApplication(AppRouter).run().routing('/user').then(it => { | ||
it.getModuleInstance<User>()?.say(); | ||
}) | ||
``` | ||
```shell | ||
npm start | ||
# say~ hello | ||
``` | ||
## Object management. | ||
<details> | ||
<summary>Dependency Injection (DI) <strong>🔻(click)</strong></summary> | ||
## @Sim | ||
Decorators must be declared to be managed. | ||
```typescript | ||
@Sim() | ||
@Router({ | ||
route: { | ||
'': '/', | ||
'/': [A, {a: 123}], | ||
'/b': B, | ||
'/b/{aa}/vv': [B, {b:'zzzzz'}] | ||
}, | ||
path: '', | ||
routers: [UserRouter] | ||
class ProjectService { | ||
sum(x: number, y: number) { | ||
return x + y; | ||
} | ||
} | ||
@Sim() | ||
class User { | ||
constructor(private projectService: ProjectService) { | ||
} | ||
say() { | ||
console.log(`say~ hello: ${this.projectService.sum(5, 25)}`); | ||
} | ||
} | ||
// result: say~ hello: 30 | ||
``` | ||
</details> | ||
<details> | ||
<summary>Life cycle provided <strong>🔻(click)</strong></summary> | ||
## OnSimCreate interface | ||
Sim Object created just one call | ||
```typescript | ||
@Sim() | ||
class User implements OnSimCreate { | ||
onSimCreate(): void { | ||
console.log('on Create') | ||
} | ||
} | ||
// output 💥 | ||
// on Create | ||
``` | ||
</details> | ||
## Aspect Oriented Programming (AOP) | ||
<details> | ||
<summary>Method call AOP <strong>🔻(click)</strong></summary> | ||
## @Before @After | ||
```typescript | ||
@Sim() | ||
class User { | ||
@Before({property: 'say'}) | ||
sayBefore() { | ||
console.log('sayBefore') | ||
} | ||
@After({property: 'say'}) | ||
sayAfter() { | ||
console.log('sayAfter') | ||
} | ||
say() { | ||
console.log(`say~ hello`); | ||
} | ||
} | ||
// 💥 call say() | ||
// sayBefore | ||
// say~ hello: 30 | ||
// sayAfter | ||
``` | ||
</details> | ||
## ExceptionHandler (Global or Local) | ||
<details> | ||
<summary>Local Exception Advice <strong>🔻(click)</strong></summary> | ||
## @ExceptionHandler | ||
```typescript | ||
@Sim() | ||
class User { | ||
@ExceptionHandler() | ||
otherException(@Inject({situationType: ExceptionHandlerSituationType.ERROR_OBJECT}) e: any) { | ||
console.log(`otherException : ${e.message}`) | ||
} | ||
@ExceptionHandler({type: Error}) | ||
errorTypeException(e: Error) { | ||
console.log(`errorTypeException : ${e.message}`) | ||
} | ||
say1() { | ||
console.log(`say~ hello`); | ||
throw {message: 'otherException'} | ||
} | ||
say2() { | ||
console.log(`say~ hello`); | ||
throw new Error('error'); | ||
} | ||
} | ||
// 💥 call say1() | ||
// say~ hello | ||
// { message: 'otherException' } | ||
// otherException : otherException | ||
// 💥 call say2() | ||
// say~ hello | ||
// Error: error at ... | ||
// errorTypeException : error | ||
``` | ||
</details> | ||
<details> | ||
<summary>Global Exception Advice <strong>🔻(click)</strong></summary> | ||
```typescript | ||
@Sim() | ||
class GlobalAdvice { | ||
@ExceptionHandler() | ||
otherException(@Inject({situationType: ExceptionHandlerSituationType.ERROR_OBJECT}) e: any) { | ||
console.log(`otherException : ${e.message}`) | ||
} | ||
@ExceptionHandler({type: Error}) | ||
errorTypeException(e: Error) { | ||
console.log(`errorTypeException : ${e.message}`) | ||
} | ||
} | ||
@Sim() | ||
class User { | ||
say1() { | ||
console.log(`say~ hello`); | ||
throw {message: 'otherException'} | ||
} | ||
say2() { | ||
console.log(`say~ hello`); | ||
throw new Error('error'); | ||
} | ||
} | ||
const option = new SimOption([GlobalAdvice]) | ||
new SimpleApplication(AppRouter, option).run().routing('/user').then(it => { | ||
it.getModuleInstance<User>()?.say1(); | ||
}) | ||
export class AppRouter implements RouterAction { | ||
// 💥 call say1() | ||
// say~ hello | ||
// { message: 'otherException' } | ||
// otherException : otherException | ||
// 💥 call say2() | ||
// say~ hello | ||
// Error: error at ... | ||
// errorTypeException : error | ||
constructor() { | ||
} | ||
``` | ||
</details> | ||
canActivate(url: Intent, module: any): void { | ||
console.log('AppRouter canActivate->>>>>', url, module) | ||
} | ||
## Router System | ||
<details> | ||
<summary>@Router<strong>🔻(click)</strong></summary> | ||
```typescript | ||
@Sim() | ||
@Router({ | ||
path: '', | ||
route: { | ||
'/user': User | ||
} | ||
}) | ||
class AppRouter { | ||
} | ||
``` | ||
# router | ||
- RouterAction | ||
- canActivate(url: Intent, module: any): void | ||
</details> | ||
<details> | ||
<summary>RouterAction Interface<strong>🔻(click)</strong></summary> | ||
### route change call canActivate merhod | ||
```typescript | ||
@Sim({scheme: 'A'}) | ||
export class A { | ||
constructor() { | ||
console.log('--->aA') | ||
} | ||
@Sim() | ||
@Router({ | ||
path: '', | ||
route: { | ||
'/user': User | ||
} | ||
}) | ||
class AppRouter implements RouterAction { | ||
print(){ | ||
console.log('print') | ||
} | ||
async canActivate(url: Intent, module: any) { | ||
console.log('--', url, module) | ||
} | ||
gogo(intent: Intent) { | ||
console.log('gogogo', intent); | ||
} | ||
} | ||
const option = new SimOption([GlobalAdvice]) | ||
new SimpleApplication(AppRouter, option).run().routing('/user').then(it => { | ||
it.getModuleInstance<User>()?.say(); | ||
}) | ||
// output 💥 | ||
// -- Intent { uri: '/user', data: undefined, event: undefined } User { say: [Function (anonymous)], say2: [Function (anonymous)] } | ||
// say~ hello | ||
``` | ||
</details> | ||
# intent subscribe | ||
- IntentSubscribe | ||
- intentSubscribe(intent: Intent): void; | ||
<details> | ||
<summary>@Route<strong>🔻(click)</strong></summary> | ||
```typescript | ||
@Sim() | ||
export class B { | ||
constructor(private a: A, private routerManager: RouterManager, private simstanceManager: SimstanceManager) { | ||
} | ||
@Router({ | ||
path: '' | ||
}) | ||
class AppRouter { | ||
@Route({path:'/user'}) | ||
user1() { | ||
console.log('user say1~') | ||
} | ||
@Route({path:'/user'}) | ||
user2() { | ||
console.log('user say2~') | ||
} | ||
} | ||
print() { | ||
this.a.print(); | ||
console.log('bbb print', this.routerManager.activeRouterModule.pathData.aa) | ||
} | ||
const option = new SimOption([GlobalAdvice]) | ||
new SimpleApplication(AppRouter, option).run().routing('/user').then(it => { | ||
it.propertyKeys?.forEach(key => { | ||
it.executeModuleProperty(key); | ||
}) | ||
}) | ||
// output 💥 | ||
// user say1~ | ||
// user say2~ | ||
intentSubscribe(intent: Intent) { | ||
//receive | ||
} | ||
err() { | ||
throw new UserNotFound('good'); | ||
} | ||
``` | ||
</details> | ||
## Intent Event System | ||
<details> | ||
<summary>Intent Message<strong>🔻(click)</strong></summary> | ||
* transmit data between objects and generate events | ||
* send data and generate events to @Sim scheme | ||
- Support Object transmission | ||
- Support query parameters | ||
- Allocate directly to variables | ||
- Calling the method | ||
```typescript | ||
@Sim({scheme: 'AppRouter'}) @Router({path: '',route: {'/user': User}}) | ||
class AppRouter { | ||
say(intent: Intent) { | ||
console.log('say1-->', intent.data); | ||
} | ||
} | ||
``` | ||
```typescript | ||
const app = new SimpleApplication(AppRouter).run(); | ||
app.publishIntent(new Intent('AppRouter://say1', {name: 'visualkhh', age: 99})); | ||
// output 💥 | ||
// say1--> { name: 'visualkhh', age: 99 } | ||
``` | ||
```typescript | ||
const intent = new Intent('AppRouter://say2', ['visualkhh', 99]); | ||
intent.publishType = PublishType.INLINE_DATA_PARAMETERS; | ||
app.publishIntent(intent); | ||
// output 💥 | ||
// say2--> visualkhh 99 | ||
``` | ||
```typescript | ||
const global = new Intent('://say2'); // <-- global intent message event | ||
const queryParam = new Intent('scheme://say2?age=5&name=visualkhh'); // <-- query parameter | ||
queryParam.queryParams.name; | ||
queryParam.queryParams.age; | ||
``` | ||
</details> | ||
``` | ||
# License | ||
* MIT | ||
* visualkhh@gmail.com | ||
import { Intent } from '../intent/Intent'; | ||
export interface RouterAction { | ||
canActivate(url: Intent, module: any): Promise<void>; | ||
hasActivate(checkObj: any): boolean; | ||
hasActivate?(checkObj: any): boolean; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -13,3 +13,3 @@ import { Intent } from '../intent/Intent'; | ||
}; | ||
routing(intent: Intent): Promise<RouterModule | undefined>; | ||
routing(intent: Intent): Promise<RouterModule>; | ||
private getExecuteModule; | ||
@@ -16,0 +16,0 @@ private isRootUrl; |
@@ -196,3 +196,3 @@ "use strict"; | ||
this.activeRouterModule = routerModule; | ||
return [2, rootRouter]; | ||
return [2, this.activeRouterModule]; | ||
} | ||
@@ -199,0 +199,0 @@ }); |
@@ -0,0 +0,0 @@ import { ConstructorType } from '../types/Types'; |
@@ -0,0 +0,0 @@ "use strict"; |
export interface Runnable { | ||
run(...data: any): any; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -0,0 +0,0 @@ import { ConstructorType } from './types/Types'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -18,5 +18,7 @@ import { Runnable } from './run/Runnable'; | ||
constructor(rootRouter: ConstructorType<Object>, option?: SimOption); | ||
run(otherInstanceSim?: Map<ConstructorType<any>, any>): void; | ||
run(otherInstanceSim?: Map<ConstructorType<any>, any>): SimpleApplication; | ||
publishIntent(i: string, data?: any): any[]; | ||
publishIntent(i: Intent): any[]; | ||
routing<R = SimAtomic, M = any>(i: Intent): Promise<RouterModule | undefined>; | ||
routing<R = SimAtomic, M = any>(i: string, data?: any): Promise<RouterModule>; | ||
routing<R = SimAtomic, M = any>(i: Intent): Promise<RouterModule>; | ||
} |
@@ -8,2 +8,3 @@ "use strict"; | ||
var RouterManager_1 = require("./route/RouterManager"); | ||
var Intent_1 = require("./intent/Intent"); | ||
require("reflect-metadata"); | ||
@@ -25,8 +26,19 @@ var SimpleApplication = (function () { | ||
this.simstanceManager.run(otherInstanceSim); | ||
return this; | ||
}; | ||
SimpleApplication.prototype.publishIntent = function (i) { | ||
return this.intentManager.publish(i); | ||
SimpleApplication.prototype.publishIntent = function (i, data) { | ||
if (i instanceof Intent_1.Intent) { | ||
return this.intentManager.publish(i); | ||
} | ||
else { | ||
return this.intentManager.publish(i, data); | ||
} | ||
}; | ||
SimpleApplication.prototype.routing = function (i) { | ||
return this.routerManager.routing(i); | ||
SimpleApplication.prototype.routing = function (i, data) { | ||
if (i instanceof Intent_1.Intent) { | ||
return this.routerManager.routing(i); | ||
} | ||
else { | ||
return this.routerManager.routing(new Intent_1.Intent(i, data)); | ||
} | ||
}; | ||
@@ -33,0 +45,0 @@ return SimpleApplication; |
@@ -0,0 +0,0 @@ import { ConstructorType } from '../types/Types'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import "reflect-metadata"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare class SimError { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { SimError } from './SimError'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export interface ConstructorType<T> { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -0,0 +0,0 @@ export declare class ConvertUtils { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare class FunctionUtils { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ConstructorType } from '../../types/Types'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare class RandomUtils { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import 'reflect-metadata'; |
@@ -0,0 +0,0 @@ "use strict"; |
export declare class ValidUtils { | ||
static isNullOrUndefined(data: any): boolean; | ||
static isNotNullUndefined(data: any): boolean; | ||
static isNull(data: any): boolean; | ||
static isUndefined(data: any): boolean; | ||
static isArray(object_o: any): boolean; | ||
@@ -5,0 +7,0 @@ static isNumber(object_o: any): boolean; |
@@ -8,17 +8,13 @@ "use strict"; | ||
ValidUtils.isNullOrUndefined = function (data) { | ||
if (data == null || undefined === data) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
return data == null || undefined === data; | ||
}; | ||
ValidUtils.isNotNullUndefined = function (data) { | ||
return data !== null && data !== undefined; | ||
}; | ||
ValidUtils.isNull = function (data) { | ||
if (data == null) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
return data === null; | ||
}; | ||
ValidUtils.isUndefined = function (data) { | ||
return data === undefined; | ||
}; | ||
ValidUtils.isArray = function (object_o) { | ||
@@ -25,0 +21,0 @@ if (ValidUtils.isNullOrUndefined(object_o)) { |
126147
14
357
1
74
2631
+ Addedreflect-metadata@^0.1.13
+ Addedreflect-metadata@0.1.14(transitive)