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
package/README.md CHANGED
@@ -53,16 +53,40 @@ export const TEST_SERVER_GROUP: ContentBundle = {
53
53
  }
54
54
  ```
55
55
 
56
+ ### Markdown and Links
57
+
58
+ Fields with long text values can typically accept [Markdown](https://www.markdownguide.org/) format. These fields will also be typed with the tag type [MarkdownString](src/main/api/markdown-string.ts).
59
+
60
+ Within markdown, you can construct a link to a badge or map using the special `badge://` and `map://` protocol indicators that consumer apps can use to provide runtime links or tooltips.
61
+ This replaces the custom `[badge:xyz]` format from v1 and data packages will need to update accordingly.
62
+
63
+ To create a link, use the standard Markdown link format, with the url as following:
64
+
65
+ ```markdown
66
+ This is a link to the [Ghoulish](badge://ghoulish) badge.
67
+ ```
68
+
69
+ There are convenience functions also provided to construct the URI automatically that can be used as follows:
70
+
71
+ ```typescript
72
+ import { badgeLink, badgeUri } from 'coh-content-db'
73
+
74
+ const uri = `This is a link to the [Ghoulish](${badgeUri('ghoulish')}) badge.`
75
+ // This is a link to the [Ghoulish](badge://ghoulish) badge.
76
+ const link = `This is a link to the ${badgeLink('ghoulish')} badge.`
77
+ // This is a link to the [ghoulish](badge://ghoulish) badge.
78
+ ```
79
+
56
80
  ## As a DB consumer
57
81
 
