coh-content-db 2.0.0-rc.4 → 2.0.0-rc.5

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.
Files changed (37) hide show
  1. package/README.md +28 -4
  2. package/dist/coh-content-db.d.ts +189 -68
  3. package/dist/coh-content-db.js +323 -229
  4. package/dist/coh-content-db.js.map +1 -1
  5. package/dist/coh-content-db.mjs +317 -228
  6. package/dist/coh-content-db.mjs.map +1 -1
  7. package/package.json +1 -4
  8. package/src/main/api/alternate-data.ts +2 -2
  9. package/src/main/api/badge-data.ts +5 -10
  10. package/src/main/api/badge-partial-data.ts +6 -5
  11. package/src/main/api/change.ts +5 -2
  12. package/src/main/api/content-bundle.ts +2 -3
  13. package/src/main/api/markdown-string.ts +4 -0
  14. package/src/main/api/vidiot-map-point-of-interest-data.ts +3 -3
  15. package/src/main/changelog.ts +3 -2
  16. package/src/main/db/alignments.ts +17 -0
  17. package/src/main/db/alternates.ts +8 -14
  18. package/src/main/db/badge-index.ts +87 -0
  19. package/src/main/db/badge-partial.ts +54 -6
  20. package/src/main/db/badge-search-options.ts +51 -0
  21. package/src/main/db/badge.ts +8 -13
  22. package/src/main/db/bundle-metadata.ts +2 -3
  23. package/src/main/db/coh-content-database.ts +17 -25
  24. package/src/main/db/paged.ts +7 -0
  25. package/src/main/db/vidiot-map-point-of-interest.ts +2 -3
  26. package/src/main/index.ts +7 -1
  27. package/src/main/util.ts +36 -6
  28. package/src/test/api/alignments.test.ts +40 -0
  29. package/src/test/api/badge-partial-data.fixture.ts +1 -1
  30. package/src/test/db/alternates.test.ts +16 -74
  31. package/src/test/db/badge-index.test.ts +488 -0
  32. package/src/test/db/coh-content-database.test.ts +15 -0
  33. package/src/test/index.test.ts +4 -2
  34. package/src/test/util.test.ts +49 -13
  35. package/src/main/db/badge-search-document.ts +0 -16
  36. package/src/test/db/badge-search-document.test.ts +0 -35
  37. package/src/test/db/coh-content-database-search.test.ts +0 -119
@@ -1,5 +1,3 @@
1
- import MiniSearch from 'minisearch';
2
-
3
1
  const ALIGNMENT = ["H", "V", "P"];
4
2
 
