@dnd-mapp/shared-domain

v2.1.0

Published

Shared domain models, builders, enums, and test mock databases for D&D Mapp

Downloads

583

Readme

@dnd-mapp/shared-domain

Shared domain models, builders, and enums for the D&D Mapp project — usable across both server and client applications.

npm version minzipped size license

Installation

npm install @dnd-mapp/shared-domain
# or
pnpm add @dnd-mapp/shared-domain

Usage

Models

TypeScript interfaces describing the core domain entities:

import type { User, Role, Permission, Client, SigningKey } from '@dnd-mapp/shared-domain';

Each entity also ships with typed Create*Data and Update*Data helper types for constructing payloads.

Builders

Fluent builder classes with sensible defaults (auto-generated IDs, current timestamps):

import { UserBuilder, RoleBuilder, PermissionBuilder, ClientBuilder } from '@dnd-mapp/shared-domain';

const user = new UserBuilder()
    .withUsername('TheLegend27')
    .withEmail('[email protected]')
    .build();

const role = new RoleBuilder().withName(RoleNames.PLAYER).build();

Enums

Type-safe constant sets for entity fields:

import { ClientTypes, RoleNames, PermissionNames } from '@dnd-mapp/shared-domain';

ClientTypes.PUBLIC;              // 'PUBLIC'
RoleNames.ADMIN;                 // 'ADMIN'
PermissionNames.USER_READ;       // 'user:read'

Testing utilities

In-memory mock databases for use in test suites, exported from a separate entry point so they are never bundled into production code:

import { MockUserDB, MockRoleDB, MockPermissionDB, MockClientDB, seedUser } from '@dnd-mapp/shared-domain/testing';

const db = new MockUserDB();
db.add(new UserBuilder().withUsername('tester').build());

Features

  • Domain models — TypeScript interfaces for User, Role, Permission, Client, and SigningKey, together with typed Create* / Update* payload types.
  • Fluent buildersUserBuilder, RoleBuilder, PermissionBuilder, and ClientBuilder with auto-generated IDs and timestamps, designed for concise test fixtures and factory functions.
  • EnumsClientTypes, RoleNames, and PermissionNames covering all recognized constant values.
  • Mock databases — Tree-shakeable /testing sub-entry with in-memory implementations (MockUserDB, MockRoleDB, MockPermissionDB, MockClientDB, MockSigningKeyDB, MockRolePermissionDB) and pre-seeded seed objects (seedUser, seedClient).
  • Dual CJS / ESM output — ships both index.js (ESM) and index.cjs (CommonJS) so it works in any Node.js or bundler environment.

Contributing & Development

See the repository README for local setup, available scripts, and contribution guidelines.

License

MIT