@optolith/entity-descriptions 0.14.0 → 0.16.0

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 (62) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/lib/creator.d.ts +17 -12
  3. package/lib/creator.js +89 -17
  4. package/lib/entities/activatable.d.ts +5 -2
  5. package/lib/entities/activatable.js +7 -1
  6. package/lib/entities/alternativeRule.d.ts +1 -1
  7. package/lib/entities/attribute.d.ts +1 -3
  8. package/lib/entities/combatTechnique.d.ts +2 -2
  9. package/lib/entities/condition.d.ts +2 -6
  10. package/lib/entities/culture.d.ts +2 -1
  11. package/lib/entities/curriculum.d.ts +1 -1
  12. package/lib/entities/derivedCharacteristic.d.ts +1 -1
  13. package/lib/entities/disease.d.ts +1 -1
  14. package/lib/entities/disease.js +5 -6
  15. package/lib/entities/elixir.d.ts +1 -1
  16. package/lib/entities/elixir.js +2 -2
  17. package/lib/entities/equipment.d.ts +6 -8
  18. package/lib/entities/equipment.js +517 -213
  19. package/lib/entities/equipmentPackage.d.ts +1 -1
  20. package/lib/entities/experienceLevel.d.ts +1 -3
  21. package/lib/entities/focusRule.d.ts +1 -1
  22. package/lib/entities/influence.d.ts +1 -1
  23. package/lib/entities/liturgicalChant.d.ts +3 -3
  24. package/lib/entities/optionalRule.d.ts +1 -3
  25. package/lib/entities/partial/commonnessRatedAdvantagesAndDisadvantages.d.ts +1 -1
  26. package/lib/entities/partial/enhancements.d.ts +1 -1
  27. package/lib/entities/partial/herbary.d.ts +6 -3
  28. package/lib/entities/partial/herbary.js +5 -3
  29. package/lib/entities/partial/prerequisites/index.d.ts +1 -1
  30. package/lib/entities/partial/rated/activatable/effect.d.ts +1 -1
  31. package/lib/entities/partial/rated/activatable/index.d.ts +1 -1
  32. package/lib/entities/partial/rated/activatable/targetCategory.d.ts +1 -1
  33. package/lib/entities/partial/rated/improvementCost.d.ts +1 -1
  34. package/lib/entities/partial/units/simple.d.ts +55 -0
  35. package/lib/entities/partial/units/simple.js +56 -0
  36. package/lib/entities/personalityTrait.d.ts +1 -1
  37. package/lib/entities/poison.d.ts +1 -1
  38. package/lib/entities/poison.js +2 -2
  39. package/lib/entities/profession.d.ts +2 -1
  40. package/lib/entities/race.d.ts +2 -2
  41. package/lib/entities/sexPractice.d.ts +1 -3
  42. package/lib/entities/skill.d.ts +1 -1
  43. package/lib/entities/spell.d.ts +17 -16
  44. package/lib/entities/state.d.ts +1 -3
  45. package/lib/entities/tradeSecret.d.ts +4 -0
  46. package/lib/entities/tradeSecret.js +77 -0
  47. package/lib/entityDescription.d.ts +118 -0
  48. package/lib/entityDescription.js +1 -0
  49. package/lib/env.d.ts +9 -2
  50. package/lib/helpers/locale.d.ts +4 -0
  51. package/lib/index.d.ts +247 -423
  52. package/lib/index.js +9 -1
  53. package/lib/rawEntityDescription.d.ts +144 -0
  54. package/lib/rawEntityDescription.js +1 -0
  55. package/lib/references/index.d.ts +2 -3
  56. package/lib/references/index.js +11 -16
  57. package/lib/references/page.d.ts +4 -2
  58. package/lib/references/page.js +6 -4
  59. package/lib/references/pageRange.d.ts +3 -3
  60. package/lib/references/pageRange.js +6 -4
  61. package/lib/tsconfig.tsbuildinfo +1 -1
  62. package/package.json +3 -2
