Giter VIP home page Giter VIP logo

noel-archive / lilith Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 2.0 3.97 MB

πŸ»β€β„οΈπŸͺ‘ Modern and cutesy application framework for TypeScript to build robust, object-orientated services

Home Page: https://docs.noelware.org/libraries/lilith

License: MIT License

TypeScript 84.28% Shell 1.04% JavaScript 13.56% Dockerfile 1.13%
typescript framework app-framework nodejs ts noelware dependency-injection container

lilith's Introduction

🧡 Lilith

Application framework for TypeScript to build robust, and simple services

Lilith is Noelware's framework to build JavaScript-based microservices with TypeScript! It is used to build robust applications with TypeScript with the tools you need to build it! Lilith comes with pre-built libraries that makes it easy to work with:

  • @noelware/lilith-logging ~ Package to handle logging scenarios, combined with the @noelware/lilith-config package also!
  • @noelware/lilith-config ~ Package to handle different configuration sources, that are easily injectable with the @Variable decorator.

Usage

Warning β€” Lilith v6 and above is not compatible with older versions of Lilith, so you will need to refractor your whole application that was built upon Lilith. You can read up on the migration section.

$ npm install @noelware/lilith
$ yarn add @noelware/lilith
$ pnpm install @noelware/lilith
import { createLilith, singleton, service, inject } from '@noelware/lilith';

const container = createLilith({
  singletons: [
    // Defines a path to load singletons from
    { path: './path/to/singletons' },
    singleton<Logger>({
      provide() { return Logger.create(); }
      onLoad(logger /*: Logger */) { /* ran once singleton is loaded into the container */ },
      onDestroy(logger /*: Logger */) { /* destroy singleton */ }
    })
  ],

  services: [
    // Defines a path to load services from
    { path: './path/to/services' },
    service({
      name: 'myservice',
      children: [/* list of children that this service has control over */],
      onLoad() { /* called for loading the service (i.e, start http server/load config) */ },
      onDestroy() { /* called for destroying the service (i.e, stopping http service) */ },
      onChildLoad(child /*: any */) { /* called for loading children into the service scope */ },
      onChildDestroy(child /*: any */) { /* called for destroying children into the service scope */ },
    })
  ]
});

const logger = inject('logger');
// => Logger

const service = inject('myservice');
// => Service

Packages

@noelware/lilith

@noelware/lilith is the main library that ties together with the new packages like @noelware/lilith-logging. You use @noelware/lilith to manage the lifecycle of the managed IoC container to do dependency injection out of the box.

@noelware/lilith doesn't need any peer dependencies, but you will need to have reflect-metadata loaded before using @noelware/lilith because it depends on it!

$ npm install @noelware/lilith
$ yarn add @noelware/lilith
$ pnpm install @noelware/lilith
import { Service, Inject, createLilith } from '@noelware/lilith';

@Service({ name: 'a name' })
class MyService {
  @Inject
  private readonly other!: OtherService;

  onLoad() {
    console.log('I have loaded!');
  }
}

@Service({ name: 'another name', priority: 10 })
class OtherService {
  private readonly lucky: number = 42;

  get luckyNumber() {
    return this.lucky;
  }
}

const container = createLilith({
  services: [MyService, OtherService]
});

container.start();
  • Lilith will construct the container as a export of Container,
  • When you call start, the IoC hooks will be attached to the services in this minimal example,
  • Since services can be a higher priority, the services that have a high priority will be initialized first
    • You can't inject components that are even a higher priority in a high priority service since services are not lazily constructed (i.e, needed when it needs to be used). They're loaded automatically, only singletons are lazily loaded.
    • You can't have service names with the same name, you will get a TypeError thrown.
| ~~~~~~~~~~~~~~ |  /----> | another name |
| ioc container  | -             / \
| ~~~~~~~~~~~~~~ |  \----> |    a name    |

@noelware/lilith-logging

