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 🙏

© 2026 – Pkg Stats / Ryan Hefner

bedest-core

v1.0.2

Published

Core abstractions for the BED stack (Bun + Elysia + Drizzle)

Readme

bedest-core

Core abstractions for the Bedest BED stack (Bun + Elysia + Drizzle).

Installation

bun add bedest-core

Peer Dependencies

bun add elysia drizzle-orm

Included Exports

| Export | Description | | ----------------------------------------------- | ----------------------------------------------------------------------------------- | | ServiceBase | Generic CRUD base class (create, getAll, getById, update, remove) | | ServiceBaseTenant | Tenant-scoped CRUD service. All operations run inside an RLS transaction. | | UtilTenantScope | tenantScope and systemScope transaction wrappers for configuring RLS context. | | UtilDbSchema | Schema helpers: tenantIsolationPolicy, activeIndex, activeUniqueIndex. | | UtilRouter | defPaginatedSchema — paginated response wrapper for Elysia schemas. | | UtilAudit | scrub() — removes sensitive fields from audit logs. | | MacroRoleGuard | Elysia macro for role-based access control. | | MacroPlanGuard | Elysia macro for tenant plan-based access control (checkPlan injection required). | | baseColumns | Common Drizzle columns: id, isDeleted, createdAt, deletedAt. | | VId, VEmail, VString, VQuery, VNumber | Reusable Elysia/TypeBox validation primitives. | | IApp, ITenantApp, IUserApp | Application context interfaces. | | ISession | Session contract: userId, sessionId, role, isSuperUser. | | IBaseTable | Base Drizzle table type constraint. | | TDb | NodePgDatabase type alias. |


Usage

1. ISession — isSuperUser

The role property is now typed as a plain string, removing any enum dependency.

The isSuperUser flag should be resolved in your application's Context.ts:

// src/app/Context.ts
import { ISession, IUserApp } from "bedest-core";
import { EUserRole } from "@f/user/enums/EUserRole";

const session: ISession = {
  userId: payload.userId,
  sessionId: payload.sessionId,
  role: payload.role,
  isSuperUser: payload.role === EUserRole.SYSTEM,
};

2. MacroRoleGuard

Register the macro in your application context:

import { MacroRoleGuard } from "bedest-core";

.macro("RoleGuard", MacroRoleGuard)

Use it in routes:

{
  RoleGuard: [EUserRole.ADMIN, EUserRole.SYSTEM]
}

Since EUserRole extends string, route definitions remain fully type-safe.

3. MacroPlanGuard

Bind a checkPlan function once in Context.ts:

import { MacroPlanGuard, PlanChecker } from "bedest-core";
import ServiceTenant from "@f/tenant/services/ServiceTenant";
import { ETenantPlan } from "@f/tenant/enums/ETenantPlan";

const planChecker: PlanChecker = (tenantId, nowDatetime) =>
  ServiceTenant.checkPlan({ db, nowDatetime }, tenantId);

.macro(
  "PlanGuard",
  (plans: ETenantPlan[]) => MacroPlanGuard(plans, planChecker)
);

Use it in routes:

{
  PlanGuard: [ETenantPlan.PROFESSIONAL]
}

4. ServiceBase / ServiceBaseTenant

import { ServiceBaseTenant } from "bedest-core";
import { SMyTable } from "../schemas/SMyTable";

class ServiceMyEntity extends ServiceBaseTenant<typeof SMyTable> {
  constructor() {
    super(SMyTable);
  }
}

export default new ServiceMyEntity();

5. UtilDbSchema

import { baseColumns, UtilDbSchema } from "bedest-core";

export const SMyTable = pgTable(
  "my_table",
  {
    ...baseColumns,
    tenantId: uuid().notNull(),
    name: varchar({ length: 255 }).notNull(),
  },
  (t) => [
    UtilDbSchema.activeIndex("idx_my_table_active", t.id),
    UtilDbSchema.tenantIsolationPolicy(t.tenantId),
  ]
).enableRLS();

Peer Dependencies

{
  "peerDependencies": {
    "drizzle-orm": ">=0.41",
    "elysia": ">=1.1"
  }
}