58
82
  Create a new database instance, then load a content bundle, such as [coh-content-db-homecoming](https://github.com/n15g/coh-content-db-homecoming):
59
83
 
60
84
  ```typescript
61
- import { CohContentDatabase } from 'coh-content-db';
62
- import { Homecoming } from 'coh-content-db-homecoming';
85
+ import { CohContentDatabase } from 'coh-content-db'
86
+ import { Homecoming } from 'coh-content-db-homecoming'
63
87
 
64
- const db = new CohContentDatabase();
65
- db.loadBundle(new Homecoming());
88
+ const db = new CohContentDatabase()
89
+ db.loadBundle(new Homecoming())
66
90
  ```
67
91
 
68
92
  #### Access the content
@@ -11,11 +11,11 @@ interface AlternateData<V> {
11
11
  /**
12
12
  * The character alignment this alternate applies to.
13
13
  */
14
- readonly alignment?: Alignment | string;
14
+ readonly alignment?: Alignment;
15
15
  /**
16
16
  * The character sex this alternate applies to.
17
17
  */
18
- readonly sex?: Sex | string;
18
+ readonly sex?: Sex;
19
19
  /**
20
20
  * The value for this combination.
21
21
  */
@@ -37,6 +37,11 @@ type BadgePartialType = typeof BADGE_PARTIAL_TYPE[number];
37
37
  declare const PLAQUE_TYPE: string[];
38
38
  type PlaqueType = typeof PLAQUE_TYPE[number];
39
39
 
40
+ /**
41
+ * Tage type to indicate that a string will accept {@link https://www.markdownguide.org/|Markdown} format.
42
+ */
43
+ type MarkdownString = string;
44
+
40
45
  interface BadgePartialData {
41
46
  /**
42
47
  * Key.
@@ -45,7 +50,7 @@ interface BadgePartialData {
45
50
  /**
46
51
  * Type of partial.
47
52
  */
48
- readonly type: BadgePartialType | string;
53
+ readonly type: BadgePartialType;
49
54
  /**
50
55
  * Map the partial is located on.
51
56
  */
@@ -57,11 +62,11 @@ interface BadgePartialData {
57
62
  /**
58
63
  * Is it a wall plaque or a physical monument?
59
64
  */
60
- readonly plaqueType?: PlaqueType | string;
65
+ readonly plaqueType?: PlaqueType;
61
66
  /**
62
67
  * Plaque inscription.
63
68
  */
64
- readonly inscription?: string;
69
+ readonly plaqueInscription?: string;
65
70
  /**
66
71
  * The number or letter the partial appears as on Vidiot Maps.
67
72
  */
@@ -77,7 +82,7 @@ interface BadgePartialData {
77
82
  /**
78
83
  * The types of enhancements required to be crafted.
79
84
  */
80
- readonly inventionTypes?: (EnhancementCategory | string)[];
85
+ readonly inventionTypes?: EnhancementCategory[];
81
86
  /**
82
87
  * Number of invention crafts required.
83
88
  */
@@ -85,7 +90,7 @@ interface BadgePartialData {
85
90
  /**
86
91
  * Any additional notes.
87
92
  */
88
- readonly notes?: string;
93
+ readonly notes?: MarkdownString;
89
94
  }
90
95
 
91
96
  interface Link {
@@ -106,7 +111,7 @@ interface BadgeData {
106
111
  /**
107
112
  * The type of badge.
108
113
  */
109
- readonly type: BadgeType | string;
114
+ readonly type: BadgeType;
110
115
  /**
111
116
  * The name of this badge.
112
117
  *
@@ -123,10 +128,8 @@ interface BadgeData {
123
128
  readonly badgeText?: AlternateData<string>[];
124
129
  /**
125
130
  * Description of how to acquire the badge.
126
- *
127
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
128
131
  */
129
- readonly acquisition?: string;
132
+ readonly acquisition?: MarkdownString;
130
133
  /**
131
134
  * List of absolute URLs for this badge's icons.
132
135
  *
@@ -135,10 +138,8 @@ interface BadgeData {
135
138
  readonly icon?: AlternateData<string>[];
136
139
  /**
137
140
  * Freeform notes or tips about the badge.
138
- *
139
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
140
141
  */
141
- readonly notes?: string;
142
+ readonly notes?: MarkdownString;
142
143
  /**
143
144
  * List of external links for this Badge. Wiki, forums, etc.
144
145
  */
@@ -170,10 +171,8 @@ interface BadgeData {
170
171
  };
171
172
  /**
172
173
  * A description of the effect the badge will have, such as a buff or granting a temporary power.
173
- *
174
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
175
174
  */
176
- readonly effect?: string;
175
+ readonly effect?: MarkdownString;
177
176
  /**
178
177
  * 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.
179
178
  */
@@ -194,9 +193,9 @@ interface Change {
194
193
  */
195
194
  date: Date;
196
195
  /**
197
- * Description of the change in {@link https://www.markdownguide.org/|Markdown} format.
196
+ * Description of the change.
198
197
  */
199
- description: string;
198
+ description: MarkdownString;
200
199
  }
201
200
 
202
201
  interface VidiotMapPointOfInterestData {
@@ -208,10 +207,8 @@ interface VidiotMapPointOfInterestData {
208
207
  readonly pos?: [number, number];
209
208
  /**
210
209
  * Freeform notes about the PoI.
211
- *
212
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
213
210
  */
214
- readonly notes?: string;
211
+ readonly notes?: MarkdownString;
215
212
  /**
216
213
  * If the POI is a zone transfer, the map it transfers to.
217
214
  */
@@ -272,10 +269,8 @@ interface ContentBundle {
272
269
  readonly name: string;
273
270
  /**
274
271
  * Description of the fork.
275
- *
276
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
277
272
  */
278
- readonly description?: string;
273
+ readonly description?: MarkdownString;
279
274
  /**
280
275
  * Repository where the db content package is maintained.
281
276
  */
@@ -307,6 +302,34 @@ interface ContentBundle {
307
302
  readonly changelog?: Change[];
308
303
  }
309
304
 
305
+ declare class Alignments {
306
+ readonly items: Alignment[];
307
+ readonly hero: boolean;
308
+ readonly villain: boolean;
309
+ readonly praetorian: boolean;
310
+ readonly primal: boolean;
311
+ constructor(raw: Alignment[]);
312
+ }
313
+
314
+ declare class Alternates<T> {
315
+ #private;
316
+ constructor(values: AlternateData<T>[]);
317
+ getValue(alignment?: Alignment, sex?: Sex): T | undefined;
318
+ /**
319
+ * Get the default value for this list of alternates, the value with the highest priority and lowest specificity.
320
+ */
321
+ get default(): AlternateData<T> | undefined;
322
+ /**
323
+ * Get the list of alternates sorted in canonical order (alignment then sex, low to high specificity).
324
+ */
325
+ get canonical(): AlternateData<T>[];
326
+ /**
327
+ * Create a joined string from the alternate values in canonical order.
328
+ * @param separator Separator to use. Default is ' / '
329
+ */
330
+ toString(separator: string): string;
331
+ }
332
+
310
333
  declare class Archetype {
311
334
  readonly key: string;
312
335
  readonly name: string;
@@ -315,38 +338,55 @@ declare class Archetype {
315
338
  }
316
339
 
317
340
  declare class BadgePartial {
341
+ /**
342
+ * Key.
343
+ */
318
344
  readonly key: string;
319
- readonly type: BadgePartialType | string;
345
+ /**
346
+ * Type of partial.
347
+ */
348
+ readonly type: BadgePartialType;
349
+ /**
350
+ * Map the partial is located on.
351
+ */
320
352
  readonly mapKey?: string;
353
+ /**
354
+ * /loc coordinates.
355
+ */
321
356
  readonly loc?: number[];
322
- readonly plaqueType?: PlaqueType | string;
323
- readonly inscription?: string;
357
+ /**
358
+ * Is it a wall plaque or a physical monument?
359
+ */
360
+ readonly plaqueType?: PlaqueType;
361
+ /**
362
+ * Plaque inscription.
363
+ */
364
+ readonly plaqueInscription?: string;
365
+ /**
366
+ * The number or letter the partial appears as on Vidiot Maps.
367
+ */
324
368
  readonly vidiotMapKey?: string;
369
+ /**
370
+ * The badge required for this partial.
371
+ */
325
372
  readonly badgeKey?: string;
373
+ /**
374
+ * Level of the invention required.
375
+ */
326
376
  readonly inventionLevel?: number;
327
- readonly inventionTypes?: (EnhancementCategory | string)[];
328
- readonly inventionCount?: number;
329
- readonly notes?: string;
330
- constructor(data: BadgePartialData);
331
- }
332
-
333
- declare class Alternates<T> {
334
- #private;
335
- constructor(values: AlternateData<T>[]);
336
- getValue(alignment?: Alignment | string, sex?: Sex | string): T | undefined;
337
377
  /**
338
- * Get the default value for this list of alternates, the value with the highest priority and lowest specificity.
378
+ * The types of enhancements required to be crafted.
339
379
  */
340
- get default(): T | undefined;
380
+ readonly inventionTypes?: EnhancementCategory[];
341
381
  /**
342
- * Get the list of alternates sorted in canonical order (alignment then sex, low to high specificity).
382
+ * Number of invention crafts required.
343
383
  */
344
- get canonical(): AlternateData<T>[];
384
+ readonly inventionCount?: number;
345
385
  /**
346
- * Create a joined string from the alternate values in canonical order.
347
- * @param separator Separator to use. Default is ' / '
386
+ * Any additional notes.
348
387
  */
349
- toString(separator: string): string;
388
+ readonly notes?: MarkdownString;
389
+ constructor(data: BadgePartialData);
350
390
  }
351
391
 
352
392
  declare class Badge {
@@ -358,7 +398,7 @@ declare class Badge {
358
398
  /**
359
399
  * The type of badge.
360
400
  */
361
- readonly type: BadgeType | string;
401
+ readonly type: BadgeType;
362
402
  /**
363
403
  * The name of this badge.
364
404
  *
@@ -368,17 +408,15 @@ declare class Badge {
368
408
  /**
369
409
  * The character alignments that this badge is available to.
370
410
  */
371
- readonly alignment: Alignment[];
411
+ readonly alignment: Alignments;
372
412
  /**
373
413
  * The badge text as it appears in-game. May vary by character sex or alignment.
374
414
  */
375
415
  readonly badgeText: Alternates<string>;
376
416
  /**
377
417
  * Description of how to acquire the badge.
378
- *
379
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
380
418
  */
381
- readonly acquisition?: string;
419
+ readonly acquisition?: MarkdownString;
382
420
  /**
383
421
  * Absolute URL to this badge's icon.
384
422
  *
@@ -387,10 +425,8 @@ declare class Badge {
387
425
  readonly icon: Alternates<string>;
388
426
  /**
389
427
  * Freeform notes or tips about the badge.
390
- *
391
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
392
428
  */
393
- readonly notes?: string;
429
+ readonly notes?: MarkdownString;
394
430
  /**
395
431
  * List of external links for this Badge. Wiki, forums, etc.
396
432
  */
@@ -422,10 +458,8 @@ declare class Badge {
422
458
  };
423
459
  /**
424
460
  * A description of the effect the badge will have, such as a buff or granting a temporary power.
425
- *
426
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
427
461
  */
428
- readonly effect?: string;
462
+ readonly effect?: MarkdownString;
429
463
  /**
430
464
  * 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.
431
465
  */
@@ -438,6 +472,50 @@ declare class Badge {
438
472
  getPartial(key: string): BadgePartial;
439
473
  }
440
474
 
475
+ interface BadgeSearchOptions {
476
+ /**
477
+ * Text-based search.
478
+ *
479
+ * Case-insensitive. Defaults to searching on name only.
480
+ */
481
+ query?: {
482
+ str?: string;
483
+ on?: {
484
+ name?: boolean;
485
+ badgeText?: boolean;
486
+ acquisition?: boolean;
487
+ notes?: boolean;
488
+ effect?: boolean;
489
+ setTitle?: boolean;
490
+ };
491
+ };
492
+ /**
493
+ * Filter results matching the given values.
494
+ */
495
+ filter?: {
496
+ type?: BadgeType;
497
+ mapKey?: string;
498
+ alignment?: Alignment;
499
+ };
500
+ /**
501
+ * Sort results.
502
+ *
503
+ * Badges are assumed to be in canonical order in the content bundle, and should match the in-game display order.
504
+ */
505
+ sort?: {
506
+ by?: 'CANONICAL' | 'BADGE_NAME' | 'MAP_NAME';
507
+ dir?: 'ASC' | 'DESC';
508
+ };
509
+ /**
510
+ * The page (1-based)
511
+ */
512
+ page?: number;
513
+ /**
514
+ * How many results per page
515
+ */
516
+ pageSize?: number;
517
+ }
518
+
441
519
  declare class VidiotMapPointOfInterest {
442
520
  /**
443
521
  * The pixel-space position of the PoI on the map graphic.
@@ -447,10 +525,8 @@ declare class VidiotMapPointOfInterest {
447
525
  readonly pos?: [number, number];
448
526
  /**
449
527
  * Freeform notes about the PoI.
450
- *
451
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
452
528
  */
453
- readonly notes?: string;
529
+ readonly notes?: MarkdownString;
454
530
  /**
455
531
  * If the POI is a zone transfer, the map it transfers to.
456
532
  */
@@ -502,6 +578,21 @@ declare class GameMap {
502
578
  constructor(data: GameMapData);
503
579
  }
504
580
 
581
+ interface Paged<T> {
582
+ items: T[];
583
+ page: number;
584
+ pageSize?: number;
585
+ totalItems: number;
586
+ totalPages: number;
587
+ }
588
+
589
+ declare class BadgeIndex {
590
+ #private;
591
+ constructor(badges: Badge[], maps?: GameMap[]);
592
+ getBadge(key: string): Badge;
593
+ searchBadges(options?: BadgeSearchOptions): Paged<Badge>;
594
+ }
595
+
505
596
  declare class BundleMetadata {
506
597
  /**
507
598
  * Name of the server group.
@@ -509,10 +600,8 @@ declare class BundleMetadata {
509
600
  readonly name: string;
510
601
  /**
511
602
  * Description of the server group.
512
- *
513
- * Supports {@link https://www.markdownguide.org/|Markdown} format.
514
603
  */
515
- readonly description?: string;
604
+ readonly description?: MarkdownString;
516
605
  /**
517
606
  * Repository where the db content package is maintained.
518
607
  */
@@ -559,7 +648,13 @@ declare class CohContentDatabase {
559
648
  getArchetype(key: string): Archetype;
560
649
  getMap(key: string): GameMap;
561
650
  getBadge(key: string): Badge;
562
- searchBadges(query?: string): Badge[];
651
+ /**
652
+ * Search, sort and filter the badge list.
653
+ * This is a fairly brute-forced approach and will not be as performant as loading the badge data into a traditional
654
+ * database engine, but is sufficient for most operations.
655
+ * @param options {@link BadgeSearchOptions}
656
+ */
657
+ searchBadges(options?: BadgeSearchOptions): Paged<Badge>;
563
658
  }
564
659
 
565
660
  declare class Key {
@@ -571,18 +666,44 @@ declare class Key {
571
666
  declare const CHANGELOG: Change[];
572
667
 
573
668
  /**
574
- * Create a reference string that can be used in most text strings to display a link to the given badge.
669
+ * Returns the URI of the given badge that can be used in {@link MarkdownString} links.
670
+ *
671
+ * URI format: `badge://<key>`
672
+ *
673
+ * @param target The badge or badge key to target.
674
+ */
675
+ declare function badgeUri(target: string | {
676
+ key: string;
677
+ }): string;
678
+ /**
679
+ * Returns a {@link MarkdownString} link to the given badge.
680
+ *
681
+ * Link format: `[<key>](badge://<key>)`
682
+ *
575
683
  * @param target The badge or badge key to target.
576
684
  */
577
- declare function createBadgeReference(target: string | {
685
+ declare function badgeLink(target: string | {
578
686
  key: string;
579
687
  }): string;
580
688
  /**
581
- * Create a reference string that can be used in most text strings to display a link to the given map.
689
+ * Returns the URI of the given map that can be used in {@link MarkdownString} links.
690
+ *
691
+ * URI format: `map://<key>`
692
+ *
582
693
  * @param target The {@link GameMap} or map key to target.
583
694
  */
584
- declare function createMapReference(target: string | {
695
+ declare function mapUri(target: string | {
696
+ key: string;
697
+ }): string;
698
+ /**
699
+ * Returns a {@link MarkdownString} link to the given map.
700
+ *
701
+ * Link format: `[<key>](map://<key>)`
702
+ *
703
+ * @param target The map or map key to target.
704
+ */
705
+ declare function mapLink(target: string | {
585
706
  key: string;
586
707
  }): string;
587
708
 
588
- export { ALIGNMENT, type Alignment, type AlternateData, Archetype, type ArchetypeData, BADGE_PARTIAL_TYPE, BADGE_TYPE, Badge, type BadgeData, BadgePartial, type BadgePartialData, type BadgePartialType, type BadgeType, BundleMetadata, CHANGELOG, type Change, CohContentDatabase, type ContentBundle, ENHANCEMENT_CATEGORY, type EnhancementCategory, GameMap, type GameMapData, Key, type Link, PLAQUE_TYPE, type PlaqueType, SEX, type Sex, VidiotMap, type VidiotMapData, VidiotMapPointOfInterest, type VidiotMapPointOfInterestData, createBadgeReference, createMapReference };
709
+ export { ALIGNMENT, type Alignment, Alignments, type AlternateData, Alternates, Archetype, type ArchetypeData, BADGE_PARTIAL_TYPE, BADGE_TYPE, Badge, type BadgeData, BadgeIndex, BadgePartial, type BadgePartialData, type BadgePartialType, type BadgeSearchOptions, type BadgeType, BundleMetadata, CHANGELOG, type Change, CohContentDatabase, type ContentBundle, ENHANCEMENT_CATEGORY, type EnhancementCategory, GameMap, type GameMapData, Key, type Link, type MarkdownString, PLAQUE_TYPE, type Paged, type PlaqueType, SEX, type Sex, VidiotMap, type VidiotMapData, VidiotMapPointOfInterest, type VidiotMapPointOfInterestData, badgeLink, badgeUri, mapLink, mapUri };