@noelware/lilith-logging is a service package that lets you inject a LoggerFactoryService into your services and creates a Logger for using logging. This package requires a peer dependency on winston:

$ npm install @noelware/lilith @noelware/lilith-logging @noelware/lilith-logging-winston winston
$ yarn add @noelware/lilith @noelware/lilith-logging @noelware/lilith-logging-winston winston
$ pnpm install @noelware/lilith @noelware/lilith-logging @noelware/lilith-logging-winston winston
import { Service, Inject, createLilith } from '@noelware/lilith';
import { LogService, type Logger } from '@noelware/lilith-logging';
import { WinstonBackend } from '@noelware/lilith-logging-winston';
import winston from 'winston';

@Service({ name: 'my service name' })
class MyService {
  @Inject
  private readonly logging!: LogService<WinstonBackend>;
  private readonly logger!: Logger;

  onLoad() {
    this.logger = this.logging.loggerFactory.get('my', 'service', 'info');
    this.logger.info('I am loading stuff!');
  }
}

const container = createLilith({
  services: [
    new LogService({
      defaultLevel: 'debug',
      backend: new WinstonBackend({
        transports: [new winston.transports.Console()]
      })
    }),
    MyService
  ]
});

container.start();

@noelware/lilith-config

@noelware/lilith-config is a service that gives you a way to simplify configuration files with a Zod schema. It has loaders for:

  • YAML (requires js-yaml)
  • JSON (no extra dependencies)
  • TOML (requires @ltd/j-toml)

@noelware/lilith-config has a peer dependency on zod if you wish to have schema validation. It is not required to have zod installed, it'll just ignore the configuration schema if provided.

$ npm install @noelware/lilith @noelware/lilith-config zod
$ yarn add @noelware/lilith @noelware/lilith-config zod
$ pnpm install @noelware/lilith @noelware/lilith-config zod
import { Service, Inject, createLilith } from '@noelware/lilith';
import { ConfigService, YamlLoader } from '@noelware/lilith-config';
import z from 'zod';

export interface Config {
  lol: boolean;
}

@Service({ name: 'my service' })
class MyService {
  @Inject
  private readonly config!: ConfigService<Config>;

  onLoad() {
    const shouldLol = this.config.get('lol');
    if (shouldLol) {
      console.log('lol!!!!');
    }
  }
}

const container = createLilith({
  services: [
    new ConfigService<Config>({
      schema: z
        .object({
          lol: z.boolean()
        })
        .strict(),

      loader: new YamlLoader()
    }),
    MyService
  ]
});

container.start();
const service = container.inject(MyService);

Contributing

