@dnd-mapp/shared-domain
v2.1.0
Published
Shared domain models, builders, enums, and test mock databases for D&D Mapp
Downloads
583
Maintainers
Readme
@dnd-mapp/shared-domain
Shared domain models, builders, and enums for the D&D Mapp project — usable across both server and client applications.
Installation
npm install @dnd-mapp/shared-domain
# or
pnpm add @dnd-mapp/shared-domainUsage
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, andSigningKey, together with typedCreate*/Update*payload types. - Fluent builders —
UserBuilder,RoleBuilder,PermissionBuilder, andClientBuilderwith auto-generated IDs and timestamps, designed for concise test fixtures and factory functions. - Enums —
ClientTypes,RoleNames, andPermissionNamescovering all recognized constant values. - Mock databases — Tree-shakeable
/testingsub-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) andindex.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.