@sharpps/core
v2.0.0
Published
```typescript // Typescript / ESM import * as sharpps from '@sharpps/core'; ```
Downloads
158
Readme
@sharpps/core
Usage
📌 Import as Module
// Typescript / ESM
import * as sharpps from '@sharpps/core';Dependency Injection
import * as ps from '@sharpps/core';
import { registerDbContext } from '@sharpps/core/dist/data';
import pretty from 'pino-pretty';
export const di:ps.dependecyInjection.IServiceConfigurator = {
configure(services, configuration) {
//use services.register with token here
const level:string = configuration.APP_LOGGING_LEVEL ?? "debug";
services.register(ps.options.ConfigureOptions<ps.logging.LoggerOption>, {
useValue: new ps.options.ConfigureOptions<ps.logging.LoggerOption>({}
,ps.logging.LoggerOption
,x => {
x.level = level;
x.target = pretty({
colorize: true,
});
})
});
const c:Options = {
dialect:'mysql',
database: 'appdatabase',
host:'localhost',
username: 'root',
password: 'Password'
};
registerDbContext(DatabaseContext, services, c);
}
}Service Provider
import { IServiceScope } from "@sharpps/core/dist/dependencyInjection";
const scopeFactory = scope.getProvider().getService(ps.dependecyInjection.ServiceScopeFactory);
const s = scopeFactory.createScope();
const p = s.getProvider();Pipeline
import * as ps from '@sharpps/core';
const pipeline = p.getService(ps.pipeline.PipelineFactory).create<ps.pipeline.PipelineArgs, string>();
await pipeline.run({
serviceProvider : p,
loggerName: "app",
customData: {}
}, "initialize");HttpClient
import { HttpFactory } from '@sharpps/core/dist/http';
const factory = serviceProvider.getService(HttpFactory);
const httpClient = factory.createHttpClient("default");
httpClient({ url : "https://httpbin.org/get", method: "GET" })
.then(x => console.log(x))
.catch(x => console.error(x));Notification
import { HttpFactory } from '@sharpps/core/dist/http';
const payload = createNotification("output", { validated : 1 }, ["error"]);Logger
import * as ps from '@sharpps/core';
const logFactory = p.getService(ps.logging.LoggerFactory);
const logger = logFactory.createLogger("app");
logger.info({obj : 1}, "Message with object", { p : 1});