5
3
  const BADGE_PARTIAL_TYPE = [
@@ -64,115 +62,60 @@ const PLAQUE_TYPE = [
64
62
 
65
63
  const SEX = ["M", "F"];
66
64
 
67
- var __typeError$3 = (msg) => {
68
- throw TypeError(msg);
69
- };
70
- var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
71
- var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
72
- var __privateAdd$3 = (obj, member, value) => member.has(obj) ? __typeError$3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
73
- var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
74
- var __privateMethod$1 = (obj, member, method) => (__accessCheck$3(obj, member, "access private method"), method);
75
- var _value, _Key_instances, validateKey_fn;
76
- const INVALID_KEY_PATTERN = /[^a-z0-9-]/;
77
- class Key {
78
- constructor(value) {
79
- __privateAdd$3(this, _Key_instances);
80
- __privateAdd$3(this, _value);
81
- __privateMethod$1(this, _Key_instances, validateKey_fn).call(this, value);
82
- __privateSet$2(this, _value, value);
83
- }
84
- get value() {
85
- return __privateGet$3(this, _value);
86
- }
87
- }
88
- _value = new WeakMap();
89
- _Key_instances = new WeakSet();
90
- validateKey_fn = function(key) {
91
- if (INVALID_KEY_PATTERN.test(key)) throw new Error(`Invalid key: [${key}]; Keys can only contain lowercase characters, numbers and dashes.`);
92
- };
93
-
94
65
  var __defProp$8 = Object.defineProperty;
95
66
  var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
96
67
  var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
97
- class Archetype {
98
- constructor(data) {
99
- __publicField$8(this, "key");
100
- __publicField$8(this, "name");
101
- __publicField$8(this, "description");
102
- this.key = new Key(data.key).value;
103
- this.name = data.name;
104
- this.description = data.description;
105
- }
106
- }
107
-
108
- var __defProp$7 = Object.defineProperty;
109
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
110
- var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
111
- class BadgePartial {
112
- constructor(data) {
113
- __publicField$7(this, "key");
114
- __publicField$7(this, "type");
115
- __publicField$7(this, "mapKey");
116
- __publicField$7(this, "loc");
117
- __publicField$7(this, "plaqueType");
118
- __publicField$7(this, "inscription");
119
- __publicField$7(this, "vidiotMapKey");
120
- __publicField$7(this, "badgeKey");
121
- __publicField$7(this, "inventionLevel");
122
- __publicField$7(this, "inventionTypes");
123
- __publicField$7(this, "inventionCount");
124
- __publicField$7(this, "notes");
125
- this.key = new Key(data.key).value;
126
- this.type = data.type;
127
- this.mapKey = data.mapKey;
128
- this.loc = data.loc;
129
- this.plaqueType = data.plaqueType;
130
- this.inscription = data.inscription;
131
- this.vidiotMapKey = data.vidiotMapKey;
132
- this.badgeKey = data.badgeKey;
133
- this.inventionLevel = data.inventionLevel;
134
- this.inventionTypes = data.inventionTypes;
135
- this.inventionCount = data.inventionCount;
136
- this.notes = data.notes;
68
+ class Alignments {
69
+ constructor(raw) {
70
+ __publicField$8(this, "items");
71
+ __publicField$8(this, "hero");
72
+ __publicField$8(this, "villain");
73
+ __publicField$8(this, "praetorian");
74
+ __publicField$8(this, "primal");
75
+ this.items = raw;
76
+ this.hero = raw.includes("H");
77
+ this.villain = raw.includes("V");
78
+ this.praetorian = raw.includes("P");
79
+ this.primal = !this.praetorian && (this.hero || this.villain);
137
80
  }
138
81
  }
139
82
 
140
- var __typeError$2 = (msg) => {
83
+ var __typeError$4 = (msg) => {
141
84
  throw TypeError(msg);
142
85
  };
143
- var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
144
- var __privateGet$2 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
145
- var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
146
- var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), member.set(obj, value), value);
147
- var __privateMethod = (obj, member, method) => (__accessCheck$2(obj, member, "access private method"), method);
86
+ var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
87
+ var __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
88
+ var __privateAdd$4 = (obj, member, value) => member.has(obj) ? __typeError$4("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
89
+ var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
90
+ var __privateMethod$2 = (obj, member, method) => (__accessCheck$4(obj, member, "access private method"), method);
148
91
  var _sortedValues, _Alternates_instances, compareAlternates_fn, compareAlignment_fn, compareSex_fn;
149
92
  const ALIGNMENT_SORT = { H: 2, V: 1, P: 0 };
150
93
  const SEX_SORT = { M: 1, F: 0 };
151
94
  class Alternates {
152
95
  constructor(values) {
153
- __privateAdd$2(this, _Alternates_instances);
154
- __privateAdd$2(this, _sortedValues, []);
155
- __privateSet$1(this, _sortedValues, values.sort());
156
- __privateGet$2(this, _sortedValues).sort((a, b) => __privateMethod(this, _Alternates_instances, compareAlternates_fn).call(this, a, b));
96
+ __privateAdd$4(this, _Alternates_instances);
97
+ __privateAdd$4(this, _sortedValues, []);
98
+ __privateSet$3(this, _sortedValues, values.sort());
99
+ __privateGet$4(this, _sortedValues).sort((a, b) => __privateMethod$2(this, _Alternates_instances, compareAlternates_fn).call(this, a, b));
157
100
  }
158
101
  getValue(alignment, sex) {
159
- for (let index = __privateGet$2(this, _sortedValues).length; index--; ) {
160
- const entry = __privateGet$2(this, _sortedValues)[index];
102
+ for (let index = __privateGet$4(this, _sortedValues).length; index--; ) {
103
+ const entry = __privateGet$4(this, _sortedValues)[index];
161
104
  if ((entry.alignment === void 0 || entry.alignment === alignment) && (entry.sex === void 0 || entry.sex === sex)) return entry.value;
162
105
  }
163
- return this.default;
106
+ return this.default?.value;
164
107
  }
165
108
  /**
166
109
  * Get the default value for this list of alternates, the value with the highest priority and lowest specificity.
167
110
  */
168
111
  get default() {
169
- return __privateGet$2(this, _sortedValues)[0]?.value;
112
+ return __privateGet$4(this, _sortedValues)[0];
170
113
  }
171
114
  /**
172
115
  * Get the list of alternates sorted in canonical order (alignment then sex, low to high specificity).
173
116
  */
174
117
  get canonical() {
175
- return __privateGet$2(this, _sortedValues);
118
+ return __privateGet$4(this, _sortedValues);
176
119
  }
177
120
  /**
178
121
  * Create a joined string from the alternate values in canonical order.
@@ -188,9 +131,9 @@ compareAlternates_fn = function(a, b) {
188
131
  const aSpecificity = (a.alignment ? 2 : 0) + (a.sex ? 1 : 0);
189
132
  const bSpecificity = (b.alignment ? 2 : 0) + (b.sex ? 1 : 0);
190
133
  if (aSpecificity !== bSpecificity) return aSpecificity - bSpecificity;
191
- const alignmentComparison = __privateMethod(this, _Alternates_instances, compareAlignment_fn).call(this, a.alignment, b.alignment);
134
+ const alignmentComparison = __privateMethod$2(this, _Alternates_instances, compareAlignment_fn).call(this, a.alignment, b.alignment);
192
135
  if (alignmentComparison !== 0) return alignmentComparison;
193
- const sexComparison = __privateMethod(this, _Alternates_instances, compareSex_fn).call(this, a.sex, b.sex);
136
+ const sexComparison = __privateMethod$2(this, _Alternates_instances, compareSex_fn).call(this, a.sex, b.sex);
194
137
  if (sexComparison !== 0) return sexComparison;
195
138
  return String(a.value).localeCompare(String(b.value));
196
139
  };
@@ -200,8 +143,7 @@ compareAlignment_fn = function(a, b) {
200
143
  if (b === void 0 && a !== void 0) return 1;
201
144
  const aSort = a === void 0 ? -1 : ALIGNMENT_SORT[a] ?? -1;
202
145
  const bSort = b === void 0 ? -1 : ALIGNMENT_SORT[b] ?? -1;
203
- if (aSort !== bSort) return bSort - aSort;
204
- return a?.localeCompare(b ?? "") ?? 0;
146
+ return bSort - aSort;
205
147
  };
206
148
  compareSex_fn = function(a, b) {
207
149
  if (a === b) return 0;
@@ -209,101 +151,203 @@ compareSex_fn = function(a, b) {
209
151
  if (b === void 0 && a !== void 0) return 1;
210
152
  const aSort = SEX_SORT[a ?? -1] ?? -1;
211
153
  const bSort = SEX_SORT[b ?? -1] ?? -1;
212
- if (aSort !== bSort) return bSort - aSort;
213
- return a?.localeCompare(b ?? "") ?? 0;
154
+ return bSort - aSort;
214
155
  };
215
156
 
216
- var __defProp$6 = Object.defineProperty;
217
- var __typeError$1 = (msg) => {
157
+ var __typeError$3 = (msg) => {
218
158
  throw TypeError(msg);
219
159
  };
160
+ var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
161
+ var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
162
+ var __privateAdd$3 = (obj, member, value) => member.has(obj) ? __typeError$3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
163
+ var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
164
+ var __privateMethod$1 = (obj, member, method) => (__accessCheck$3(obj, member, "access private method"), method);
165
+ var _value, _Key_instances, validateKey_fn;
166
+ const INVALID_KEY_PATTERN = /[^a-z0-9-]/;
167
+ class Key {
168
+ constructor(value) {
169
+ __privateAdd$3(this, _Key_instances);
170
+ __privateAdd$3(this, _value);
171
+ __privateMethod$1(this, _Key_instances, validateKey_fn).call(this, value);
172
+ __privateSet$2(this, _value, value);
173
+ }
174
+ get value() {
175
+ return __privateGet$3(this, _value);
176
+ }
177
+ }
178
+ _value = new WeakMap();
179
+ _Key_instances = new WeakSet();
180
+ validateKey_fn = function(key) {
181
+ if (INVALID_KEY_PATTERN.test(key)) throw new Error(`Invalid key: [${key}]; Keys can only contain lowercase characters, numbers and dashes.`);
182
+ };
183
+
184
+ var __defProp$7 = Object.defineProperty;
185
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
186
+ var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
187
+ class Archetype {
188
+ constructor(data) {
189
+ __publicField$7(this, "key");
190
+ __publicField$7(this, "name");
191
+ __publicField$7(this, "description");
192
+ this.key = new Key(data.key).value;
193
+ this.name = data.name;
194
+ this.description = data.description;
195
+ }
196
+ }
197
+
198
+ var __defProp$6 = Object.defineProperty;
220
199
  var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
221
200
  var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
222
- var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
223
- var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
224
- var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
201
+ class BadgePartial {
202
+ constructor(data) {
203
+ /**
204
+ * Key.
205
+ */
206
+ __publicField$6(this, "key");
207
+ /**
208
+ * Type of partial.
209
+ */
210
+ __publicField$6(this, "type");
211
+ /**
212
+ * Map the partial is located on.
213
+ */
214
+ __publicField$6(this, "mapKey");
215
+ /**
216
+ * /loc coordinates.
217
+ */
218
+ __publicField$6(this, "loc");
219
+ /**
220
+ * Is it a wall plaque or a physical monument?
221
+ */
222
+ __publicField$6(this, "plaqueType");
223
+ /**
224
+ * Plaque inscription.
225
+ */
226
+ __publicField$6(this, "plaqueInscription");
227
+ /**
228
+ * The number or letter the partial appears as on Vidiot Maps.
229
+ */
230
+ __publicField$6(this, "vidiotMapKey");
231
+ /**
232
+ * The badge required for this partial.
233
+ */
234
+ __publicField$6(this, "badgeKey");
235
+ /**
236
+ * Level of the invention required.
237
+ */
238
+ __publicField$6(this, "inventionLevel");
239
+ /**
240
+ * The types of enhancements required to be crafted.
241
+ */
242
+ __publicField$6(this, "inventionTypes");
243
+ /**
244
+ * Number of invention crafts required.
245
+ */
246
+ __publicField$6(this, "inventionCount");
247
+ /**
248
+ * Any additional notes.
249
+ */
250
+ __publicField$6(this, "notes");
251
+ this.key = new Key(data.key).value;
252
+ this.type = data.type;
253
+ this.mapKey = data.mapKey;
254
+ this.loc = data.loc;
255
+ this.plaqueType = data.plaqueType;
256
+ this.plaqueInscription = data.plaqueInscription;
257
+ this.vidiotMapKey = data.vidiotMapKey;
258
+ this.badgeKey = data.badgeKey;
259
+ this.inventionLevel = data.inventionLevel;
260
+ this.inventionTypes = data.inventionTypes;
261
+ this.inventionCount = data.inventionCount;
262
+ this.notes = data.notes;
263
+ }
264
+ }
265
+
266
+ var __defProp$5 = Object.defineProperty;
267
+ var __typeError$2 = (msg) => {
268
+ throw TypeError(msg);
269
+ };
270
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
271
+ var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
272
+ var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
273
+ var __privateGet$2 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
274
+ var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
225
275
  var _partialsIndex;
226
276
  class Badge {
227
277
  constructor(data) {
228
- __privateAdd$1(this, _partialsIndex, {});
278
+ __privateAdd$2(this, _partialsIndex, {});
229
279
  /**
230
280
  * The database key for this badge.
231
281
  */
232
- __publicField$6(this, "key");
282
+ __publicField$5(this, "key");
233
283
  /**
234
284
  * The type of badge.
235
285
  */
236
- __publicField$6(this, "type");
286
+ __publicField$5(this, "type");
237
287
  /**
238
288
  * The name of this badge.
239
289
  *
240
290
  * May vary by character sex or alignment.
241
291
  */
242
- __publicField$6(this, "name");
292
+ __publicField$5(this, "name");
243
293
  /**
244
294
  * The character alignments that this badge is available to.
245
295
  */
246
- __publicField$6(this, "alignment");
296
+ __publicField$5(this, "alignment");
247
297
  /**
248
298
  * The badge text as it appears in-game. May vary by character sex or alignment.
249
299
  */
250
- __publicField$6(this, "badgeText");
300
+ __publicField$5(this, "badgeText");
251
301
  /**
252
302
  * Description of how to acquire the badge.
253
- *
254
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
255
303
  */
256
- __publicField$6(this, "acquisition");
304
+ __publicField$5(this, "acquisition");
257
305
  /**
258
306
  * Absolute URL to this badge's icon.
259
307
  *
260
308
  * May vary by character sex or alignment.
261
309
  */
262
- __publicField$6(this, "icon");
310
+ __publicField$5(this, "icon");
263
311
  /**
264
312
  * Freeform notes or tips about the badge.
265
- *
266
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
267
313
  */
268
- __publicField$6(this, "notes");
314
+ __publicField$5(this, "notes");
269
315
  /**
270
316
  * List of external links for this Badge. Wiki, forums, etc.
271
317
  */
272
- __publicField$6(this, "links");
318
+ __publicField$5(this, "links");
273
319
  /**
274
320
  * For exploration badges, the key of the {@link GameMap} that this badge is found on.
275
321
  */
276
- __publicField$6(this, "mapKey");
322
+ __publicField$5(this, "mapKey");
277
323
  /**
278
324
  * For exploration badges, the `/loc` coordinates of the badge on the in-game map.
279
325
  */
280
- __publicField$6(this, "loc");
326
+ __publicField$5(this, "loc");
281
327
  /**
282
328
  * For badges that appear on a Vidiot Map, the number or letter the badge appears as.
283
329
  */
284
- __publicField$6(this, "vidiotMapKey");
330
+ __publicField$5(this, "vidiotMapKey");
285
331
  /**
286
332
  * ID used with the in-game `/settitle` command to apply the badge.
287
333
  */
288
- __publicField$6(this, "setTitle");
334
+ __publicField$5(this, "setTitle");
289
335
  /**
290
336
  * A description of the effect the badge will have, such as a buff or granting a temporary power.
291
- *
292
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
293
337
  */
294
- __publicField$6(this, "effect");
338
+ __publicField$5(this, "effect");
295
339
  /**
296
340
  * A list of requirements for badges that have partial fulfilment steps, such as visiting plaques for history badges, or collecting other badges for meta-badges like accolades.
297
341
  */
298
- __publicField$6(this, "partials");
342
+ __publicField$5(this, "partials");
299
343
  /**
300
344
  * Some badges are not included in the badge total count... such as Flames of Prometheus, which can be removed by redeeming it for a Notice of the Well.
301
345
  */
302
- __publicField$6(this, "ignoreInTotals");
346
+ __publicField$5(this, "ignoreInTotals");
303
347
  this.key = new Key(data.key).value;
304
348
  this.type = data.type;
305
349
  this.name = new Alternates(data.name);
306
- this.alignment = data.alignment;
350
+ this.alignment = new Alignments(data.alignment);
307
351
  this.badgeText = new Alternates(data.badgeText ?? []);
308
352
  this.acquisition = data.acquisition;
309
353
  this.icon = new Alternates(data.icon ?? []);
@@ -316,23 +360,124 @@ class Badge {
316
360
  this.setTitle = data.setTitle;
317
361
  this.ignoreInTotals = data.ignoreInTotals ?? false;
318
362
  this.partials = data.partials?.map((data2) => {
319
- if (__privateGet$1(this, _partialsIndex)[data2.key] !== void 0) throw new Error(`Duplicate badge partial key [${data2.key}]`);
363
+ if (__privateGet$2(this, _partialsIndex)[data2.key] !== void 0) throw new Error(`Duplicate badge partial key [${data2.key}]`);
320
364
  const badge = new BadgePartial(data2);
321
- __privateGet$1(this, _partialsIndex)[badge.key] = badge;
365
+ __privateGet$2(this, _partialsIndex)[badge.key] = badge;
322
366
  return badge;
323
367
  });
324
368
  }
325
369
  getPartial(key) {
326
- const result = __privateGet$1(this, _partialsIndex)[key];
370
+ const result = __privateGet$2(this, _partialsIndex)[key];
327
371
  if (result === void 0) throw new Error(`Unknown badge partial key [${key}]`);
328
372
  return result;
329
373
  }
330
374
  }
331
375
  _partialsIndex = new WeakMap();
332
376
 
333
- var __defProp$5 = Object.defineProperty;
334
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
335
- var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
377
+ var __typeError$1 = (msg) => {
378
+ throw TypeError(msg);
379
+ };
380
+ var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
381
+ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
382
+ var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
383
+ var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
384
+ var __privateMethod = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
385
+ var _badges, _badgeIndex$1, _mapOrder, _BadgeIndex_instances, satisfiesQueryPredicate_fn, satisfiesFilterPredicate_fn, sort_fn;
386
+ class BadgeIndex {
387
+ constructor(badges, maps) {
388
+ __privateAdd$1(this, _BadgeIndex_instances);
389
+ __privateAdd$1(this, _badges, []);
390
+ __privateAdd$1(this, _badgeIndex$1, {});
391
+ __privateAdd$1(this, _mapOrder, {});
392
+ __privateSet$1(this, _mapOrder, Object.fromEntries(
393
+ maps?.sort((a, b) => a.name.localeCompare(b.name))?.map((x, index) => [x.key, index]) ?? []
394
+ ));
395
+ __privateSet$1(this, _badges, badges);
396
+ for (const badge of badges) {
397
+ if (__privateGet$1(this, _badgeIndex$1)[badge.key] !== void 0) throw new Error(`Duplicate badge key [${badge.key}]`);
398
+ __privateGet$1(this, _badgeIndex$1)[badge.key] = badge;
399
+ }
400
+ }
401
+ getBadge(key) {
402
+ const result = __privateGet$1(this, _badgeIndex$1)[key];
403
+ if (result === void 0) throw new Error(`Unknown badge key [${key}]`);
404
+ return result;
405
+ }
406
+ searchBadges(options) {
407
+ const filtered = options?.query || options?.filter ? __privateGet$1(this, _badges).filter((badge) => __privateMethod(this, _BadgeIndex_instances, satisfiesQueryPredicate_fn).call(this, badge, options?.query) && __privateMethod(this, _BadgeIndex_instances, satisfiesFilterPredicate_fn).call(this, badge, options?.filter)) : __privateGet$1(this, _badges);
408
+ const paged = options?.pageSize ? filtered.slice(((options?.page ?? 1) - 1) * options.pageSize, (options?.page ?? 1) * options?.pageSize) : filtered;
409
+ const sorted = __privateMethod(this, _BadgeIndex_instances, sort_fn).call(this, paged, options?.sort);
410
+ return {
411
+ items: sorted,
412
+ page: options?.page ?? 1,
413
+ pageSize: options?.pageSize,
414
+ totalItems: filtered.length,
415
+ totalPages: options?.pageSize ? Math.ceil(filtered.length / options?.pageSize) : 1
416
+ };
417
+ }
418
+ }
419
+ _badges = new WeakMap();
420
+ _badgeIndex$1 = new WeakMap();
421
+ _mapOrder = new WeakMap();
422
+ _BadgeIndex_instances = new WeakSet();
423
+ satisfiesQueryPredicate_fn = function(badge, query) {
424
+ const queryString = query?.str?.toLowerCase() ?? "";
425
+ return !!((query?.on?.name ?? true) && badge.name.canonical.some((x) => x.value.toLowerCase().includes(queryString)) || query?.on?.badgeText && badge.badgeText.canonical.some((x) => x.value.toLowerCase().includes(queryString)) || query?.on?.acquisition && badge.acquisition?.toLowerCase().includes(queryString) || query?.on?.effect && badge.effect?.toLowerCase().includes(queryString) || query?.on?.notes && badge.notes?.toLowerCase().includes(queryString) || query?.on?.setTitle && (badge.setTitle?.id?.toString().includes(queryString) || badge.setTitle?.praetorianId?.toString().includes(queryString)));
426
+ };
427
+ satisfiesFilterPredicate_fn = function(badge, filter) {
428
+ return (!filter?.type || badge.type === filter.type) && (!filter?.mapKey || badge.mapKey === filter.mapKey) && (!filter?.alignment || badge.alignment.items.includes(filter.alignment));
429
+ };
430
+ sort_fn = function(badges, sort) {
431
+ if (!sort) return badges;
432
+ const ascending = sort.dir !== "DESC";
433
+ if (!sort.by || sort.by === "CANONICAL") return sort.dir === "DESC" ? badges.reverse() : badges;
434
+ if (sort.by === "BADGE_NAME") return ascending ? badges.sort((a, b) => a.name.default?.value.localeCompare(b.name.default?.value ?? "") ?? 0) : badges.sort((a, b) => b.name.default?.value.localeCompare(a.name.default?.value ?? "") ?? 0);
435
+ return badges.sort((a, b) => {
436
+ const aIndex = __privateGet$1(this, _mapOrder)[a.mapKey ?? ""];
437
+ const bIndex = __privateGet$1(this, _mapOrder)[b.mapKey ?? ""];
438
+ if (aIndex === bIndex) return 0;
439
+ if (aIndex === void 0) return ascending ? 1 : -1;
440
+ if (bIndex === void 0) return ascending ? -1 : 1;
441
+ return ascending ? aIndex - bIndex : bIndex - aIndex;
442
+ });
443
+ };
444
+
445
+ var __defProp$4 = Object.defineProperty;
446
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
447
+ var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
448
+ class BundleMetadata {
449
+ constructor(bundle) {
450
+ /**
451
+ * Name of the server group.
452
+ */
453
+ __publicField$4(this, "name");
454
+ /**
455
+ * Description of the server group.
456
+ */
457
+ __publicField$4(this, "description");
458
+ /**
459
+ * Repository where the db content package is maintained.
460
+ */
461
+ __publicField$4(this, "repository");
462
+ /**
463
+ * List of external links for this Server Group. Wiki, forums, etc.
464
+ */
465
+ __publicField$4(this, "links");
466
+ /**
467
+ * Change log for this data package.
468
+ */
469
+ __publicField$4(this, "changelog");
470
+ this.name = bundle.name;
471
+ this.description = bundle.description;
472
+ this.repository = bundle.repository;
473
+ this.links = bundle.links ?? [];
474
+ this.changelog = bundle.changelog ?? [];
475
+ }
476
+ }
477
+
478
+ var __defProp$3 = Object.defineProperty;
479
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
480
+ var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
336
481
  class VidiotMapPointOfInterest {
337
482
  constructor(data) {
338
483
  /**
@@ -340,25 +485,23 @@ class VidiotMapPointOfInterest {
340
485
  *
341
486
  * Screen-space, pixels from top-left `[0, 0]`.
342
487
  */
343
- __publicField$5(this, "pos");
488
+ __publicField$3(this, "pos");
344
489
  /**
345
490
  * Freeform notes about the PoI.
346
- *
347
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
348
491
  */
349
- __publicField$5(this, "notes");
492
+ __publicField$3(this, "notes");
350
493
  /**
351
494
  * If the POI is a zone transfer, the map it transfers to.
352
495
  */
353
- __publicField$5(this, "mapKey");
496
+ __publicField$3(this, "mapKey");
354
497
  /**
355
498
  * If the POI is a badge, the badge.
356
499
  */
357
- __publicField$5(this, "badgeKey");
500
+ __publicField$3(this, "badgeKey");
358
501
  /**
359
502
  * If the POI is a partial for a badge, the partial key.
360
503
  */
361
- __publicField$5(this, "badgePartialKey");
504
+ __publicField$3(this, "badgePartialKey");
362
505
  this.pos = data.pos;
363
506
  this.notes = data.notes;
364
507
  this.mapKey = data.mapKey;
@@ -367,50 +510,50 @@ class VidiotMapPointOfInterest {
367
510
  }
368
511
  }
369
512
 
370
- var __defProp$4 = Object.defineProperty;
371
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
372
- var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
513
+ var __defProp$2 = Object.defineProperty;
514
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
515
+ var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
373
516
  class VidiotMap {
374
517
  constructor(data) {
375
518
  /**
376
519
  * URL of the map image.
377
520
  */
378
- __publicField$4(this, "imageUrl");
521
+ __publicField$2(this, "imageUrl");
379
522
  /**
380
523
  * Name to display for the Vidiot map.
381
524
  */
382
- __publicField$4(this, "name");
525
+ __publicField$2(this, "name");
383
526
  /**
384
527
  * List of Points of Interest labelled on the image.
385
528
  */
386
- __publicField$4(this, "pointsOfInterest");
529
+ __publicField$2(this, "pointsOfInterest");
387
530
  this.imageUrl = data.imageUrl;
388
531
  this.name = data.name;
389
532
  this.pointsOfInterest = data.pointsOfInterest?.map((data2) => new VidiotMapPointOfInterest(data2));
390
533
  }
391
534
  }
392
535
 
393
- var __defProp$3 = Object.defineProperty;
394
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
395
- var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
536
+ var __defProp$1 = Object.defineProperty;
537
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
538
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
396
539
  class GameMap {
397
540
  constructor(data) {
398
541
  /**
399
542
  * The database key for this map.
400
543
  */
401
- __publicField$3(this, "key");
544
+ __publicField$1(this, "key");
402
545
  /**
403
546
  * The name of the map as it appears in-game.
404
547
  */
405
- __publicField$3(this, "name");
548
+ __publicField$1(this, "name");
406
549
  /**
407
550
  * List of external links for this Map. Wiki, forums, etc.
408
551
  */
409
- __publicField$3(this, "links");
552
+ __publicField$1(this, "links");
410
553
  /**
411
554
  * List of Vidiot Map assets for this map.
412
555
  */
413
- __publicField$3(this, "vidiotMaps");
556
+ __publicField$1(this, "vidiotMaps");
414
557
  this.key = new Key(data.key).value;
415
558
  this.name = data.name;
416
559
  this.links = data.links;
@@ -418,58 +561,6 @@ class GameMap {
418
561
  }
419
562
  }
420
563
 
421
- var __defProp$2 = Object.defineProperty;
422
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
423
- var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
424
- class BundleMetadata {
425
- constructor(bundle) {
426
- /**
427
- * Name of the server group.
428
- */
429
- __publicField$2(this, "name");
430
- /**
431
- * Description of the server group.
432
- *
433
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
434
- */
435
- __publicField$2(this, "description");
436
- /**
437
- * Repository where the db content package is maintained.
438
- */
439
- __publicField$2(this, "repository");
440
- /**
441
- * List of external links for this Server Group. Wiki, forums, etc.
442
- */
443
- __publicField$2(this, "links");
444
- /**
445
- * Change log for this data package.
446
- */
447
- __publicField$2(this, "changelog");
448
- this.name = bundle.name;
449
- this.description = bundle.description;
450
- this.repository = bundle.repository;
451
- this.links = bundle.links ?? [];
452
- this.changelog = bundle.changelog ?? [];
453
- }
454
- }
455
-
456
- var __defProp$1 = Object.defineProperty;
457
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
458
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
459
- class BadgeSearchDocument {
460
- constructor(badge) {
461
- __publicField$1(this, "id");
462
- __publicField$1(this, "key");
463
- __publicField$1(this, "name");
464
- __publicField$1(this, "badgeText");
465
- __publicField$1(this, "acquisition");
466
- this.id = this.key = badge.key;
467
- this.name = badge.name.toString(", ");
468
- this.badgeText = badge.badgeText.toString(", ");
469
- this.acquisition = badge.acquisition ?? "";
470
- }
471
- }
472
-
473
564
  var __defProp = Object.defineProperty;
474
565
  var __typeError = (msg) => {
475
566
  throw TypeError(msg);
@@ -480,7 +571,7 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
480
571
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
481
572
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
482
573
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
483
- var _archetypeIndex, _mapIndex, _badgeIndex, _badgeSearch;
574
+ var _archetypeIndex, _mapIndex, _badgeIndex;
484
575
  class CohContentDatabase {
485
576
  /**
486
577
  * Initialize the database with a content bundle.
@@ -489,8 +580,7 @@ class CohContentDatabase {
489
580
  constructor(bundle) {
490
581
  __privateAdd(this, _archetypeIndex, {});
491
582
  __privateAdd(this, _mapIndex, {});
492
- __privateAdd(this, _badgeIndex, {});
493
- __privateAdd(this, _badgeSearch);
583
+ __privateAdd(this, _badgeIndex);
494
584
  /**
495
585
  * Metadata about the content bundle.
496
586
  */
@@ -526,19 +616,8 @@ class CohContentDatabase {
526
616
  __privateGet(this, _mapIndex)[map.key] = map;
527
617
  return map;
528
618
  }) ?? [];
529
- this.badges = bundle.badges?.map((data) => {
530
- if (__privateGet(this, _badgeIndex)[data.key] !== void 0) throw new Error(`Duplicate badge key [${data.key}]`);
531
- const badge = new Badge(data);
532
- __privateGet(this, _badgeIndex)[badge.key] = badge;
533
- return badge;
534
- }) ?? [];
535
- __privateSet(this, _badgeSearch, new MiniSearch({
536
- fields: ["key", "name", "badgeText", "acquisition"],
537
- storeFields: ["key"]
538
- }));
539
- for (const badge of this.badges) {
540
- __privateGet(this, _badgeSearch).add(new BadgeSearchDocument(badge));
541
- }
619
+ this.badges = bundle.badges?.map((data) => new Badge(data)) ?? [];
620
+ __privateSet(this, _badgeIndex, new BadgeIndex(this.badges, this.maps));
542
621
  }
543
622
  getArchetype(key) {
544
623
  const result = __privateGet(this, _archetypeIndex)[key];
@@ -551,20 +630,21 @@ class CohContentDatabase {
551
630
  return result;
552
631
  }
553
632
  getBadge(key) {
554
- const result = __privateGet(this, _badgeIndex)[key];
555
- if (result === void 0) throw new Error(`Unknown badge key [${key}]`);
556
- return result;
633
+ return __privateGet(this, _badgeIndex).getBadge(key);
557
634
  }
558
- searchBadges(query) {
559
- if (!query) return this.badges;
560
- const keys = __privateGet(this, _badgeSearch).search(query, { prefix: true, fuzzy: true });
561
- return keys.map((result) => this.getBadge(result["key"]));
635
+ /**
636
+ * Search, sort and filter the badge list.
637
+ * This is a fairly brute-forced approach and will not be as performant as loading the badge data into a traditional
638
+ * database engine, but is sufficient for most operations.
639
+ * @param options {@link BadgeSearchOptions}
640
+ */
641
+ searchBadges(options) {
642
+ return __privateGet(this, _badgeIndex).searchBadges(options);
562
643
  }
563
644
  }
564
645
  _archetypeIndex = new WeakMap();
565
646
  _mapIndex = new WeakMap();
566
647
  _badgeIndex = new WeakMap();
567
- _badgeSearch = new WeakMap();
568
648
 
569
649
  const CHANGELOG = [
570
650
  {
@@ -572,14 +652,15 @@ const CHANGELOG = [
572
652
  date: /* @__PURE__ */ new Date("2025-03-12"),
573
653
  description: `* Replaced redundant interfaces with their concrete equivalents.
574
654
  * Server groups are now referred to as 'forks'.
575
- * Replaced enums with extensible union types; Forks with new badge types, enhancement types, etc. can now extend them locally.
655
+ * Replaced enums with union types.
576
656
  * \`IServerGroupData\` is now \`ContentBundle\` and each database instance is now designed to accept only a single server group.
577
657
  * Removed the \`serverGroup\` property from entities to simplify the object tree given that only a single context can exist per db now.
578
658
  * Added a simple indexing and search function for badge names, text and acquisition info.
659
+ * Map and badge references now follow a standard Markdown link format with a \`badge://\` or \`map://\` protocol.
579
660
  * Standardized pluralization of some field names (name, icon).
580
661
  * Combined \`settitle\` ids into a single tuple field.
581
662
  * Change from GNU to The Unlicense.
582
- * Removed dependency on lodash.
663
+ * Removed all third-party dependencies.
583
664
  * Moved from webpack to rollup for packaging.
584
665
  * Add eslint for linting.
585
666
  * Add jest for unit tests.
@@ -588,14 +669,22 @@ const CHANGELOG = [
588
669
  }
589
670
  ];
590
671
 
591
- function createBadgeReference(target) {
672
+ function badgeUri(target) {
673
+ const key = typeof target === "string" ? target : target.key;
674
+ return `badge://${key}`;
675
+ }
676
+ function badgeLink(target) {
677
+ const key = typeof target === "string" ? target : target.key;
678
+ return `[${key}](${badgeUri(target)})`;
679
+ }
680
+ function mapUri(target) {
592
681
  const key = typeof target === "string" ? target : target.key;
593
- return `[badge:${key}]`;
682
+ return `map://${key}`;
594
683
  }
595
- function createMapReference(target) {
684
+ function mapLink(target) {
596
685
  const key = typeof target === "string" ? target : target.key;
597
- return `[map:${key}]`;
686
+ return `[${key}](${mapUri(target)})`;
598
687
  }
599
688
 
600
- export { ALIGNMENT, Archetype, BADGE_PARTIAL_TYPE, BADGE_TYPE, Badge, BadgePartial, BundleMetadata, CHANGELOG, CohContentDatabase, ENHANCEMENT_CATEGORY, GameMap, Key, PLAQUE_TYPE, SEX, VidiotMap, VidiotMapPointOfInterest, createBadgeReference, createMapReference };
689
+ export { ALIGNMENT, Alignments, Alternates, Archetype, BADGE_PARTIAL_TYPE, BADGE_TYPE, Badge, BadgeIndex, BadgePartial, BundleMetadata, CHANGELOG, CohContentDatabase, ENHANCEMENT_CATEGORY, GameMap, Key, PLAQUE_TYPE, SEX, VidiotMap, VidiotMapPointOfInterest, badgeLink, badgeUri, mapLink, mapUri };
601
690
  //# sourceMappingURL=coh-content-db.mjs.map