@sharpee/queries 1.0.8 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @sharpee/queries
|
|
2
|
+
|
|
3
|
+
LINQ-style fluent entity query API for the Sharpee Interactive Fiction platform.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @sharpee/queries
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
A lightweight, immutable, chainable query layer over `IFEntity` collections (ADR-150):
|
|
14
|
+
|
|
15
|
+
- **`EntityQuery`** - LINQ-style filtering, ordering, aggregation, and materialization. Every filter returns a new query; the source is never mutated.
|
|
16
|
+
- **World-model entry points** - Importing the package augments `WorldModel` with `all`, `rooms`, `actors`, `objects`, `scenes`, `regions`, plus `contents()`, `allContents()`, `having()`, `visible()`, and `inScope()`.
|
|
17
|
+
- **Concrete class only** - The query entry points live on the concrete `WorldModel` class, not the `IWorldModel` interface. Access queries through a `WorldModel` instance.
|
|
18
|
+
- **Iterable** - `EntityQuery` implements `Iterable<IFEntity>`, so it works with `for...of` and spread.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import '@sharpee/queries'; // side-effect import: activates query entry points
|
|
24
|
+
import { EntityQuery } from '@sharpee/queries';
|
|
25
|
+
import { WorldModel, TraitType } from '@sharpee/world-model';
|
|
26
|
+
|
|
27
|
+
function findLitItems(world: WorldModel) {
|
|
28
|
+
// Entry points return EntityQuery; chain LINQ-style filters
|
|
29
|
+
const litObjects = world.objects
|
|
30
|
+
.having(TraitType.LIGHT_SOURCE)
|
|
31
|
+
.where(e => e.id !== 'player');
|
|
32
|
+
|
|
33
|
+
// Materialize when you need an array
|
|
34
|
+
return [...litObjects];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Filter contents of a room and look one up by name
|
|
38
|
+
function torchInKitchen(world: WorldModel) {
|
|
39
|
+
return world.contents('kitchen')
|
|
40
|
+
.matching('torch')
|
|
41
|
+
.named('brass torch');
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Common filters
|
|
46
|
+
|
|
47
|
+
| Method | Effect |
|
|
48
|
+
|--------|--------|
|
|
49
|
+
| `where(predicate)` | Keep entities matching a predicate |
|
|
50
|
+
| `withTrait(type)` / `withoutTrait(type)` | Filter by trait presence/absence |
|
|
51
|
+
| `ofType(type)` | Filter by entity type (`'room'`, `'object'`, …) |
|
|
52
|
+
| `named(name)` | Exact (case-sensitive) identity-name match |
|
|
53
|
+
| `matching(term)` | Case-insensitive name/alias substring match |
|
|
54
|
+
|
|
55
|
+
## Related Packages
|
|
56
|
+
|
|
57
|
+
- [@sharpee/world-model](https://www.npmjs.com/package/@sharpee/world-model) - Entity, trait, and behavior system
|
|
58
|
+
- [@sharpee/helpers](https://www.npmjs.com/package/@sharpee/helpers) - Fluent entity builders
|
|
59
|
+
- [@sharpee/sharpee](https://www.npmjs.com/package/@sharpee/sharpee) - Full platform bundle
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharpee/queries",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "LINQ-style fluent entity query API for Sharpee Interactive Fiction Platform",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@sharpee/world-model": "^1.
|
|
16
|
-
"@sharpee/if-domain": "^1.
|
|
15
|
+
"@sharpee/world-model": "^1.1.1",
|
|
16
|
+
"@sharpee/if-domain": "^1.1.1"
|
|
17
17
|
},
|
|
18
18
|
"keywords": [
|
|
19
19
|
"interactive-fiction",
|