@sharpee/queries
v3.0.0
Published
LINQ-style fluent entity query API for Sharpee Interactive Fiction Platform
Readme
@sharpee/queries
LINQ-style fluent entity query API for the Sharpee Interactive Fiction platform.
Installation
npm install @sharpee/queriesOverview
A lightweight, immutable, chainable query layer over IFEntity collections (ADR-150):
EntityQuery- LINQ-style filtering, ordering, aggregation, and materialization. Every filter returns a new query; the source is never mutated.- World-model entry points - Importing the package augments
WorldModelwithall,rooms,actors,objects,scenes,regions, pluscontents(),allContents(),having(),visible(), andinScope(). - Concrete class only - The query entry points live on the concrete
WorldModelclass, not theIWorldModelinterface. Access queries through aWorldModelinstance. - Iterable -
EntityQueryimplementsIterable<IFEntity>, so it works withfor...ofand spread.
Usage
import '@sharpee/queries'; // side-effect import: activates query entry points
import { EntityQuery } from '@sharpee/queries';
import { WorldModel, TraitType } from '@sharpee/world-model';
function findLitItems(world: WorldModel) {
// Entry points return EntityQuery; chain LINQ-style filters
const litObjects = world.objects
.having(TraitType.LIGHT_SOURCE)
.where(e => e.id !== 'player');
// Materialize when you need an array
return [...litObjects];
}
// Filter contents of a room and look one up by name
function torchInKitchen(world: WorldModel) {
return world.contents('kitchen')
.matching('torch')
.named('brass torch');
}Common filters
| Method | Effect |
|--------|--------|
| where(predicate) | Keep entities matching a predicate |
| withTrait(type) / withoutTrait(type) | Filter by trait presence/absence |
| ofType(type) | Filter by entity type ('room', 'object', …) |
| named(name) | Exact (case-sensitive) identity-name match |
| matching(term) | Case-insensitive name/alias substring match |
Related Packages
- @sharpee/world-model - Entity, trait, and behavior system
- @sharpee/helpers - Fluent entity builders
- @sharpee/sharpee - Full platform bundle
License
MIT