package/lib/index.js CHANGED
@@ -15,6 +15,7 @@ import { getFocusRuleEntityDescription } from "./entities/focusRule.js";
15
15
  import { getInfluenceEntityDescription } from "./entities/influence.js";
16
16
  import { getBlessingEntityDescription, getCeremonyEntityDescription, getLiturgicalChantEntityDescription, } from "./entities/liturgicalChant.js";
17
17
  import { getOptionalRuleEntityDescription } from "./entities/optionalRule.js";
18
+ import { ResponsiveTextSize } from "./entities/partial/responsiveText.js";
18
19
  import { getPersonalityTraitEntityDescription } from "./entities/personalityTrait.js";
19
20
  import { getPoisonEntityDescription } from "./entities/poison.js";
20
21
  import { getProfessionVersionEntityDescription } from "./entities/profession.js";
@@ -23,6 +24,7 @@ import { getSexPracticeEntityDescription } from "./entities/sexPractice.js";
23
24
  import { getSkillEntityDescription } from "./entities/skill.js";
24
25
  import { getAnimistPowerEntityDescription, getBannzeichenEntityDescription, getCantripEntityDescription, getCurseEntityDescription, getDominationRitualEntityDescription, getElvenMagicalSongEntityDescription, getFamiliarsTrickEntityDescription, getGeodeRitualEntityDescription, getGoblinRitualEntityDescription, getJesterTrickEntityDescription, getMagicalDanceEntityDescription, getMagicalMelodyEntityDescription, getMagicalRuneEntityDescription, getRitualEntityDescription, getSpellEntityDescription, getZibiljaRitualEntityDescription, } from "./entities/spell.js";
25
26
  import { getStateEntityDescription } from "./entities/state.js";
