optolith-database-schema 0.10.1 → 0.11.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.
Files changed (368) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/build/config.d.ts +11 -0
  3. package/{config/directories.js → build/config.js} +6 -1
  4. package/build/generate.js +64 -0
  5. package/lib/config.d.ts +155 -4
  6. package/lib/config.js +154 -154
  7. package/lib/errors.d.ts +20 -0
  8. package/lib/errors.js +33 -0
  9. package/lib/helpers/array.d.ts +14 -0
  10. package/lib/helpers/array.js +15 -0
  11. package/lib/helpers/i18n.d.ts +1 -0
  12. package/lib/helpers/i18n.js +1 -0
  13. package/lib/helpers/io.d.ts +29 -0
  14. package/lib/helpers/io.js +51 -0
  15. package/lib/helpers/objectPath.d.ts +13 -0
  16. package/lib/helpers/objectPath.js +3 -0
  17. package/lib/helpers/pair.d.ts +20 -0
  18. package/lib/helpers/pair.js +20 -0
  19. package/lib/helpers/result.d.ts +57 -0
  20. package/lib/helpers/result.js +45 -0
  21. package/lib/helpers/typeSafety.d.ts +6 -0
  22. package/lib/helpers/typeSafety.js +8 -0
  23. package/lib/main.d.ts +49 -14
  24. package/lib/main.js +46 -133
  25. package/lib/typeConfig.d.ts +10 -0
  26. package/lib/typeConfig.js +1 -0
  27. package/lib/types/Advantage.d.ts +2 -1
  28. package/lib/types/Advantage.js +9 -2
  29. package/lib/types/AnimalDisease.d.ts +3 -2
  30. package/lib/types/AnimalDisease.js +9 -2
  31. package/lib/types/AnimalType.d.ts +2 -1
  32. package/lib/types/AnimalType.js +9 -2
  33. package/lib/types/ArcaneBardTradition.d.ts +2 -1
  34. package/lib/types/ArcaneBardTradition.js +9 -2
  35. package/lib/types/ArcaneDancerTradition.d.ts +2 -1
  36. package/lib/types/ArcaneDancerTradition.js +9 -2
  37. package/lib/types/Aspect.d.ts +2 -1
  38. package/lib/types/Aspect.js +9 -2
  39. package/lib/types/Attribute.d.ts +2 -3
  40. package/lib/types/Attribute.js +9 -4
  41. package/lib/types/Blessing.d.ts +4 -3
  42. package/lib/types/Blessing.js +9 -2
  43. package/lib/types/Cantrip.d.ts +4 -3
  44. package/lib/types/Cantrip.js +9 -2
  45. package/lib/types/Ceremony.d.ts +4 -3
  46. package/lib/types/Ceremony.js +9 -2
  47. package/lib/types/CombatTechnique_Close.d.ts +4 -3
  48. package/lib/types/CombatTechnique_Close.js +9 -2
  49. package/lib/types/CombatTechnique_Ranged.d.ts +4 -3
  50. package/lib/types/CombatTechnique_Ranged.js +9 -2
  51. package/lib/types/Condition.d.ts +4 -3
  52. package/lib/types/Condition.js +9 -2
  53. package/lib/types/Continent.d.ts +2 -1
  54. package/lib/types/Continent.js +9 -2
  55. package/lib/types/Culture.d.ts +4 -3
  56. package/lib/types/Culture.js +13 -6
  57. package/lib/types/DerivedCharacteristic.d.ts +3 -2
  58. package/lib/types/DerivedCharacteristic.js +9 -2
  59. package/lib/types/Disadvantage.d.ts +2 -1
  60. package/lib/types/Disadvantage.js +9 -2
  61. package/lib/types/Disease.d.ts +3 -2
  62. package/lib/types/Disease.js +9 -2
  63. package/lib/types/Element.d.ts +2 -1
  64. package/lib/types/Element.js +9 -2
  65. package/lib/types/ExperienceLevel.d.ts +2 -1
  66. package/lib/types/ExperienceLevel.js +9 -2
  67. package/lib/types/EyeColor.d.ts +2 -1
  68. package/lib/types/EyeColor.js +9 -2
  69. package/lib/types/FamiliarsTrick.d.ts +4 -3
  70. package/lib/types/FamiliarsTrick.js +9 -2
  71. package/lib/types/HairColor.d.ts +2 -1
  72. package/lib/types/HairColor.js +9 -2
  73. package/lib/types/Kirchenpraegung.d.ts +2 -1
  74. package/lib/types/Kirchenpraegung.js +9 -2
  75. package/lib/types/Lessons_Curriculum.d.ts +4 -3
  76. package/lib/types/Lessons_Curriculum.js +9 -2
  77. package/lib/types/Lessons_Guideline.d.ts +2 -1
  78. package/lib/types/Lessons_Guideline.js +9 -2
  79. package/lib/types/LiturgicalChant.d.ts +4 -3
  80. package/lib/types/LiturgicalChant.js +9 -2
  81. package/lib/types/Locale.d.ts +3 -6
  82. package/lib/types/Locale.js +10 -3
  83. package/lib/types/MetaCondition.d.ts +4 -3
  84. package/lib/types/MetaCondition.js +9 -2
  85. package/lib/types/PactCategory.d.ts +4 -3
  86. package/lib/types/PactCategory.js +9 -2
  87. package/lib/types/Patron.d.ts +2 -1
  88. package/lib/types/Patron.js +11 -4
  89. package/lib/types/PatronCategory.d.ts +2 -1
  90. package/lib/types/PatronCategory.js +9 -2
  91. package/lib/types/PersonalityTrait.d.ts +4 -3
  92. package/lib/types/PersonalityTrait.js +9 -2
  93. package/lib/types/Profession.d.ts +2 -1
  94. package/lib/types/Profession.js +10 -3
  95. package/lib/types/Property.d.ts +2 -1
  96. package/lib/types/Property.js +9 -2
  97. package/lib/types/Race.d.ts +4 -3
  98. package/lib/types/Race.js +10 -3
  99. package/lib/types/Region.d.ts +2 -1
  100. package/lib/types/Region.js +9 -2
  101. package/lib/types/Ritual.d.ts +4 -3
  102. package/lib/types/Ritual.js +9 -2
  103. package/lib/types/Service.d.ts +4 -3
  104. package/lib/types/Service.js +10 -3
  105. package/lib/types/SexPractice.d.ts +3 -2
  106. package/lib/types/SexPractice.js +9 -2
  107. package/lib/types/Skill.d.ts +4 -3
  108. package/lib/types/Skill.js +11 -4
  109. package/lib/types/SkillGroup.d.ts +2 -1
  110. package/lib/types/SkillGroup.js +9 -2
  111. package/lib/types/SkillModificationLevel.d.ts +2 -1
  112. package/lib/types/SkillModificationLevel.js +10 -3
  113. package/lib/types/SocialStatus.d.ts +2 -1
  114. package/lib/types/SocialStatus.js +9 -2
  115. package/lib/types/Spell.d.ts +4 -3
  116. package/lib/types/Spell.js +9 -2
  117. package/lib/types/State.d.ts +4 -3
  118. package/lib/types/State.js +9 -2
  119. package/lib/types/Talisman.d.ts +2 -1
  120. package/lib/types/Talisman.js +10 -3
  121. package/lib/types/TargetCategory.d.ts +2 -1
  122. package/lib/types/TargetCategory.js +9 -2
  123. package/lib/types/UI.d.ts +2 -1
  124. package/lib/types/UI.js +9 -2
  125. package/lib/types/_Activatable.js +5 -5
  126. package/lib/types/_ActivatableSelectOptionCategory.js +1 -1
  127. package/lib/types/_ActivatableSkillCastingTime.js +1 -1
  128. package/lib/types/_ActivatableSkillCheckResultBased.js +2 -2
  129. package/lib/types/_ActivatableSkillDuration.js +1 -1
  130. package/lib/types/_ActivatableSkillRange.js +1 -1
  131. package/lib/types/_Dice.js +1 -1
  132. package/lib/types/_DiseasePoison.js +1 -1
  133. package/lib/types/_ImprovementCost.js +1 -1
  134. package/lib/types/_Sex.js +1 -1
  135. package/lib/types/_SkillCheck.js +1 -1
  136. package/lib/types/equipment/EquipmentPackage.d.ts +3 -2
  137. package/lib/types/equipment/EquipmentPackage.js +9 -2
  138. package/lib/types/equipment/item/Alchemicum.d.ts +2 -1
  139. package/lib/types/equipment/item/Alchemicum.js +9 -2
  140. package/lib/types/equipment/item/Ammunition.d.ts +4 -3
  141. package/lib/types/equipment/item/Ammunition.js +9 -2
  142. package/lib/types/equipment/item/Animal.d.ts +3 -2
  143. package/lib/types/equipment/item/Animal.js +9 -2
  144. package/lib/types/equipment/item/AnimalCare.d.ts +3 -2
  145. package/lib/types/equipment/item/AnimalCare.js +9 -2
  146. package/lib/types/equipment/item/Armor.d.ts +4 -3
  147. package/lib/types/equipment/item/Armor.js +9 -2
  148. package/lib/types/equipment/item/BandageOrRemedy.d.ts +3 -2
  149. package/lib/types/equipment/item/BandageOrRemedy.js +9 -2
  150. package/lib/types/equipment/item/Book.d.ts +4 -3
  151. package/lib/types/equipment/item/Book.js +9 -2
  152. package/lib/types/equipment/item/CeremonialItem.d.ts +3 -2
  153. package/lib/types/equipment/item/CeremonialItem.js +9 -2
  154. package/lib/types/equipment/item/Clothes.d.ts +2 -1
  155. package/lib/types/equipment/item/Clothes.js +9 -2
  156. package/lib/types/equipment/item/Container.d.ts +2 -1
  157. package/lib/types/equipment/item/Container.js +9 -2
  158. package/lib/types/equipment/item/Elixir.d.ts +4 -3
  159. package/lib/types/equipment/item/Elixir.js +9 -2
  160. package/lib/types/equipment/item/EquipmentOfBlessedOnes.d.ts +3 -2
  161. package/lib/types/equipment/item/EquipmentOfBlessedOnes.js +9 -2
  162. package/lib/types/equipment/item/GemOrPreciousStone.d.ts +4 -3
  163. package/lib/types/equipment/item/GemOrPreciousStone.js +9 -2
  164. package/lib/types/equipment/item/IlluminationLightSource.d.ts +3 -2
  165. package/lib/types/equipment/item/IlluminationLightSource.js +10 -3
  166. package/lib/types/equipment/item/IlluminationRefillsOrSupplies.d.ts +2 -1
  167. package/lib/types/equipment/item/IlluminationRefillsOrSupplies.js +9 -2
  168. package/lib/types/equipment/item/Jewelry.d.ts +4 -3
  169. package/lib/types/equipment/item/Jewelry.js +9 -2
  170. package/lib/types/equipment/item/Liebesspielzeug.d.ts +2 -1
  171. package/lib/types/equipment/item/Liebesspielzeug.js +9 -2
  172. package/lib/types/equipment/item/LuxuryGood.d.ts +3 -2
  173. package/lib/types/equipment/item/LuxuryGood.js +9 -2
  174. package/lib/types/equipment/item/MagicalArtifact.d.ts +4 -3
  175. package/lib/types/equipment/item/MagicalArtifact.js +9 -2
  176. package/lib/types/equipment/item/MusicalInstrument.d.ts +3 -2
  177. package/lib/types/equipment/item/MusicalInstrument.js +9 -2
  178. package/lib/types/equipment/item/OrienteeringAid.d.ts +2 -1
  179. package/lib/types/equipment/item/OrienteeringAid.js +9 -2
  180. package/lib/types/equipment/item/Poison.d.ts +4 -3
  181. package/lib/types/equipment/item/Poison.js +12 -5
  182. package/lib/types/equipment/item/RopeOrChain.d.ts +2 -1
  183. package/lib/types/equipment/item/RopeOrChain.js +9 -2
  184. package/lib/types/equipment/item/Stationary.d.ts +2 -1
  185. package/lib/types/equipment/item/Stationary.js +9 -2
  186. package/lib/types/equipment/item/ThievesTool.d.ts +2 -1
  187. package/lib/types/equipment/item/ThievesTool.js +9 -2
  188. package/lib/types/equipment/item/ToolOfTheTrade.d.ts +4 -3
  189. package/lib/types/equipment/item/ToolOfTheTrade.js +9 -2
  190. package/lib/types/equipment/item/TravelGearOrTool.d.ts +2 -1
  191. package/lib/types/equipment/item/TravelGearOrTool.js +9 -2
  192. package/lib/types/equipment/item/Vehicle.d.ts +3 -2
  193. package/lib/types/equipment/item/Vehicle.js +9 -2
  194. package/lib/types/equipment/item/Weapon.d.ts +2 -1
  195. package/lib/types/equipment/item/Weapon.js +9 -2
  196. package/lib/types/equipment/item/WeaponAccessory.d.ts +2 -1
  197. package/lib/types/equipment/item/WeaponAccessory.js +9 -2
  198. package/lib/types/equipment/item/_Herbary.js +2 -2
  199. package/lib/types/equipment/item/sub/ArmorType.d.ts +2 -1
  200. package/lib/types/equipment/item/sub/ArmorType.js +9 -2
  201. package/lib/types/equipment/item/sub/Reach.d.ts +2 -1
  202. package/lib/types/equipment/item/sub/Reach.js +9 -2
  203. package/lib/types/magicalActions/AnimistPower.d.ts +4 -3
  204. package/lib/types/magicalActions/AnimistPower.js +9 -2
  205. package/lib/types/magicalActions/AnimistPower_Tribe.d.ts +2 -1
  206. package/lib/types/magicalActions/AnimistPower_Tribe.js +9 -2
  207. package/lib/types/magicalActions/Curse.d.ts +4 -3
  208. package/lib/types/magicalActions/Curse.js +9 -2
  209. package/lib/types/magicalActions/DominationRitual.d.ts +4 -3
  210. package/lib/types/magicalActions/DominationRitual.js +9 -2
  211. package/lib/types/magicalActions/ElvenMagicalSong.d.ts +4 -3
  212. package/lib/types/magicalActions/ElvenMagicalSong.js +9 -2
  213. package/lib/types/magicalActions/GeodeRitual.d.ts +4 -3
  214. package/lib/types/magicalActions/GeodeRitual.js +9 -2
  215. package/lib/types/magicalActions/JesterTrick.d.ts +4 -3
  216. package/lib/types/magicalActions/JesterTrick.js +9 -2
  217. package/lib/types/magicalActions/MagicalDance.d.ts +4 -3
  218. package/lib/types/magicalActions/MagicalDance.js +9 -2
  219. package/lib/types/magicalActions/MagicalMelody.d.ts +4 -3
  220. package/lib/types/magicalActions/MagicalMelody.js +9 -2
  221. package/lib/types/magicalActions/MagicalRune.d.ts +4 -3
  222. package/lib/types/magicalActions/MagicalRune.js +9 -2
  223. package/lib/types/magicalActions/ZibiljaRitual.d.ts +4 -3
  224. package/lib/types/magicalActions/ZibiljaRitual.js +9 -2
  225. package/lib/types/magicalActions/_MusicTradition.js +2 -2
  226. package/lib/types/magicalActions/_SkillReference.js +1 -1
  227. package/lib/types/prerequisites/single/PrimaryAttributePrerequisite.js +1 -1
  228. package/lib/types/prerequisites/single/RatedMinimumNumberPrerequisite.js +1 -1
  229. package/lib/types/prerequisites/single/SexualCharacteristicPrerequisite.js +1 -1
  230. package/lib/types/prerequisites/single/TextPrerequisite.js +2 -2
  231. package/lib/types/prerequisites/single/TraditionPrerequisite.js +2 -2
  232. package/lib/types/rule/CoreRule.d.ts +4 -3
  233. package/lib/types/rule/CoreRule.js +10 -3
  234. package/lib/types/rule/FocusRule.d.ts +4 -3
  235. package/lib/types/rule/FocusRule.js +9 -2
  236. package/lib/types/rule/FocusRule_Subject.d.ts +2 -1
  237. package/lib/types/rule/FocusRule_Subject.js +9 -2
  238. package/lib/types/rule/OptionalRule.d.ts +4 -3
  239. package/lib/types/rule/OptionalRule.js +9 -2
  240. package/lib/types/source/Publication.d.ts +2 -1
  241. package/lib/types/source/Publication.js +10 -3
  242. package/lib/types/specialAbility/AdvancedCombatSpecialAbility.d.ts +4 -3
  243. package/lib/types/specialAbility/AdvancedCombatSpecialAbility.js +9 -2
  244. package/lib/types/specialAbility/AdvancedKarmaSpecialAbility.d.ts +4 -3
  245. package/lib/types/specialAbility/AdvancedKarmaSpecialAbility.js +9 -2
  246. package/lib/types/specialAbility/AdvancedMagicalSpecialAbility.d.ts +4 -3
  247. package/lib/types/specialAbility/AdvancedMagicalSpecialAbility.js +9 -2
  248. package/lib/types/specialAbility/AdvancedSkillSpecialAbility.d.ts +4 -3
  249. package/lib/types/specialAbility/AdvancedSkillSpecialAbility.js +9 -2
  250. package/lib/types/specialAbility/AncestorGlyph.d.ts +4 -3
  251. package/lib/types/specialAbility/AncestorGlyph.js +9 -2
  252. package/lib/types/specialAbility/BlessedTradition.d.ts +4 -3
  253. package/lib/types/specialAbility/BlessedTradition.js +9 -2
  254. package/lib/types/specialAbility/BrawlingSpecialAbility.d.ts +4 -3
  255. package/lib/types/specialAbility/BrawlingSpecialAbility.js +9 -2
  256. package/lib/types/specialAbility/CeremonialItemSpecialAbility.d.ts +2 -1
  257. package/lib/types/specialAbility/CeremonialItemSpecialAbility.js +9 -2
  258. package/lib/types/specialAbility/CombatSpecialAbility.d.ts +2 -1
  259. package/lib/types/specialAbility/CombatSpecialAbility.js +9 -2
  260. package/lib/types/specialAbility/CombatStyleSpecialAbility.d.ts +4 -3
  261. package/lib/types/specialAbility/CombatStyleSpecialAbility.js +9 -2
  262. package/lib/types/specialAbility/CommandSpecialAbility.d.ts +4 -3
  263. package/lib/types/specialAbility/CommandSpecialAbility.js +9 -2
  264. package/lib/types/specialAbility/FamiliarSpecialAbility.d.ts +4 -3
  265. package/lib/types/specialAbility/FamiliarSpecialAbility.js +9 -2
  266. package/lib/types/specialAbility/FatePointSexSpecialAbility.d.ts +4 -3
  267. package/lib/types/specialAbility/FatePointSexSpecialAbility.js +9 -2
  268. package/lib/types/specialAbility/FatePointSpecialAbility.d.ts +4 -3
  269. package/lib/types/specialAbility/FatePointSpecialAbility.js +9 -2
  270. package/lib/types/specialAbility/GeneralSpecialAbility.d.ts +2 -1
  271. package/lib/types/specialAbility/GeneralSpecialAbility.js +9 -2
  272. package/lib/types/specialAbility/KarmaSpecialAbility.d.ts +2 -1
  273. package/lib/types/specialAbility/KarmaSpecialAbility.js +9 -2
  274. package/lib/types/specialAbility/LiturgicalStyleSpecialAbility.d.ts +4 -3
  275. package/lib/types/specialAbility/LiturgicalStyleSpecialAbility.js +9 -2
  276. package/lib/types/specialAbility/LycantropicGift.d.ts +4 -3
  277. package/lib/types/specialAbility/LycantropicGift.js +9 -2
  278. package/lib/types/specialAbility/MagicStyleSpecialAbility.d.ts +4 -3
  279. package/lib/types/specialAbility/MagicStyleSpecialAbility.js +9 -2
  280. package/lib/types/specialAbility/MagicalSign.d.ts +4 -3
  281. package/lib/types/specialAbility/MagicalSign.js +9 -2
  282. package/lib/types/specialAbility/MagicalSpecialAbility.d.ts +2 -1
  283. package/lib/types/specialAbility/MagicalSpecialAbility.js +9 -2
  284. package/lib/types/specialAbility/MagicalTradition.d.ts +4 -3
  285. package/lib/types/specialAbility/MagicalTradition.js +9 -2
  286. package/lib/types/specialAbility/PactGift.d.ts +4 -3
  287. package/lib/types/specialAbility/PactGift.js +11 -4
  288. package/lib/types/specialAbility/ProtectiveWardingCircleSpecialAbility.d.ts +4 -3
  289. package/lib/types/specialAbility/ProtectiveWardingCircleSpecialAbility.js +9 -2
  290. package/lib/types/specialAbility/Sermon.d.ts +4 -3
  291. package/lib/types/specialAbility/Sermon.js +9 -2
  292. package/lib/types/specialAbility/SexSpecialAbility.d.ts +4 -3
  293. package/lib/types/specialAbility/SexSpecialAbility.js +9 -2
  294. package/lib/types/specialAbility/SikaryanDrainSpecialAbility.d.ts +4 -3
  295. package/lib/types/specialAbility/SikaryanDrainSpecialAbility.js +9 -2
  296. package/lib/types/specialAbility/SkillStyleSpecialAbility.d.ts +4 -3
  297. package/lib/types/specialAbility/SkillStyleSpecialAbility.js +9 -2
  298. package/lib/types/specialAbility/VampiricGift.d.ts +2 -1
  299. package/lib/types/specialAbility/VampiricGift.js +9 -2
  300. package/lib/types/specialAbility/Vision.d.ts +4 -3
  301. package/lib/types/specialAbility/Vision.js +9 -2
  302. package/lib/types/specialAbility/sub/Language.d.ts +4 -3
  303. package/lib/types/specialAbility/sub/Language.js +9 -2
  304. package/lib/types/specialAbility/sub/Script.d.ts +4 -3
  305. package/lib/types/specialAbility/sub/Script.js +9 -2
  306. package/lib/types/specialAbility/sub/TradeSecret.d.ts +4 -3
  307. package/lib/types/specialAbility/sub/TradeSecret.js +9 -2
  308. package/lib/types/traditionArtifacts/ArcaneOrbEnchantment.d.ts +2 -1
  309. package/lib/types/traditionArtifacts/ArcaneOrbEnchantment.js +9 -2
  310. package/lib/types/traditionArtifacts/AttireEnchantment.d.ts +2 -1
  311. package/lib/types/traditionArtifacts/AttireEnchantment.js +9 -2
  312. package/lib/types/traditionArtifacts/BowlEnchantment.d.ts +2 -1
  313. package/lib/types/traditionArtifacts/BowlEnchantment.js +9 -2
  314. package/lib/types/traditionArtifacts/CauldronEnchantment.d.ts +2 -1
  315. package/lib/types/traditionArtifacts/CauldronEnchantment.js +9 -2
  316. package/lib/types/traditionArtifacts/ChronicleEnchantment.d.ts +2 -1
  317. package/lib/types/traditionArtifacts/ChronicleEnchantment.js +9 -2
  318. package/lib/types/traditionArtifacts/DaggerRitual.d.ts +2 -1
  319. package/lib/types/traditionArtifacts/DaggerRitual.js +9 -2
  320. package/lib/types/traditionArtifacts/FoolsHatEnchantment.d.ts +2 -1
  321. package/lib/types/traditionArtifacts/FoolsHatEnchantment.js +9 -2
  322. package/lib/types/traditionArtifacts/InstrumentEnchantment.d.ts +2 -1
  323. package/lib/types/traditionArtifacts/InstrumentEnchantment.js +9 -2
  324. package/lib/types/traditionArtifacts/Krallenkettenzauber.d.ts +2 -1
  325. package/lib/types/traditionArtifacts/Krallenkettenzauber.js +9 -2
  326. package/lib/types/traditionArtifacts/OrbEnchantment.d.ts +2 -1
  327. package/lib/types/traditionArtifacts/OrbEnchantment.js +9 -2
  328. package/lib/types/traditionArtifacts/RingEnchantment.d.ts +2 -1
  329. package/lib/types/traditionArtifacts/RingEnchantment.js +9 -2
  330. package/lib/types/traditionArtifacts/SickleRitual.d.ts +2 -1
  331. package/lib/types/traditionArtifacts/SickleRitual.js +9 -2
  332. package/lib/types/traditionArtifacts/SpellSwordEnchantment.d.ts +2 -1
  333. package/lib/types/traditionArtifacts/SpellSwordEnchantment.js +9 -2
  334. package/lib/types/traditionArtifacts/StaffEnchantment.d.ts +2 -1
  335. package/lib/types/traditionArtifacts/StaffEnchantment.js +9 -2
  336. package/lib/types/traditionArtifacts/ToyEnchantment.d.ts +2 -1
  337. package/lib/types/traditionArtifacts/ToyEnchantment.js +9 -2
  338. package/lib/types/traditionArtifacts/Trinkhornzauber.d.ts +2 -1
  339. package/lib/types/traditionArtifacts/Trinkhornzauber.js +9 -2
  340. package/lib/types/traditionArtifacts/WandEnchantment.d.ts +2 -1
  341. package/lib/types/traditionArtifacts/WandEnchantment.js +9 -2
  342. package/lib/types/traditionArtifacts/WeaponEnchantment.d.ts +2 -1
  343. package/lib/types/traditionArtifacts/WeaponEnchantment.js +9 -2
  344. package/lib/types/traditionArtifacts/sub/AnimalShape.d.ts +2 -1
  345. package/lib/types/traditionArtifacts/sub/AnimalShape.js +9 -2
  346. package/lib/types/traditionArtifacts/sub/AnimalShapePath.d.ts +2 -1
  347. package/lib/types/traditionArtifacts/sub/AnimalShapePath.js +9 -2
  348. package/lib/types/traditionArtifacts/sub/AnimalShapeSize.d.ts +2 -1
  349. package/lib/types/traditionArtifacts/sub/AnimalShapeSize.js +9 -2
  350. package/lib/types/traditionArtifacts/sub/Brew.d.ts +2 -1
  351. package/lib/types/traditionArtifacts/sub/Brew.js +9 -2
  352. package/lib/validation/builders/integrity.d.ts +57 -0
  353. package/lib/validation/builders/integrity.js +44 -0
  354. package/lib/validation/builders/naming.d.ts +13 -0
  355. package/lib/validation/builders/naming.js +14 -0
  356. package/lib/validation/builders/schema.d.ts +31 -0
  357. package/lib/validation/builders/schema.js +32 -0
  358. package/lib/validation/filename.d.ts +9 -0
  359. package/lib/validation/filename.js +10 -0
  360. package/lib/validation/raw.d.ts +9 -0
  361. package/lib/validation/raw.js +55 -0
  362. package/lib/validation/schema.d.ts +6 -22
  363. package/lib/validation/schema.js +31 -32
  364. package/package.json +8 -3
  365. package/schema/Locale.schema.json +1 -8
  366. package/config/directories.d.ts +0 -4
  367. package/lib/validation/integrity.d.ts +0 -16
  368. package/lib/validation/integrity.js +0 -3
