data-of-loathing 3.1.2 → 3.1.3
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 +104 -16
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,21 +1,68 @@
|
|
|
1
1
|
# data-of-loathing
|
|
2
2
|
|
|
3
|
-
A client
|
|
3
|
+
A typed client for querying Kingdom of Loathing game data. It wraps a SQLite database served by [data.loathers.net](https://data.loathers.net) and exposes it through a [MikroORM](https://mikro-orm.io) entity manager.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
The browser client uses [SQLocal](https://sqlocal.dev) (SQLite over WASM) under the hood. To use it in a browser app you will need to install the optional peer dependencies as dev dependencies:
|
|
5
|
+
## Installation
|
|
8
6
|
|
|
9
7
|
```sh
|
|
10
|
-
npm install -
|
|
8
|
+
npm install data-of-loathing
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
## Node
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createClient } from "data-of-loathing";
|
|
15
|
+
|
|
16
|
+
const client = createClient();
|
|
17
|
+
await client.load();
|
|
18
|
+
|
|
19
|
+
const item = await client.query.findOne("Item", { name: "seal tooth" });
|
|
20
|
+
console.log(item?.autosell); // 1
|
|
21
|
+
```
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
The default strategy downloads the database from data.loathers.net and caches it to `~/.cache/data-of-loathing/`. It re-downloads only when the server's ETag changes.
|
|
24
|
+
|
|
25
|
+
You can point it at a local file instead:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
const client = createClient({ strategy: "local", path: "./dol.sqlite" });
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Browser
|
|
32
|
+
|
|
33
|
+
Three strategies are available in the browser, each with different trade-offs.
|
|
34
|
+
|
|
35
|
+
`"memory"` downloads the full database on each page load and holds it in memory. Simple, but slow to start on a cold load. Once the browser has cached the database file, however, it will be as fast as any other solution.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { createClient } from "data-of-loathing";
|
|
39
|
+
|
|
40
|
+
const client = createClient({ strategy: "memory" });
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`"opfs"` downloads the database once and persists it to the [Origin Private File System](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system). Subsequent loads skip the download if the server's ETag matches.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const client = createClient({ strategy: "opfs" });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`"ranged"` never downloads the full database. It fetches only the SQLite pages it needs on demand using HTTP Range requests. This gives fast startup time at the cost of per-query network latency on a cold cache.
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
const client = createClient({ strategy: "ranged" });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
All three accept a `url` option if you are hosting the database yourself:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const client = createClient({ strategy: "memory", url: "https://example.com/dol.sqlite" });
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Vite setup
|
|
62
|
+
|
|
63
|
+
Add the plugin to your Vite config:
|
|
16
64
|
|
|
17
65
|
```ts
|
|
18
|
-
// vite.config.ts
|
|
19
66
|
import { defineConfig } from "vite";
|
|
20
67
|
import dol from "data-of-loathing/vite";
|
|
21
68
|
|
|
@@ -24,19 +71,60 @@ export default defineConfig({
|
|
|
24
71
|
});
|
|
25
72
|
```
|
|
26
73
|
|
|
27
|
-
The plugin
|
|
74
|
+
The plugin excludes the package and its SQLite WASM dependency from Vite's dependency optimiser, which is required for the worker URLs to resolve correctly. It also polyfills `Buffer`.
|
|
28
75
|
|
|
29
|
-
-
|
|
30
|
-
- Polyfills `Buffer` (required by the underlying SQLite driver)
|
|
76
|
+
If your deployment needs [cross-origin isolation headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy) for other reasons, pass `{ coi: true }` to enable them on the dev server:
|
|
31
77
|
|
|
32
|
-
|
|
78
|
+
```ts
|
|
79
|
+
plugins: [dol({ coi: true })]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Querying
|
|
33
83
|
|
|
34
|
-
|
|
84
|
+
After `await client.load()`, `client.query` is a MikroORM `EntityManager`. The full MikroORM querying API is available, but the most common patterns are:
|
|
35
85
|
|
|
36
86
|
```ts
|
|
37
|
-
|
|
38
|
-
|
|
87
|
+
const em = client.query;
|
|
88
|
+
|
|
89
|
+
// find one record
|
|
90
|
+
const item = await em.findOne("Item", { name: "seal tooth" });
|
|
91
|
+
|
|
92
|
+
// find multiple records
|
|
93
|
+
const familiars = await em.findAll("Familiar", {
|
|
94
|
+
where: { category: FamiliarCategory.Combat },
|
|
95
|
+
orderBy: { name: "asc" },
|
|
39
96
|
});
|
|
97
|
+
|
|
98
|
+
// find with a limit
|
|
99
|
+
const skills = await em.find("Skill", {}, { limit: 10 });
|
|
40
100
|
```
|
|
41
101
|
|
|
42
|
-
|
|
102
|
+
## Entities
|
|
103
|
+
|
|
104
|
+
The following entities are available to query:
|
|
105
|
+
|
|
106
|
+
- `Item` - in-game items
|
|
107
|
+
- `Effect` - status effects
|
|
108
|
+
- `Skill` - skills usable by players
|
|
109
|
+
- `Familiar` - familiars
|
|
110
|
+
- `Monster` - monsters
|
|
111
|
+
- `MonsterDrop` - individual item drops from monsters (relates `Monster` to `Item`)
|
|
112
|
+
- `NativeMonster` - monsters that appear natively in a location (relates `Location` to `Monster`)
|
|
113
|
+
- `Location` - in-game locations
|
|
114
|
+
- `Path` - challenge paths
|
|
115
|
+
- `AscensionClass` - player classes
|
|
116
|
+
- `Equipment` - equipment items, with slot and stat requirements
|
|
117
|
+
- `Consumable` - food and booze
|
|
118
|
+
- `Concoction` - craftable items
|
|
119
|
+
- `Ingredient` - ingredients for a concoction (relates `Concoction` to `Item`)
|
|
120
|
+
- `Outfit` - outfits
|
|
121
|
+
- `OutfitTreat` - the items that make up an outfit (relates `Outfit` to `Item`)
|
|
122
|
+
- `FoldGroup` - groups of items that can be folded into each other
|
|
123
|
+
- `ZapGroup` - groups of items that can be zapped into each other
|
|
124
|
+
- `ItemModifiers` - numeric modifiers for an item (one-to-one with `Item`)
|
|
125
|
+
- `EffectModifiers` - numeric modifiers for an effect (one-to-one with `Effect`)
|
|
126
|
+
- `SkillModifiers` - numeric modifiers for a skill (one-to-one with `Skill`)
|
|
127
|
+
- `FamiliarModifiers` - numeric modifiers for a familiar (one-to-one with `Familiar`)
|
|
128
|
+
- `Meta` - metadata about the database, including the last update timestamp
|
|
129
|
+
|
|
130
|
+
Enum types for filtering (`ItemUse`, `EffectQuality`, `SkillTag`, `FamiliarCategory`, `MonsterElement`, and others) are exported from the package alongside the entity types.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-of-loathing",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"packageManager": "yarn@4.6.0",
|
|
6
6
|
"repository": {
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@mikro-orm/core": "^7.0.14",
|
|
38
38
|
"@mikro-orm/sql": "^7.0.14",
|
|
39
39
|
"@sqlite.org/sqlite-wasm": "~3.51.2-build9",
|
|
40
|
+
"env-paths": "^4.0.0",
|
|
40
41
|
"kysely": "^0.28.17"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|