Thanks for considering contributing to Lilith! Before you boop your heart out on your keyboard ✧ ─=≑Σ((( ぀‒̀ω‒́)぀, we recommend you to do the following:

If you read both if you're a new time contributor, now you can do the following:

  • Fork me! **β™‘( βŽα΅•α΄—α΅•βŽ οΌ‰
  • Clone your fork on your machine: git clone https://github.com/your-username/Lilith
  • Create a new branch: git checkout -b some-branch-name
  • BOOP THAT KEYBOARD!!!! ♑┉ˏ͛ (❛ γ€° ❛)ΛŠΛŽβ”‰β™‘
  • Commit your changes onto your branch: git commit -am "add features (q>β€Ώβ€Ώ<q οΌ‰"
  • Push it to the fork you created: git push -u origin some-branch-name
  • Submit a Pull Request and then cry! qο½₯゚゚ο½₯(ΰ°₯ Π” ΰ°₯。)ο½₯゚゚ο½₯q

License

Lilith is released under the MIT License with love by Noelware. :3

lilith's People

Contributors

auguwu avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

cyberflamego

lilith's Issues

Support constructor parameter injections

blueprint:

interface Inject {
    (target: Object, property: string | symbol): void;
    (target: Object, property: string | symbol, parameterIndex: number): void;
}

declare const Inject: Inject;

class Owo {
    @Inject
    readonly a!: number;

    constructor(@Inject a: string){}
}

feature: Add decorators

  • [] Add @Injectable / injectable(value)
    • So you don't have to make a seperate component/service, it can just be automatically injected.
  • [] Let @Inject be in constructor parameters
    • This can be difficult if you want to use TypeScript libraries with Lilith that have a dependency injection layer, i.e, type-graphql.
  • [] Add @Variable / addVariable(name, value)
    • Lilith will manage your application variables and inject them if needed.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update Yarn to v3.6.0
  • Update dependency @noelware/utils to v2.3.0
  • Update dependency tsup to v6.7.0
  • Update dependency winston to v3.9.0
  • Update dependency dot-prop to v8
  • Update dependency rimraf to v5
  • Update dependency typescript to v5
  • πŸ” Create all rate-limited PRs at once πŸ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

dockerfile
.devcontainer/Dockerfile
github-actions
.github/workflows/CodeQL.yml
  • actions/checkout v3
  • actions/setup-node v3
  • github/codeql-action v2
  • github/codeql-action v2
.github/workflows/ESLint.yml
  • actions/checkout v3
  • actions/setup-node v3
.github/workflows/Publish.yml
  • actions/checkout v3
  • actions/setup-node v3
npm
package.json
  • @actions/core 1.10.0
  • @augu/eslint-config 4.0.1
  • @noelware/utils 2.2.1
  • @types/eslint 8.4.6
  • @types/rimraf 3.0.2
  • eslint 8.24.0
  • eslint-config-prettier 8.6.0
  • leeks.js 0.2.4
  • log-symbols 5.1.0
  • prettier 2.7.1
  • rimraf 4.1.2
  • tsup 6.6.3
  • vitest 0.23.4
  • yarn 3.4.1
src/config/package.json
  • dot-prop 7.2.0
  • @augu/eslint-config 4.0.1
  • @augu/tsconfig 1.1.1
  • @types/js-yaml 4.0.5
  • @types/node 18.13.0
  • @typescript-eslint/eslint-plugin 5.52.0
  • @typescript-eslint/parser 5.52.0
  • eslint 8.24.0
  • eslint-config-prettier 8.6.0
  • type-fest 3.6.0
  • typescript 4.9.5
  • vitest 0.23.4
  • @ltd/j-toml 1.38.0
  • js-yaml 4.1.0
  • zod 3.20.6
src/lilith/package.json
  • @noelware/utils 2.2.1
  • reflect-metadata 0.1.13
  • @augu/eslint-config 4.0.1
  • @augu/tsconfig 1.1.1
  • @types/node 18.13.0
  • @typescript-eslint/eslint-plugin 5.52.0
  • @typescript-eslint/parser 5.52.0
  • eslint 8.24.0
  • eslint-config-prettier 8.6.0
  • type-fest 3.6.0
  • typescript 4.9.5
  • vitest 0.23.4
src/logging/package.json
  • leeks.js 0.2.4
  • @augu/eslint-config 4.0.1
  • @augu/tsconfig 1.1.1
  • @types/node 18.13.0
  • @typescript-eslint/eslint-plugin 5.52.0
  • @typescript-eslint/parser 5.52.0
  • eslint 8.24.0
  • eslint-config-prettier 8.6.0
  • type-fest 3.6.0
  • typescript 4.9.5
  • vitest 0.23.4
src/winston/package.json
  • @augu/eslint-config 4.0.1
  • @augu/tsconfig 1.1.1
  • @types/node 18.13.0
  • @typescript-eslint/eslint-plugin 5.52.0
  • @typescript-eslint/parser 5.52.0
  • eslint 8.24.0
  • eslint-config-prettier 8.6.0
  • type-fest 3.6.0
  • typescript 4.9.5
  • vitest 0.23.4
  • winston 3.8.2

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.