npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@yadah/yadah

v0.2.2

Published

Business logic layer fitting between your API and your database

Downloads

5

Readme

Yadah

Yadah helps building services by organising the "data layer" into "subsystems" and "domains".

The @yadah/yadah package re-exports modules from all the core Yadah packages to simplify package installation and usage.

Usage

npm install -w @myscope/package-name @yadah/yadah

A typical "data layer" package will have a folder structure like:

src/
  models/
    index.js
    Bar.js
    Foo.js
  domains/
    index.js
    Bar.js
    Foo.js
  index.js
  config.js

The src/index.js file is responsible for creating subsystem instances and initialising the "Yada domains classes" via the DataManager.

// packages/package-name/src/index.js
import {
  createContext,
  createKnex,
  createLogger,
  createMessageQueue,
  createPubSub,
  createSchedule,
  DataManager,
  Model,
} from "@yadah/yadah";
import config from "./config.js";
import * as modelModules from "./models/index.js";
import * as domainModules from "./domains/index.js";

// setup subsystems
export const models = modelModules;
export const context = createContext();
export const knex = createKnex(config.knex);
export const logger = createLogger(config.logger);
export const mq = createMessageQueue(knex, logger);
export const pubsub = createPubSub(knex, config.pubsub);
export const schedule = createSchedule(knex, logger, config.schedule);

// initialise the data manager
const dataManager = new DataManager({
  models,
  context,
  knex,
  logger,
  mq,
  pubsub,
  schedule,
});

// boot domains
export const domains = dataManager.boot(domainModules);

// lifecycle functions allow services to cleanly control startup and shutdown
export const startup = async () => {
  Model.knex(knex);
  await dataManager.startup();
};
export const shutdown = async () => {
  await dataManager.shutdown();
  await knex.destroy();
};

Other packages may then access subsystems and domains classes from this package.

import { domains, logger } from "@myscope/package-name";

const foo = await domains.Foo.find(123);
logger.info("message", foo);

data-manager

https://www.npmjs.com/package/@yadah/data-manager

class DataManager

Manages subsystems and domain classes

class Domain

Base Yadah domain class implemenation

domain-critical-section

https://www.npmjs.com/package/@yadah/domain-critical-section

CriticalSectionMixin

A mixin for Yadah domain classes providing a way to shutdown processes cleanly.

domain-listener

https://www.npmjs.com/package/@yadah/domain-listener

ListenerMixin

A mixin for Yadah domain classes to manage registering event listeners.

domain-model

https://www.npmjs.com/package/@yadah/domain-model

class Model

An Objection.js Model with plugins that provide functionality required by the ModelMixin service class mixin.

ModelMixin

A mixin for Yadah domain classes that provides access to an Objection.js Model.

class NotUniqueError

A Error class that may be thrown by ModelMixin when a query does not validate as having a unique result.

NotUniqueMixin

A mixin for Objection.js models which adds a .throwIfNotUnique() function to query builder instances.

subsystem-context

https://www.npmjs.com/package/@yadah/subsystem-context

createContext

A function to create a "context" subsystem.

ContextMixin

A mixin for Yadah domain classes which provides access to the service's context subsystem.

subsystem-knex

https://www.npmjs.com/package/@yadah/subsystem-knex

createKnex

A function to create a knex instance.

KnexMixin

A mixin for Yadah domain classes which provides access to the service's knex instance.

TRANSACTION

A symbol used to lookup the current knex transaction in a promise-chain context.

TransactionMixin

A mixin for Yadah domain classes which allows creating database transactions.

subsystem-logger

https://www.npmjs.com/package/@yadah/subsystem-logger

createLogger

A function to create a logger subsystem.

LoggerMixin

A mixin for Yadah domain classes which provides access to the service's logger subsystem.

subsystem-message-queue

https://www.npmjs.com/package/@yadah/subsystem-message-queue

createMessageQueue

A function to create a message queue (mq) subsystem.

MessageQueueMixin

A mixin for Yadah domain classes which provides access to the message queue subsystem, and helper methods for adding jobs to the queue.

subsystem-pubsub

https://www.npmjs.com/package/@yadah/subsystem-pubsub

createPubSub

A function to create a PubSub subsystem.

PubSubMixin

A mixin for Yadah domain classes which provides access to the pubsub subsystem, and helper methods for publishing messages.

subsystem-schedule

https://www.npmjs.com/package/@yadah/subsystem-schedule

createSchedule

A function to create a schedule subsystem.

ScheduleMixin

A mixin for Yadah domain classes which allows registering scheduled jobs.

subsystem-storage

https://www.npmjs.com/package/@yadah/subsystem-storage

createStorage

A function to create a Storage subsystem.

StorageMixin

A mixin for Yadah domain classes which provides access to the storage subsystem.