27
+ import { getTradeSecretEntityDescription } from "./entities/tradeSecret.js";
26
28
  const registeredEntityDescriptionCreators = {
27
29
  // rules
28
30
  // CoreRule: getCoreRuleEntityDescription,
@@ -124,6 +126,8 @@ const registeredEntityDescriptionCreators = {
124
126
  Vision: getActivatableEntityDescription,
125
127
  WandEnchantment: getActivatableEntityDescription,
126
128
  WeaponEnchantment: getActivatableEntityDescription,
129
+ // auxiliary special ability
130
+ TradeSecret: getTradeSecretEntityDescription,
127
131
  // equipment
128
132
  Ammunition: getEquipmentEntityDescription,
129
133
  Animal: getEquipmentEntityDescription,
@@ -177,7 +181,7 @@ export const supportedEntities = Object.keys(registeredEntityDescriptionCreators
177
181
  * Get a JSON representation of the rules text for an entry in the database.
178
182
  */
179
183
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- false positive
180
- export const getEntityDescription = (database, localeEnv, idMap, getResolvedSelectOptionById, getAllResolvedSelectOptions, getAllResolvedNewSkillApplications, getAllResolvedSkillUses, entityName, instanceId, publicationOptions) => {
184
+ export const getEntityDescription = (database, localeEnv, idMap, getResolvedSelectOptionById, getAllResolvedSelectOptions, getAllResolvedNewSkillApplications, getAllResolvedSkillUses, entityName, instanceId, publicationOptions, responsiveTextSize = "Full") => {
181
185
  const creator = registeredEntityDescriptionCreators[entityName];
182
186
  const instance = database.getInstanceOfEntityById(entityName, instanceId);
183
187
  if (!instance) {
@@ -193,5 +197,9 @@ export const getEntityDescription = (database, localeEnv, idMap, getResolvedSele
193
197
  getAllResolvedNewSkillApplications,
194
198
  getAllResolvedSkillUses,
195
199
  idMap,
200
+ ...localeEnv,
201
+ localeJoin: localeEnv.join,
202
+ localeCompare: localeEnv.compare,
203
+ responsiveTextSize: ResponsiveTextSize[responsiveTextSize],
196
204
  }, localeEnv, { entity: entityName, content: instance, id: instanceId }, { publications: publicationOptions });
197
205
  };
@@ -0,0 +1,144 @@
1
+ import type { AnyNonNullish } from "@elyukai/utils/nullable";
2
+ import type { Reader } from "@elyukai/utils/reader";
3
+ import type { Errata, PublicationRefs } from "@optolith/database-schema/gen";
4
+ /**
5
+ * A JSON representation of the rules text for a library entry that has not been
6
+ * cleaned up.
7
+ */
8
+ export type RawEntityDescription<Cols extends string = string, E = AnyNonNullish> = RawTextEntityDescription<E> | RawTabularEntityDescription<Cols, E> | RawTabularEntityDescription<Cols, E>[];
9
+ /**
10
+ * A JSON representation of the rules text for a library entry that has not been
11
+ * cleaned up.
12
+ */
13
+ export type RawTextEntityDescription<E> = {
14
+ type?: "text";
15
+ category?: {
16
+ label: Reader<E, string>;
17
+ value: Reader<E, string>;
18
+ };
19
+ title: string;
20
+ subtitle?: string;
21
+ badge?: RawEntityDescriptionBadge;
22
+ className: string;
23
+ body: (RawEntityDescriptionSection | RawEntityDescriptionSectionR<E> | undefined)[];
24
+ errata?: Errata;
25
+ references?: PublicationRefs;
26
+ };
27
+ /**
28
+ * A JSON representation of the table for a library entry that has not been
29
+ * cleaned up.
30
+ */
31
+ export type RawTabularEntityDescription<Cols extends string, E> = {
32
+ type: "tabular";
33
+ category?: {
34
+ label: Reader<E, string>;
35
+ value: Reader<E, string>;
36
+ };
37
+ title: string;
38
+ labels: {
39
+ [K in Cols]: Reader<E, string>;
40
+ };
41
+ values: {
42
+ [K in Cols]: Reader<E, string>;
43
+ };
44
+ additionalInformation?: ({
45
+ label: Reader<E, string>;
46
+ id: string;
47
+ value: Reader<E, string | undefined>;
48
+ } | undefined)[];
49
+ errata?: Errata;
50
+ references?: PublicationRefs;
51
+ };
52
+ /**
53
+ * A badge that can be displayed next to the title of a library entry.
54
+ */
55
+ export type RawEntityDescriptionBadge = {
56
+ type: "level" | "armedCombat" | "unarmedCombat";
57
+ value: string;
58
+ };
59
+ /**
60
+ * A labeled or unlabeled section of a library entry text.
61
+ */
62
+ export type RawEntityDescriptionSection = RawEntityDescriptionSectionContent<RawDefinitionListEntityDescriptionSection> | RawLabeledEntityDescriptionSection;
63
+ /**
64
+ * A labeled or unlabeled section of a library entry text.
65
+ */
66
+ export type RawEntityDescriptionSectionR<E> = RawEntityDescriptionSectionContent<RawDefinitionListEntityDescriptionSectionR<E>> | RawLabeledEntityDescriptionSectionR<E>;
67
+ /**
68
+ * A slice of the content of a library entry text.
69
+ */
70
+ export type RawEntityDescriptionSectionContent<DL> = RawPlainEntityDescriptionSection | DL | RawTableEntityDescriptionSection;
71
+ /**
72
+ * A labeled section of a library entry text.
73
+ */
74
+ export type RawLabeledEntityDescriptionSection = {
75
+ type: "labeled";
76
+ label: string;
77
+ value: RawEntityDescriptionSectionContent<RawDefinitionListEntityDescriptionSection>;
78
+ };
79
+ /**
80
+ * A labeled section of a library entry text.
81
+ */
82
+ export type RawLabeledEntityDescriptionSectionR<E> = {
83
+ type: "labeled";
84
+ label: string;
85
+ value: RawEntityDescriptionSectionContent<RawDefinitionListEntityDescriptionSectionR<E>>;
86
+ };
87
+ /**
88
+ * A plain text, possibly containing Markdown syntax.
89
+ */
90
+ export type RawPlainEntityDescriptionSection = {
91
+ type: "plain";
92
+ text: string;
93
+ };
94
+ /**
95
+ * A list of labeled values, such as prerequisites or quality levels.
96
+ */
97
+ export type RawDefinitionListEntityDescriptionSection = {
98
+ type: "definitionList";
99
+ items: (RawDefinitionListEntityDescriptionSectionItem | undefined)[];
100
+ };
101
+ /**
102
+ * A list of labeled values, such as prerequisites or quality levels.
103
+ */
104
+ export type RawDefinitionListEntityDescriptionSectionR<E> = {
105
+ type: "definitionList";
106
+ items: (RawDefinitionListEntityDescriptionSectionItemR<E> | undefined)[];
107
+ };
108
+ /**
109
+ * A list of labeled values, such as prerequisites or quality levels, nested within another definition list.
110
+ */
111
+ export type RawNestedDefinitionListEntityDescriptionSection = {
112
+ type: "definitionList";
113
+ /**
114
+ * How to render this definition list.
115
+ *
116
+ * - `"hidden"`: The definition list does not look like it is nested, it just looks like it belongs to its parent definition list.
117
+ * - `"nested"`: The definition list is visually nested inside its parent definition list, usually indented and with italic labels instead of bold ones.
118
+ */
119
+ style: "hidden" | "nested";
120
+ items: (RawDefinitionListEntityDescriptionSectionItem | undefined)[];
121
+ };
122
+ /**
123
+ * A single labeled value in a definition list.
124
+ */
125
+ export type RawDefinitionListEntityDescriptionSectionItem = {
126
+ label: string;
127
+ value: string | (RawEntityDescriptionSectionContent<RawNestedDefinitionListEntityDescriptionSection> | undefined)[];
128
+ };
129
+ /**
130
+ * A single labeled value in a definition list.
131
+ */
132
+ export type RawDefinitionListEntityDescriptionSectionItemR<E> = {
133
+ label: Reader<E, string>;
134
+ value: Reader<E, string | (RawEntityDescriptionSectionContent<RawNestedDefinitionListEntityDescriptionSection> | undefined)[]>;
135
+ };
136
+ /**
137
+ * A table with a header, rows, and an optional footer.
138
+ */
139
+ export type RawTableEntityDescriptionSection = {
140
+ type: "table";
141
+ header: string[];
142
+ rows: string[][];
143
+ footer?: string[];
144
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,7 @@
1
1
  import type { PublicationRefs } from "@optolith/database-schema/gen";
2
- import type { GetInstanceById } from "../helpers/getTypes.js";
3
- import type { LocaleEnvironment } from "../helpers/locale.js";
2
+ import type { StdReader } from "../env.js";
4
3
  import { type PublicationOptions } from "./publicationOptions.js";
5
4
  /**
6
5
  * Returns the translation of the references.
7
6
  */
8
- export declare const getReferencesTranslation: (getInstanceById: GetInstanceById<"Publication">, publicationOptions: PublicationOptions, locale: LocaleEnvironment, references: PublicationRefs) => string;
7
+ export declare const getReferencesTranslation: (publicationOptions: PublicationOptions, references: PublicationRefs) => StdReader<string, "t" | "tm" | "ibi", "Publication">;
@@ -1,41 +1,36 @@
1
+ import { Reader } from "@elyukai/utils/reader";
1
2
  import { isNotNullish } from "@optolith/helpers/nullable";
2
3
  import { assertExhaustive } from "@optolith/helpers/typeSafety";
4
+ import { getInstanceByIdR, sequence, translateMapR, translateR, } from "../entities/partial/reader.js";
3
5
  import { fromRawPageRange, normalizePageRanges, printPageRanges } from "./pageRange.js";
4
6
  import { isPublicationIncluded } from "./publicationOptions.js";
5
7
  /**
6
8
  * Returns the translation of the references.
7
9
  */
8
- export const getReferencesTranslation = (getInstanceById, publicationOptions, locale, references) => references
9
- .map(ref => {
10
- const publication = getInstanceById("Publication", ref.id);
11
- const publicationTranslations = locale.translateMap(publication?.translations);
12
- const occurrences = locale.translateMap(ref.occurrences);
10
+ export const getReferencesTranslation = (publicationOptions, references) => Reader.traverse(references, ref => getInstanceByIdR("Publication", ref.id).thenW(publication => translateMapR(publication?.translations).thenW(publicationTranslation => translateMapR(ref.occurrences).thenW(occurrences => {
13
11
  if (publication === undefined ||
14
- publicationTranslations === undefined ||
12
+ publicationTranslation === undefined ||
15
13
  occurrences === undefined ||
16
14
  (publicationOptions.onlyShowReferencesToIncludedPublications &&
17
15
  !isPublicationIncluded(publicationOptions, ref.id, publication))) {
18
- return undefined;
16
+ return Reader.of(undefined);
19
17
  }
20
18
  const initialPageRanges = normalizePageRanges(occurrences.initial.pages.map(fromRawPageRange));
21
19
  const initial = occurrences.initial.printing === undefined
22
- ? printPageRanges(locale.translate, initialPageRanges)
23
- : `${printPageRanges(locale.translate, initialPageRanges)} (${locale.translate(".input {$printing :number} {{since the {$printing}. printing}}", { printing: occurrences.initial.printing })})`;
20
+ ? printPageRanges(initialPageRanges)
21
+ : sequence `${printPageRanges(initialPageRanges)} (${translateR(".input {$printing :number} {{since the {$printing}. printing}}", { printing: occurrences.initial.printing })})`;
24
22
  const revisions = occurrences.revisions?.map(rev => {
25
23
  switch (rev.kind) {
26
24
  case "Since": {
27
25
  const pageRanges = normalizePageRanges(rev.Since.pages.map(fromRawPageRange));
28
- return `${printPageRanges(locale.translate, pageRanges)} (${locale.translate(".input {$printing :number} {{since the {$printing}. printing}}", { printing: rev.Since.printing })})`;
26
+ return sequence `${printPageRanges(pageRanges)} (${translateR(".input {$printing :number} {{since the {$printing}. printing}}", { printing: rev.Since.printing })})`;
29
27
  }
30
28
  case "Deprecated": {
31
- return locale.translate(".input {$printing :number} {{removed in {$printing}. printing}}", { printing: rev.Deprecated.printing });
29
+ return translateR(".input {$printing :number} {{removed in {$printing}. printing}}", { printing: rev.Deprecated.printing });
32
30
  }
33
31
  default:
34
32
  return assertExhaustive(rev);
35
33
  }
36
34
  }) ?? [];
37
- const allPageRanges = [initial, ...revisions].join("; ");
38
- return `${publicationTranslations.name} ${allPageRanges}`;
39
- })
40
- .filter(isNotNullish)
41
- .join("; ");
35
+ return Reader.sequence([initial, ...revisions]).map(list => `${publicationTranslation.name} ${list.join("; ")}`);
36
+ })))).map(list => list.filter(isNotNullish).join("; "));
@@ -1,6 +1,6 @@
1
+ import { Reader } from "@elyukai/utils/reader";
1
2
  import type { Page } from "@optolith/database-schema/gen";
2
3
  import type { Compare } from "@optolith/helpers/compare";
3
- import type { Translate } from "../helpers/translate.js";
4
4
  /**
5
5
  * A comparison function for two pages.
6
6
  */
@@ -20,4 +20,6 @@ export declare const numberToPage: (number: number) => Page;
20
20
  /**
21
21
  * Returns a string representation of a page.
22
22
  */
23
- export declare const printPage: (translate: Translate, page: Page) => string;
23
+ export declare const printPage: (page: Page) => Reader<{
24
+ translate: import("../helpers/translate.js").Translate;
25
+ }, string>;
@@ -1,4 +1,6 @@
1
+ import { Reader } from "@elyukai/utils/reader";
1
2
  import { assertExhaustive } from "@optolith/helpers/typeSafety";
3
+ import { translateR } from "../entities/partial/reader.js";
2
4
  /**
3
5
  * A comparison function for two pages.
4
6
  */
@@ -47,14 +49,14 @@ export const numberToPage = (number) => ({
47
49
  /**
48
50
  * Returns a string representation of a page.
49
51
  */
50
- export const printPage = (translate, page) => {
52
+ export const printPage = (page) => {
51
53
  switch (page.kind) {
52
54
  case "InsideCoverFront":
53
- return translate("Front Cover Inside");
55
+ return translateR("Front Cover Inside");
54
56
  case "InsideCoverBack":
55
- return translate("Back Cover Inside");
57
+ return translateR("Back Cover Inside");
56
58
  case "Numbered":
57
- return page.Numbered.toFixed();
59
+ return Reader.of(page.Numbered.toFixed());
58
60
  default:
59
61
  return assertExhaustive(page);
60
62
  }
@@ -1,5 +1,5 @@
1
1
  import type { Page, PageRange as RawPageRange } from "@optolith/database-schema/gen";
2
- import type { Translate } from "../helpers/translate.js";
2
+ import type { StdReader } from "../env.js";
3
3
  /**
4
4
  * A range of pages, including the first and last page, if the range includes
5
5
  * more than on page.
@@ -19,8 +19,8 @@ export declare const normalizePageRanges: (ranges: PageRange[]) => PageRange[];
19
19
  /**
20
20
  * Returns a string representation of a page range.
21
21
  */
22
- export declare const printPageRange: (translate: Translate, pageRange: PageRange) => string;
22
+ export declare const printPageRange: (pageRange: PageRange) => StdReader<string, "t">;
23
23
  /**
24
24
  * Returns a string representation of a list of page ranges.
25
25
  */
26
- export declare const printPageRanges: (translate: Translate, pageRanges: PageRange[]) => string;
26
+ export declare const printPageRanges: (pageRanges: PageRange[]) => StdReader<string, "t">;
@@ -1,4 +1,6 @@
1
+ import { Reader } from "@elyukai/utils/reader";
1
2
  import { range } from "@optolith/helpers/array";
3
+ import { sequence } from "../entities/partial/reader.js";
2
4
  import { comparePage, equalsPage, printPage, succ } from "./page.js";
3
5
  /**
4
6
  * Converts a page object range from the database to a local page object range.
@@ -40,10 +42,10 @@ export const normalizePageRanges = (ranges) => ranges
40
42
  /**
41
43
  * Returns a string representation of a page range.
42
44
  */
43
- export const printPageRange = (translate, pageRange) => pageRange.lastPage === undefined
44
- ? printPage(translate, pageRange.firstPage)
45
- : `${printPage(translate, pageRange.firstPage)}–${printPage(translate, pageRange.lastPage)}`;
45
+ export const printPageRange = (pageRange) => pageRange.lastPage === undefined
46
+ ? printPage(pageRange.firstPage)
47
+ : sequence `${printPage(pageRange.firstPage)}–${printPage(pageRange.lastPage)}`;
46
48
  /**
47
49
  * Returns a string representation of a list of page ranges.
48
50
  */
49
- export const printPageRanges = (translate, pageRanges) => pageRanges.map(pageRange => printPageRange(translate, pageRange)).join(", ");
51
+ export const printPageRanges = (pageRanges) => Reader.traverse(pageRanges, printPageRange).map(list => list.join(", "));