package/lib/errors.js ADDED
@@ -0,0 +1,33 @@
1
+ import { filterNullable } from "./helpers/array.js";
2
+ import { collator } from "./helpers/i18n.js";
3
+ /**
4
+ * Pretty-prints an error map.
5
+ * @param errorsByFile A map from file paths to the errors that occurred in
6
+ * them.
7
+ * @param printOptions Configuration options for the printer.
8
+ * @returns The pretty-printed error map.
9
+ */
10
+ export const printErrors = (errorsByFile, printOptions = {}) => {
11
+ const { verbose = false } = printOptions;
12
+ return Object.entries(errorsByFile)
13
+ .sort(([filePathA], [filePathB]) => collator.compare(filePathA, filePathB))
14
+ .flatMap(verbose
15
+ ? ([filePath, errors]) => filterNullable(errors.map(printVerboseError(filePath)))
16
+ : ([filePath, errors]) => [
17
+ ...(errors
18
+ .filter((error) => error.keyword === "integrity" || error.keyword === "filename")
19
+ .map(printVerboseError(filePath))),
20
+ ...(errors.some(error => error.keyword !== "integrity" && error.keyword !== "filename")
21
+ ? [errorMessageBlock([filePath], "has schema errors")]
22
+ : []),
23
+ ])
24
+ .join("\n\n");
25
+ };
26
+ const printVerboseError = (filePath) => (error) => {
27
+ const pathSegments = [filePath, ...error.instancePath.split("/").slice(1)];
28
+ return errorMessageBlock(pathSegments, error.message ?? "");
29
+ };
30
+ const errorMessageBlock = (path, message) => [
31
+ ...path.map((segment, i) => `${" ".repeat(i * 2)}in "${segment}":`),
32
+ `${" ".repeat(path.length * 2)}${message}`
33
+ ].join("\n");
@@ -0,0 +1,14 @@
1
+ declare global {
2
+ interface Array<T> {
3
+ /**
4
+ * Returns a `Promise` that resolves when all `Promise`s in the array
5
+ * resolve and rejects when any of the `Promise`s in the array rejects.
6
+ */
7
+ promiseAll<T>(this: Promise<T>[]): Promise<T[]>;
8
+ /**
9
+ * Returns an object from an array of key-value pairs.
10
+ */
11
+ objectFromEntries<K extends string, T>(this: [key: K, value: T][]): Record<K, T>;
12
+ }
13
+ }
14
+ export declare const filterNullable: <T>(arr: T[]) => NonNullable<T>[];
@@ -0,0 +1,15 @@
1
+ Object.defineProperty(Array.prototype, "promiseAll", {
2
+ configurable: true,
3
+ writable: true,
4
+ value: function promiseAll() {
5
+ return Promise.all(this);
6
+ }
7
+ });
8
+ Object.defineProperty(Array.prototype, "objectFromEntries", {
9
+ configurable: true,
10
+ writable: true,
11
+ value: function objectFromEntries() {
12
+ return Object.fromEntries(this);
13
+ }
14
+ });
15
+ export const filterNullable = (arr) => arr.filter((x) => x != null);
@@ -0,0 +1 @@
1
+ export declare const collator: Intl.Collator;
@@ -0,0 +1 @@
1
+ export const collator = Intl.Collator(undefined, { numeric: true });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Recursively reads all files in a directory and its subdirectories.
3
+ * @param dirPath The path to the directory to read.
4
+ */
5
+ export declare function readDirectoryRec(dirPath: string, filterName?: (entryName: string) => boolean): AsyncGenerator<string>;
6
+ /**
7
+ * Reads a JSON file and parses its content.
8
+ * @param filePath The path to the JSON file.
9
+ * @returns The parsed JSON content.
10
+ */
11
+ export declare const readJsonFile: (filePath: string) => Promise<unknown>;
12
+ /**
13
+ * Reads a YAML file and parses its content.
14
+ * @param filePath The path to the YAML file.
15
+ * @returns The parsed YAML content.
16
+ */
17
+ export declare const readYamlFile: (filePath: string) => Promise<unknown>;
18
+ /**
19
+ * Changes the extension of a file path.
20
+ * @param path The path to the file.
21
+ * @param ext The new extension to use.
22
+ * @returns
23
+ */
24
+ export declare const changeFileExtension: (path: string, ext: string) => string;
25
+ /**
26
+ * Checks if a file name represents a hidden file.
27
+ * @param name The file name to check.
28
+ */
29
+ export declare const isHiddenFileName: (name: string) => boolean;
@@ -0,0 +1,51 @@
1
+ import { readFile, readdir } from "fs/promises";
2
+ import { basename, dirname, extname, join } from "path";
3
+ import YAML from "yaml";
4
+ /**
5
+ * Recursively reads all files in a directory and its subdirectories.
6
+ * @param dirPath The path to the directory to read.
7
+ */
8
+ export async function* readDirectoryRec(dirPath, filterName = () => true) {
9
+ const dirEntries = await readdir(dirPath, { withFileTypes: true });
10
+ for (const dirEntry of dirEntries) {
11
+ if (filterName(dirEntry.name)) {
12
+ const dirEntryPath = join(dirPath, dirEntry.name);
13
+ if (dirEntry.isDirectory()) {
14
+ yield* readDirectoryRec(dirEntryPath);
15
+ }
16
+ else {
17
+ yield dirEntryPath;
18
+ }
19
+ }
20
+ }
21
+ }
22
+ /**
23
+ * Reads a JSON file and parses its content.
24
+ * @param filePath The path to the JSON file.
25
+ * @returns The parsed JSON content.
26
+ */
27
+ export const readJsonFile = async (filePath) => {
28
+ const fileContent = await readFile(filePath, "utf-8");
29
+ return JSON.parse(fileContent);
30
+ };
31
+ /**
32
+ * Reads a YAML file and parses its content.
33
+ * @param filePath The path to the YAML file.
34
+ * @returns The parsed YAML content.
35
+ */
36
+ export const readYamlFile = async (filePath) => {
37
+ const fileContent = await readFile(filePath, "utf-8");
38
+ return YAML.parse(fileContent);
39
+ };
40
+ /**
41
+ * Changes the extension of a file path.
42
+ * @param path The path to the file.
43
+ * @param ext The new extension to use.
44
+ * @returns
45
+ */
46
+ export const changeFileExtension = (path, ext) => join(dirname(path), basename(path, extname(path)) + ext);
47
+ /**
48
+ * Checks if a file name represents a hidden file.
49
+ * @param name The file name to check.
50
+ */
51
+ export const isHiddenFileName = (name) => !name.startsWith(".");
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A path segment descriptor is either a key or an index.
3
+ */
4
+ export type PathSegmentDescriptor = {
5
+ k: string;
6
+ } | {
7
+ i: number;
8
+ };
9
+ /**
10
+ * A path descriptor is a list of path segment descriptors.
11
+ */
12
+ export type PathDescriptor = PathSegmentDescriptor[];
13
+ export declare const printPathDescriptor: (pathDescriptor: PathDescriptor) => string;
@@ -0,0 +1,3 @@
1
+ export const printPathDescriptor = (pathDescriptor) => pathDescriptor
2
+ .map(segment => "k" in segment ? segment.k : segment.i)
3
+ .join("/");
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Map the second element of a pair using a function that receives both
3
+ * elements.
4
+ */
5
+ export declare const mapSecond: <A, B, C>(f: (second: B, first: A) => C) => (pair: [A, B]) => [A, C];
6
+ /**
7
+ * Map the second element of a pair using a function that receives both
8
+ * elements and returns a `Promise`.
9
+ */
10
+ export declare const mapSecondAsync: <A, B, C>(f: (second: B, first: A) => Promise<C>) => (pair: [A, B]) => Promise<[A, C]>;
11
+ /**
12
+ * Map a value using a function into the second value of a pair with the
13
+ * original value.
14
+ */
15
+ export declare const mapToSecond: <A, B>(f: (value: A) => B) => (value: A) => [A, B];
16
+ /**
17
+ * Map a value using a function that returns a `Promise` into the second value
18
+ * of a pair with the original value.
19
+ */
20
+ export declare const mapToSecondAsync: <A, B>(f: (value: A) => Promise<B>) => (value: A) => Promise<[A, B]>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Map the second element of a pair using a function that receives both
3
+ * elements.
4
+ */
5
+ export const mapSecond = (f) => (pair) => [pair[0], f(pair[1], pair[0])];
6
+ /**
7
+ * Map the second element of a pair using a function that receives both
8
+ * elements and returns a `Promise`.
9
+ */
10
+ export const mapSecondAsync = (f) => async (pair) => [pair[0], await f(pair[1], pair[0])];
11
+ /**
12
+ * Map a value using a function into the second value of a pair with the
13
+ * original value.
14
+ */
15
+ export const mapToSecond = (f) => (value) => [value, f(value)];
16
+ /**
17
+ * Map a value using a function that returns a `Promise` into the second value
18
+ * of a pair with the original value.
19
+ */
20
+ export const mapToSecondAsync = (f) => async (value) => [value, await f(value)];
@@ -0,0 +1,57 @@
1
+ /**
2
+ * A result is either a value or an error.
3
+ */
4
+ export type Result<T, E> = Ok<T> | Error<E>;
5
+ /**
6
+ * A result that contains a value.
7
+ */
8
+ export type Ok<T> = {
9
+ readonly tag: "Ok";
10
+ readonly value: T;
11
+ };
12
+ /**
13
+ * A result that contains an error.
14
+ */
15
+ export type Error<E> = {
16
+ readonly tag: "Error";
17
+ readonly error: E;
18
+ };
19
+ /**
20
+ * Creates a result that contains a value.
21
+ */
22
+ export declare const ok: <T>(value: T) => Result<T, never>;
23
+ /**
24
+ * Checks if a result contains a value.
25
+ */
26
+ export declare const isOk: <T, E>(result: Result<T, E>) => result is Ok<T>;
27
+ /**
28
+ * Creates a result that contains an error.
29
+ */
30
+ export declare const error: <E>(error: E) => Result<never, E>;
31
+ /**
32
+ * Checks if a result contains an error.
33
+ */
34
+ export declare const isError: <T, E>(result: Result<T, E>) => result is Error<E>;
35
+ /**
36
+ * Reduces a result to a value of a common type.
37
+ */
38
+ export declare const reduce: <T, E, R>(result: Result<T, E>, fok: (value: T) => R, ferror: (error: E) => R) => R;
39
+ /**
40
+ * Maps the value of a result to a new value.
41
+ */
42
+ export declare const map: <T, U, E>(result: Result<T, E>, f: (value: T) => U) => Result<U, E>;
43
+ /**
44
+ * Maps an error to a new error.
45
+ */
46
+ export declare const mapError: <T, E, F>(result: Result<T, E>, f: (value: E) => F) => Result<T, F>;
47
+ export declare const combine: <T1, T2, TR, E1, E2, ER>(result1: Result<T1, E1>, result2: Result<T2, E2>, fok: (value1: T1, value2: T2) => TR, ferror: (error1: E1, error2: E2) => ER) => Result<TR, E1 | E2 | ER>;
48
+ export declare const Result: Readonly<{
49
+ ok: <T>(value: T) => Result<T, never>;
50
+ isOk: <T_1, E>(result: Result<T_1, E>) => result is Ok<T_1>;
51
+ error: <E_1>(error: E_1) => Result<never, E_1>;
52
+ isError: <T_2, E_2>(result: Result<T_2, E_2>) => result is Error<E_2>;
53
+ reduce: <T_3, E_3, R>(result: Result<T_3, E_3>, fok: (value: T_3) => R, ferror: (error: E_3) => R) => R;
54
+ map: <T_4, U, E_4>(result: Result<T_4, E_4>, f: (value: T_4) => U) => Result<U, E_4>;
55
+ mapError: <T_5, E_5, F>(result: Result<T_5, E_5>, f: (value: E_5) => F) => Result<T_5, F>;
56
+ combine: <T1, T2, TR, E1, E2, ER>(result1: Result<T1, E1>, result2: Result<T2, E2>, fok: (value1: T1, value2: T2) => TR, ferror: (error1: E1, error2: E2) => ER) => Result<TR, E1 | E2 | ER>;
57
+ }>;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Creates a result that contains a value.
3
+ */
4
+ export const ok = (value) => ({ tag: "Ok", value });
5
+ /**
6
+ * Checks if a result contains a value.
7
+ */
8
+ export const isOk = (result) => result.tag === "Ok";
9
+ /**
10
+ * Creates a result that contains an error.
11
+ */
12
+ export const error = (error) => ({ tag: "Error", error });
13
+ /**
14
+ * Checks if a result contains an error.
15
+ */
16
+ export const isError = (result) => result.tag === "Error";
17
+ /**
18
+ * Reduces a result to a value of a common type.
19
+ */
20
+ export const reduce = (result, fok, ferror) => isOk(result) ? fok(result.value) : ferror(result.error);
21
+ /**
22
+ * Maps the value of a result to a new value.
23
+ */
24
+ export const map = (result, f) => isOk(result) ? ok(f(result.value)) : result;
25
+ /**
26
+ * Maps an error to a new error.
27
+ */
28
+ export const mapError = (result, f) => isError(result) ? error(f(result.error)) : result;
29
+ export const combine = (result1, result2, fok, ferror) => isOk(result1)
30
+ ? isOk(result2)
31
+ ? ok(fok(result1.value, result2.value))
32
+ : result2
33
+ : isOk(result2)
34
+ ? result1
35
+ : error(ferror(result1.error, result2.error));
36
+ export const Result = Object.freeze({
37
+ ok,
38
+ isOk,
39
+ error,
40
+ isError,
41
+ reduce,
42
+ map,
43
+ mapError,
44
+ combine,
45
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This function is used to make sure that the `switch` is exhaustive. Place it
3
+ * in the `default` case of the `switch`.
4
+ * @param x The value that is used in the `switch`.
5
+ */
6
+ export declare function assertExhaustive(x: never): never;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This function is used to make sure that the `switch` is exhaustive. Place it
3
+ * in the `default` case of the `switch`.
4
+ * @param x The value that is used in the `switch`.
5
+ */
6
+ export function assertExhaustive(x) {
7
+ throw new Error("The switch is not exhaustive.");
8
+ }
package/lib/main.d.ts CHANGED
@@ -1,20 +1,55 @@
1
1
  import { TypeMap } from "./config.js";
2
- import { TypeValidationResultErrors } from "./validation/schema.js";
3
- type Result = {
4
- tag: "Ok";
5
- value: {
6
- [K in keyof TypeMap]: TypeMap[K][];
7
- };
8
- } | {
9
- tag: "Error";
10
- errors: Record<string, TypeValidationResultErrors>;
2
+ import "./helpers/array.js";
3
+ import { Result } from "./helpers/result.js";
4
+ import { TypeId } from "./typeConfig.js";
5
+ import { IntegrityError } from "./validation/builders/integrity.js";
6
+ import { FileNameError } from "./validation/builders/naming.js";
7
+ import { SchemaError } from "./validation/builders/schema.js";
8
+ /**
9
+ * Options for validating data files.
10
+ */
11
+ export type ValidationOptions = {
12
+ /**
13
+ * Whether to check the integrity of the data files. This includes checking
14
+ * for referencial integrity (i.e. whether all referenced entities exist).
15
+ * @default false
16
+ */
17
+ checkIntegrity?: boolean;
11
18
  };
19
+ /**
20
+ * A type validation may fail because of the data not matching the schema, the
21
+ * file name not matching a pattern, or integrity issues.
22
+ */
23
+ export type TypeValidationError = IntegrityError | FileNameError | SchemaError;
24
+ /**
25
+ * A map of all valid entries, grouped by entity type.
26
+ */
27
+ export type ValidResults = {
28
+ [K in keyof TypeMap]: [id: TypeId<keyof TypeMap>, data: TypeMap[keyof TypeMap]][];
29
+ };
30
+ /**
31
+ * A dictionary of entity types and their data’s associated locations.
32
+ */
12
33
  export type EntityDirectoryPaths = {
13
34
  [K in keyof TypeMap]: string;
14
35
  };
15
- export declare const validate: (entityDirPaths: EntityDirectoryPaths, checkIntegrity: boolean) => Promise<Result>;
16
- export declare const printErrors: (errorsByFile: Record<string, TypeValidationResultErrors>, printOptions?: PrintOptions) => string;
17
- export type PrintOptions = {
18
- verbose?: boolean;
19
- };
36
+ type StrictResults = Result<ValidResults, Record<string, TypeValidationError[]>>;
37
+ /**
38
+ * If the database has no validation issues, returns the whole data set as a map
39
+ * of entity types to their data. If there are any errors, only the errors will
40
+ * be returned instead.
41
+ * @param entityDirPaths THe paths to the directories containing the data to be
42
+ * validated.
43
+ * @param options Configuration options for the validation.
44
+ * @returns Either the whole data set or the errors.
45
+ */
46
+ export declare const getAllValidDataOrErrors: (entityDirPaths: EntityDirectoryPaths, options?: ValidationOptions) => Promise<StrictResults>;
47
+ /**
48
+ * Returns all valid data as a map of entity types to their data.
49
+ * @param entityDirPaths THe paths to the directories containing the data to be
50
+ * validated.
51
+ * @param options Configuration options for the validation.
52
+ * @returns The valid data.
53
+ */
54
+ export declare const getAllValidData: (entityDirPaths: EntityDirectoryPaths, options?: ValidationOptions) => Promise<ValidResults>;
20
55
  export {};
package/lib/main.js CHANGED
@@ -1,142 +1,55 @@
1
- import addFormats from "ajv-formats";
2
- import Ajv2019 from "ajv/dist/2019.js";
3
- import Ajv2020 from "ajv/dist/2020.js";
4
- import { lstat, readdir, readFile } from "fs/promises";
5
- import { join } from "path";
6
- import YAML from "yaml";
7
- import { jsonSchemaDir } from "../config/directories.js";
8
- import { typeValidatorMap } from "./config.js";
9
- const readdirRecursive = async (dirPath) => {
10
- const directoryEntries = await readdir(dirPath, { withFileTypes: true });
11
- const flattenedRecursivePaths = await Promise.all(directoryEntries
12
- .filter(dirEntry => !dirEntry.name.startsWith("."))
13
- .map(async (dirEntry) => {
14
- const absoluteEntryPath = join(dirPath, dirEntry.name);
15
- if (dirEntry.isDirectory()) {
16
- return (await readdirRecursive(absoluteEntryPath));
17
- }
18
- else if (dirEntry.isFile()) {
19
- return [absoluteEntryPath];
20
- }
21
- else {
22
- return [];
23
- }
24
- }));
25
- return flattenedRecursivePaths.flat();
26
- };
27
- const registerAllJsonSchemaDocuments = async (validatorOptions) => {
28
- const readFileAsUtf8 = (path) => readFile(path, "utf-8");
29
- const readFilesAsUtf8 = (paths) => Promise.all(paths.map(readFileAsUtf8));
30
- const parseJson = (json) => JSON.parse(json);
31
- const schemes = (await readFilesAsUtf8(await readdirRecursive(jsonSchemaDir))).map(parseJson);
32
- const META_SCHEMA_ID_2020_12 = "https://json-schema.org/draft/2020-12/schema";
33
- const validator = schemes[0]?.$schema === META_SCHEMA_ID_2020_12
34
- ? new Ajv2020(validatorOptions)
35
- : new Ajv2019(validatorOptions);
36
- const registerSchemaInValidator = (jsonSchema) => { validator.addSchema(jsonSchema); };
37
- schemes.forEach(registerSchemaInValidator);
38
- return validator;
39
- };
40
- const collator = Intl.Collator(undefined, { numeric: true });
41
- const readDataFileAssocsFromDirectory = async (dirPath) => {
42
- const filenames = await readdir(dirPath);
43
- filenames.sort(collator.compare);
44
- return await Promise.all(filenames
45
- .filter(fileName => !fileName.startsWith("."))
46
- .map(async (fileName) => {
47
- const filePath = join(dirPath, fileName);
48
- try {
49
- const fileContent = YAML.parse(await readFile(join(dirPath, fileName), "utf-8"));
50
- return [filePath, fileContent];
51
- }
52
- catch (error) {
53
- if (error instanceof Error) {
54
- error.message = `in "${filePath}":\n ${error.message}`;
55
- }
56
- return [filePath, null];
57
- }
58
- }));
59
- };
60
- const validateAllFromType = async (validator, typeName, path) => {
61
- const isFile = (await lstat(path)).isFile();
62
- const typeValidator = typeValidatorMap[typeName];
63
- if (isFile) {
64
- return { [path]: typeValidator(validator, await readFile(path, "utf-8"), path) };
65
- }
66
- else {
67
- const dataFiles = await readDataFileAssocsFromDirectory(path);
68
- return Object.fromEntries(dataFiles.map(([filePath, fileContent]) => [filePath, typeValidator(validator, fileContent, filePath)]));
69
- }
70
- };
71
- const rawResultMapToResult = (rawResultMap) => Object.entries(rawResultMap).reduce((result, [typeName, typeResults]) => Object.entries(typeResults).reduce((outerResult, [filePath, fileResult]) => {
72
- if (outerResult.tag === "Ok" && fileResult.tag === "Ok") {
73
- return {
74
- tag: "Ok",
75
- value: {
76
- ...outerResult.value,
77
- [typeName]: [...(outerResult.value[typeName] ?? []), fileResult.value]
78
- }
79
- };
1
+ import "./helpers/array.js";
2
+ import { mapSecond } from "./helpers/pair.js";
3
+ import { Result, error, isError, isOk, ok } from "./helpers/result.js";
4
+ import { getRawValidationResults } from "./validation/raw.js";
5
+ const rawResultMapToResult = (rawResultMap) => rawResultMap.reduce((result, [typeName, typeResults]) => typeResults.reduce((outerResult, [filePath, fileResult]) => {
6
+ if (isOk(outerResult) && isOk(fileResult)) {
7
+ return ok({
8
+ ...outerResult.value,
9
+ [typeName]: [...(outerResult.value[typeName] ?? []), fileResult.value]
10
+ });
80
11
  }
81
- else if (outerResult.tag === "Ok" && fileResult.tag === "Error") {
82
- return {
83
- tag: "Error",
84
- errors: {
85
- [filePath]: fileResult.errors
86
- }
87
- };
12
+ else if (isOk(outerResult) && isError(fileResult)) {
13
+ return error({
14
+ [filePath]: fileResult.error
15
+ });
88
16
  }
89
- else if (outerResult.tag === "Error" && fileResult.tag === "Error") {
90
- return {
91
- tag: "Error",
92
- errors: {
93
- ...outerResult.errors,
94
- [filePath]: fileResult.errors
95
- }
96
- };
17
+ else if (isError(outerResult) && isError(fileResult)) {
18
+ return error({
19
+ ...outerResult.error,
20
+ [filePath]: fileResult.error
21
+ });
97
22
  }
98
23
  else {
99
24
  return outerResult;
100
25
  }
101
- }, result), ({
102
- tag: "Ok",
103
- value: {}
104
- }));
105
- export const validate = async (entityDirPaths, checkIntegrity) => {
106
- const validator = await registerAllJsonSchemaDocuments({});
107
- addFormats(validator);
108
- const rawResultMap = Object.fromEntries((await Promise.all(Object.entries(entityDirPaths)
109
- .map(async ([typeName, path]) => [
110
- typeName,
111
- await validateAllFromType(validator, typeName, path)
112
- ]))));
26
+ }, result), ok({}));
27
+ const filterResultMapByValidData = (rawResultMap) => rawResultMap
28
+ .map(mapSecond((typeResults) => typeResults
29
+ .filter((typeResult) => Result.isOk(typeResult[1]))
30
+ .map(fileResult => fileResult[1].value)))
31
+ .objectFromEntries();
32
+ /**
33
+ * If the database has no validation issues, returns the whole data set as a map
34
+ * of entity types to their data. If there are any errors, only the errors will
35
+ * be returned instead.
36
+ * @param entityDirPaths THe paths to the directories containing the data to be
37
+ * validated.
38
+ * @param options Configuration options for the validation.
39
+ * @returns Either the whole data set or the errors.
40
+ */
41
+ export const getAllValidDataOrErrors = async (entityDirPaths, options = {}) => {
42
+ const rawResultMap = await getRawValidationResults(entityDirPaths, options);
113
43
  return rawResultMapToResult(rawResultMap);
114
44
  };
115
- export const printErrors = (errorsByFile, printOptions = {}) => {
116
- const { verbose = false } = printOptions;
117
- return Object.entries(errorsByFile)
118
- .sort(([filePathA], [filePathB]) => collator.compare(filePathA, filePathB))
119
- .flatMap(([filePath, errors]) => {
120
- if (verbose) {
121
- return filterNullable([
122
- errors.fileNameError ? errorMessageBlock([filePath], errors.fileNameError.message) : undefined,
123
- ...errors.schemaErrors.map(error => {
124
- const pathSegments = [filePath, ...error.instancePath.split("/").slice(1)];
125
- return errorMessageBlock(pathSegments, error.message ?? "");
126
- })
127
- ]);
128
- }
129
- else {
130
- return filterNullable([
131
- errors.fileNameError ? errorMessageBlock([filePath], errors.fileNameError.message) : undefined,
132
- errors.schemaErrors.length > 0 ? errorMessageBlock([filePath], "does not match schema") : undefined
133
- ]);
134
- }
135
- })
136
- .join("\n\n");
45
+ /**
46
+ * Returns all valid data as a map of entity types to their data.
47
+ * @param entityDirPaths THe paths to the directories containing the data to be
48
+ * validated.
49
+ * @param options Configuration options for the validation.
50
+ * @returns The valid data.
51
+ */
52
+ export const getAllValidData = async (entityDirPaths, options = {}) => {
53
+ const rawResultMap = await getRawValidationResults(entityDirPaths, options);
54
+ return filterResultMapByValidData(rawResultMap);
137
55
  };
138
- const errorMessageBlock = (path, message) => [
139
- ...path.map((segment, i) => `${" ".repeat(i * 2)}in "${segment}":`),
140
- `${" ".repeat(path.length * 2)}${message}`
141
- ].join("\n");
142
- const filterNullable = (arr) => arr.filter((x) => x != null);
@@ -0,0 +1,10 @@
1
+ import { TypeMap, configMap } from "./config.js";
2
+ import { IntegrityValidator } from "./validation/builders/integrity.js";
3
+ import { SchemaValidator } from "./validation/builders/schema.js";
4
+ export type TypeId<K extends keyof TypeMap> = ReturnType<(typeof configMap)[K]["id"]>;
5
+ export type TypeConfig<T, ID extends string | number = number> = {
6
+ name: string;
7
+ id: (data: T, filepath: string) => ID;
8
+ integrityValidator: IntegrityValidator<T>;
9
+ schemaValidator: SchemaValidator<T>;
10
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @main Advantage
3
3
  */
4
+ import { TypeConfig } from "../typeConfig.js";
4
5
  import * as Activatable from "./_Activatable.js";
5
6
  import { LocaleMap } from "./_LocaleMap.js";
6
7
  import { AdvantageDisadvantagePrerequisites } from "./_Prerequisite.js";
@@ -59,4 +60,4 @@ export type AdvantageTranslation = {
59
60
  ap_value_append?: Activatable.AdventurePointsValueAppend;
60
61
  errata?: Errata;
61
62
  };
62
- export declare const validateSchema: import("../validation/schema.js").TypeValidator<Advantage>;
63
+ export declare const config: TypeConfig<Advantage>;
@@ -1,5 +1,12 @@
1
1
  /**
2
2
  * @main Advantage
3
3
  */
4
- import { validateSchemaCreator } from "../validation/schema.js";
5
- export const validateSchema = validateSchemaCreator(import.meta.url);
4
+ import { todo } from "../validation/builders/integrity.js";
5
+ import { createSchemaValidator } from "../validation/builders/schema.js";
6
+ import { getFIlenamePrefixAsNumericId } from "../validation/filename.js";
7
+ export const config = {
8
+ name: "Advantage",
9
+ id: getFIlenamePrefixAsNumericId,
10
+ integrityValidator: todo("Advantage"),
11
+ schemaValidator: createSchemaValidator(import.meta.url),
12
+ };