From 7cf067addfc1057f7df0b569f31ac77085841d6a Mon Sep 17 00:00:00 2001 From: George Borisov Date: Tue, 30 Apr 2024 14:33:28 +0100 Subject: [PATCH] readme files --- packages/core-express/README.md | 18 ++++++--- packages/core-mongo-express/README.md | 25 +++++++++++++ packages/core-mongo/README.md | 45 +++++++++++++++++++++++ packages/core-mongo/src/modules/config.ts | 4 +- packages/core/README.md | 4 +- 5 files changed, 86 insertions(+), 10 deletions(-) diff --git a/packages/core-express/README.md b/packages/core-express/README.md index f2c45f5..a83c5b1 100644 --- a/packages/core-express/README.md +++ b/packages/core-express/README.md @@ -1,21 +1,29 @@ # @101-ways/core-express -[Express](https://expressjs.com/) server accelerator packages. It uses the Service Registry pattern to create a single object with APIs. +[Express](https://expressjs.com/) server accelerator package. It uses the Service Registry pattern to create a single object with APIs. + +## Features + +- starts server on port 8000 by default +- request / response logging with tracing metadata +- [asynchronous context](https://nodejs.org/api/async_context.html) within request flow ## Usage ```ts import { load } from '@101-ways/core-express'; -loadCore([`${__dirname}/modules`]).then((sr) => { - console.log('SERVICE REGISTRY', sr); +load([`${__dirname}/modules`]).then((sr) => { + sr.express.app.get('/hello', (req, res) => { + res.json({ result: 'hello world' }); + }); }); ``` Basic example for creating a child package: ```ts -import { load as loadCore, type Registry } from '@101-ways/core'; +import { load as loadCore, type Registry } from '@101-ways/express'; export type { Registry }; @@ -28,7 +36,7 @@ export async function load(paths: string[] = [], sr?: T) { Everything in [@101-ways/core](../core/README.md) and -- sr.config - configuration ([link](./src/modules/config.ts#14)) +- sr.config - configuration (see [./src/modules/config.ts](./src/modules/config.ts)) - sr.express - Express module methods - sr.express.app - Express app (see https://expressjs.com/en/4x/api.html#app) - sr.express.returnError(req, res, err, code?) - helper function to log and return an error diff --git a/packages/core-mongo-express/README.md b/packages/core-mongo-express/README.md index 2ab2cf9..eb38ea4 100644 --- a/packages/core-mongo-express/README.md +++ b/packages/core-mongo-express/README.md @@ -1 +1,26 @@ # @101-ways/core-mongo-express + +Express + MongoDB accelerator package. It uses the Service Registry pattern to create a single object with APIs. + +## Usage + +```ts +import { load } from '@101-ways/core-mongo-express'; + +load([`${__dirname}/modules`]).then((sr) => { + const collection = sr.mongo.db().collection('test'); + + sr.express.app.get('/hello', async (req, res) => { + const results = await collection.find({}).toArray(); + res.json({ results }); + }); +}); +``` + +## Service Registry API + +Combination of [@101-ways/core-express](../core-express/README.md) and [@101-ways/core-mongo](../core-mongo/README.md). + +## Environment Variables + +Combination of [@101-ways/core-express](../core-express/README.md) and [@101-ways/core-mongo](../core-mongo/README.md). diff --git a/packages/core-mongo/README.md b/packages/core-mongo/README.md index 3fbf6f7..8a5270d 100644 --- a/packages/core-mongo/README.md +++ b/packages/core-mongo/README.md @@ -1 +1,46 @@ # @101-ways/core-mongo + +[MongoDb](https://www.mongodb.com/) client accelerator package. It uses the Service Registry pattern to create a single object with APIs. + +## Features + +- starts server on port 8000 by default +- debug logging with tracing metadata + +## Usage + +```ts +import { load } from '@101-ways/core-mongo'; + +load([`${__dirname}/modules`]).then(async (sr) => { + const collection = sr.mongo.db().collection('test'); + const list = await collection.find({}).toArray(); + console.log(list); + sr.core.shutdown.run(); +}); +``` + +Basic example for creating a child package: + +```ts +import { load as loadCore, type Registry } from '@101-ways/core-mongo'; + +export type { Registry }; + +export async function load(paths: string[] = [], sr?: T) { + return loadCore([`${__dirname}/modules`, ...paths], sr); +} +``` + +## Service Registry API + +Everything in [@101-ways/core](../core/README.md) and + +- sr.config - configuration (see [./src/modules/config.ts](./src/modules/config.ts)) +- sr.mongo - MongoDB client (see https://mongodb.github.io/node-mongodb-native/6.5/classes/MongoClient.html) + +## Environment Variables + +Everything in [@101-ways/core](../core/README.md) and + +- MONGO_URI='mongodb://localhost:27017/test' - Mongo connection URI diff --git a/packages/core-mongo/src/modules/config.ts b/packages/core-mongo/src/modules/config.ts index 96e1940..f6a59f6 100644 --- a/packages/core-mongo/src/modules/config.ts +++ b/packages/core-mongo/src/modules/config.ts @@ -2,8 +2,7 @@ import { config as coreConfig } from '@101-ways/core'; import { Registry } from '../types'; -const { MONGO_DB = 'test', MONGO_URI = 'mongodb://localhost:27017/test' } = - process.env; +const { MONGO_URI = 'mongodb://localhost:27017/test' } = process.env; export function $onBind(sr: Registry) { sr.config = config; @@ -12,7 +11,6 @@ export function $onBind(sr: Registry) { export const config = { ...coreConfig, mongo: { - db: MONGO_DB, uri: MONGO_URI, }, }; diff --git a/packages/core/README.md b/packages/core/README.md index 033f98c..a4e2af0 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -7,7 +7,7 @@ Base package for building accelerator packages. It uses the Service Registry pat ```ts import { load } from '@101-ways/core'; -loadCore([`${__dirname}/modules`]).then((sr) => { +load([`${__dirname}/modules`]).then((sr) => { console.log('SERVICE REGISTRY', sr); }); ``` @@ -26,7 +26,7 @@ export async function load(paths: string[] = [], sr?: T) { ## Service Registry API -- sr.config - configuration ([link](./src/modules/config.ts#14)) +- sr.config - configuration (see [./src/modules/config.ts](./src/modules/config.ts)) - sr.core - inherited from `@borisovg/service-core` package (see https://github.com/borisovg/node-service-core/blob/main/src/types.ts#L6) - sr.ctx - [asynchronous context](https://nodejs.org/api/async_context.html) methods - sr.ctx.get() - get current context