Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
core readme
Browse files Browse the repository at this point in the history
  • Loading branch information
borisovg committed Apr 30, 2024
1 parent e40cf64 commit f91c800
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
# @101-ways/core

Base package for building accelerator packages. It uses the Service Registry pattern to create a single object with APIs.

## Usage

```ts
import { load } from '@101-ways/core';

loadCore([`${__dirname}/modules`]).then((sr) => {
console.log('SERVICE REGISTRY', sr);
});
```

Basic example for creating a child package:

```ts
import { load as loadCore, type Registry } from '@101-ways/core';

export type { Registry };

export async function load<T extends Registry>(paths: string[] = [], sr?: T) {
return loadCore([`${__dirname}/modules`, ...paths], sr);
}
```

## Service Registry API

- sr.config - configuration ([link](./src/modules/config.ts#14))
- 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
- sr.ctx.getTraceMeta() - get trace metadata from context in [ECS format](https://www.elastic.co/guide/en/ecs/current/ecs-tracing.html)
- sr.ctx.toTraceMeta(ctx) - as above but using provided context
- sr.ctx.run(fn) - run a function with async context
- sr.ecs - [ECS schema](https://www.elastic.co/guide/en/ecs/current/ecs-field-reference.html) methods
- sr.ecs.makeEventFn() - returns a function that will in turn generate and ECS event object
- sr.log - logger methods
- sr.log.debug(params)
- sr.log.error(params)
- sr.log.info(params)
- sr.log.trace(params)
- sr.log.warn(params)
- sr.uuid - UUID generation methods
- sr.uuid.v4() - generate a UUIDv4 string

0 comments on commit f91c800

Please sign in to comment.