5etools-utils 0.2.2 → 0.3.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 (312) hide show
  1. package/lib/Api.js +1 -1
  2. package/lib/TestJson.js +43 -19
  3. package/lib/UtilMisc.js +36 -17
  4. package/package.json +6 -3
  5. package/schema/brew/actions.json +109 -0
  6. package/schema/brew/adventure/adventure.json +12 -0
  7. package/schema/brew/adventures.json +249 -0
  8. package/schema/brew/backgrounds.json +425 -0
  9. package/schema/brew/bestiary/bestiary.json +3766 -0
  10. package/schema/brew/bestiary/fluff-bestiary.json +15 -0
  11. package/schema/brew/bestiary/fluff-index.json +11 -0
  12. package/schema/brew/bestiary/foundry.json +15 -0
  13. package/schema/brew/bestiary/index.json +11 -0
  14. package/schema/brew/bestiary/legendarygroups.json +202 -0
  15. package/schema/brew/bestiary/traits.json +85 -0
  16. package/schema/brew/book/book.json +12 -0
  17. package/schema/brew/books.json +137 -0
  18. package/schema/brew/changelog.json +35 -0
  19. package/schema/brew/charcreationoptions.json +96 -0
  20. package/schema/brew/class/class.json +2059 -0
  21. package/schema/brew/class/foundry.json +373 -0
  22. package/schema/brew/class/index.json +11 -0
  23. package/schema/brew/conditionsdiseases.json +103 -0
  24. package/schema/brew/cultsboons.json +196 -0
  25. package/schema/brew/deities.json +482 -0
  26. package/schema/brew/encounters.json +99 -0
  27. package/schema/brew/entry.json +3538 -0
  28. package/schema/brew/feats.json +215 -0
  29. package/schema/brew/fluff-backgrounds.json +15 -0
  30. package/schema/brew/fluff-charcreationoptions.json +43 -0
  31. package/schema/brew/fluff-conditionsdiseases.json +43 -0
  32. package/schema/brew/fluff-feats.json +15 -0
  33. package/schema/brew/fluff-items.json +15 -0
  34. package/schema/brew/fluff-languages.json +42 -0
  35. package/schema/brew/fluff-objects.json +15 -0
  36. package/schema/brew/fluff-races.json +214 -0
  37. package/schema/brew/fluff-recipes.json +42 -0
  38. package/schema/brew/fluff-vehicles.json +63 -0
  39. package/schema/brew/foundry-actions.json +15 -0
  40. package/schema/brew/foundry-backgrounds.json +47 -0
  41. package/schema/brew/foundry-feats.json +15 -0
  42. package/schema/brew/foundry-items.json +57 -0
  43. package/schema/brew/foundry-optionalfeatures.json +15 -0
  44. package/schema/brew/foundry-psionics.json +50 -0
  45. package/schema/brew/foundry-races.json +52 -0
  46. package/schema/brew/foundry-rewards.json +15 -0
  47. package/schema/brew/foundry-vehicles.json +15 -0
  48. package/schema/brew/generated/bookref-quick.json +72 -0
  49. package/schema/brew/homebrew.json +564 -0
  50. package/schema/brew/items-base.json +460 -0
  51. package/schema/brew/items-shared.json +295 -0
  52. package/schema/brew/items.json +1866 -0
  53. package/schema/brew/languages.json +127 -0
  54. package/schema/brew/life.json +17 -0
  55. package/schema/brew/loot.json +510 -0
  56. package/schema/brew/magicvariants.json +387 -0
  57. package/schema/brew/makebrew-creature.json +40 -0
  58. package/schema/brew/makecards.json +43 -0
  59. package/schema/brew/monsterfeatures.json +53 -0
  60. package/schema/brew/msbcr.json +60 -0
  61. package/schema/brew/names.json +91 -0
  62. package/schema/brew/objects.json +172 -0
  63. package/schema/brew/optionalfeatures.json +139 -0
  64. package/schema/brew/psionics.json +185 -0
  65. package/schema/brew/races.json +1799 -0
  66. package/schema/brew/recipes.json +191 -0
  67. package/schema/brew/renderdemo.json +16 -0
  68. package/schema/brew/rewards.json +102 -0
  69. package/schema/brew/senses.json +54 -0
  70. package/schema/brew/skills.json +54 -0
  71. package/schema/brew/spells/fluff-index.json +11 -0
  72. package/schema/brew/spells/fluff-spells.json +15 -0
  73. package/schema/brew/spells/foundry.json +15 -0
  74. package/schema/brew/spells/index.json +11 -0
  75. package/schema/brew/spells/roll20.json +112 -0
  76. package/schema/brew/spells/spells.json +1841 -0
  77. package/schema/brew/tables.json +202 -0
  78. package/schema/brew/trapshazards.json +249 -0
  79. package/schema/brew/util.json +3867 -0
  80. package/schema/brew/variantrules.json +74 -0
  81. package/schema/brew/vehicles.json +854 -0
  82. package/schema/brew-fast/actions.json +109 -0
  83. package/schema/brew-fast/adventure/adventure.json +12 -0
  84. package/schema/brew-fast/adventures.json +249 -0
  85. package/schema/brew-fast/backgrounds.json +425 -0
  86. package/schema/brew-fast/bestiary/bestiary.json +3766 -0
  87. package/schema/brew-fast/bestiary/fluff-bestiary.json +15 -0
  88. package/schema/brew-fast/bestiary/fluff-index.json +11 -0
  89. package/schema/brew-fast/bestiary/foundry.json +15 -0
  90. package/schema/brew-fast/bestiary/index.json +11 -0
  91. package/schema/brew-fast/bestiary/legendarygroups.json +202 -0
  92. package/schema/brew-fast/bestiary/traits.json +85 -0
  93. package/schema/brew-fast/book/book.json +12 -0
  94. package/schema/brew-fast/books.json +137 -0
  95. package/schema/brew-fast/changelog.json +35 -0
  96. package/schema/brew-fast/charcreationoptions.json +96 -0
  97. package/schema/brew-fast/class/class.json +2059 -0
  98. package/schema/brew-fast/class/foundry.json +373 -0
  99. package/schema/brew-fast/class/index.json +11 -0
  100. package/schema/brew-fast/conditionsdiseases.json +103 -0
  101. package/schema/brew-fast/cultsboons.json +196 -0
  102. package/schema/brew-fast/deities.json +482 -0
  103. package/schema/brew-fast/encounters.json +99 -0
  104. package/schema/brew-fast/entry.json +3538 -0
  105. package/schema/brew-fast/feats.json +215 -0
  106. package/schema/brew-fast/fluff-backgrounds.json +15 -0
  107. package/schema/brew-fast/fluff-charcreationoptions.json +43 -0
  108. package/schema/brew-fast/fluff-conditionsdiseases.json +43 -0
  109. package/schema/brew-fast/fluff-feats.json +15 -0
  110. package/schema/brew-fast/fluff-items.json +15 -0
  111. package/schema/brew-fast/fluff-languages.json +42 -0
  112. package/schema/brew-fast/fluff-objects.json +15 -0
  113. package/schema/brew-fast/fluff-races.json +214 -0
  114. package/schema/brew-fast/fluff-recipes.json +42 -0
  115. package/schema/brew-fast/fluff-vehicles.json +63 -0
  116. package/schema/brew-fast/foundry-actions.json +15 -0
  117. package/schema/brew-fast/foundry-backgrounds.json +47 -0
  118. package/schema/brew-fast/foundry-feats.json +15 -0
  119. package/schema/brew-fast/foundry-items.json +57 -0
  120. package/schema/brew-fast/foundry-optionalfeatures.json +15 -0
  121. package/schema/brew-fast/foundry-psionics.json +50 -0
  122. package/schema/brew-fast/foundry-races.json +52 -0
  123. package/schema/brew-fast/foundry-rewards.json +15 -0
  124. package/schema/brew-fast/foundry-vehicles.json +15 -0
  125. package/schema/brew-fast/generated/bookref-quick.json +72 -0
  126. package/schema/brew-fast/homebrew.json +562 -0
  127. package/schema/brew-fast/items-base.json +460 -0
  128. package/schema/brew-fast/items-shared.json +295 -0
  129. package/schema/brew-fast/items.json +1866 -0
  130. package/schema/brew-fast/languages.json +127 -0
  131. package/schema/brew-fast/life.json +17 -0
  132. package/schema/brew-fast/loot.json +510 -0
  133. package/schema/brew-fast/magicvariants.json +387 -0
  134. package/schema/brew-fast/makebrew-creature.json +40 -0
  135. package/schema/brew-fast/makecards.json +43 -0
  136. package/schema/brew-fast/monsterfeatures.json +53 -0
  137. package/schema/brew-fast/msbcr.json +60 -0
  138. package/schema/brew-fast/names.json +91 -0
  139. package/schema/brew-fast/objects.json +172 -0
  140. package/schema/brew-fast/optionalfeatures.json +139 -0
  141. package/schema/brew-fast/psionics.json +185 -0
  142. package/schema/brew-fast/races.json +1799 -0
  143. package/schema/brew-fast/recipes.json +191 -0
  144. package/schema/brew-fast/renderdemo.json +16 -0
  145. package/schema/brew-fast/rewards.json +102 -0
  146. package/schema/brew-fast/senses.json +54 -0
  147. package/schema/brew-fast/skills.json +54 -0
  148. package/schema/brew-fast/spells/fluff-index.json +11 -0
  149. package/schema/brew-fast/spells/fluff-spells.json +15 -0
  150. package/schema/brew-fast/spells/foundry.json +15 -0
  151. package/schema/brew-fast/spells/index.json +11 -0
  152. package/schema/brew-fast/spells/roll20.json +112 -0
  153. package/schema/brew-fast/spells/spells.json +1841 -0
  154. package/schema/brew-fast/tables.json +202 -0
  155. package/schema/brew-fast/trapshazards.json +249 -0
  156. package/schema/brew-fast/util.json +3867 -0
  157. package/schema/brew-fast/variantrules.json +74 -0
  158. package/schema/brew-fast/vehicles.json +854 -0
  159. package/schema/site/actions.json +97 -0
  160. package/schema/site/adventure/adventure.json +12 -0
  161. package/schema/site/adventures.json +211 -0
  162. package/schema/site/backgrounds.json +306 -0
  163. package/schema/site/bestiary/bestiary.json +3537 -0
  164. package/schema/site/bestiary/fluff-bestiary.json +15 -0
  165. package/schema/site/bestiary/fluff-index.json +11 -0
  166. package/schema/site/bestiary/foundry.json +15 -0
  167. package/schema/site/bestiary/index.json +11 -0
  168. package/schema/site/bestiary/legendarygroups.json +202 -0
  169. package/schema/site/bestiary/traits.json +85 -0
  170. package/schema/site/book/book.json +12 -0
  171. package/schema/site/books.json +137 -0
  172. package/schema/site/changelog.json +35 -0
  173. package/schema/site/charcreationoptions.json +80 -0
  174. package/schema/site/class/class.json +1792 -0
  175. package/schema/site/class/foundry.json +373 -0
  176. package/schema/site/class/index.json +11 -0
  177. package/schema/site/conditionsdiseases.json +82 -0
  178. package/schema/site/cultsboons.json +172 -0
  179. package/schema/site/deities.json +461 -0
  180. package/schema/site/encounters.json +99 -0
  181. package/schema/site/entry.json +3471 -0
  182. package/schema/site/feats.json +199 -0
  183. package/schema/site/fluff-backgrounds.json +15 -0
  184. package/schema/site/fluff-charcreationoptions.json +43 -0
  185. package/schema/site/fluff-conditionsdiseases.json +43 -0
  186. package/schema/site/fluff-feats.json +15 -0
  187. package/schema/site/fluff-items.json +15 -0
  188. package/schema/site/fluff-languages.json +42 -0
  189. package/schema/site/fluff-objects.json +15 -0
  190. package/schema/site/fluff-races.json +214 -0
  191. package/schema/site/fluff-recipes.json +42 -0
  192. package/schema/site/fluff-vehicles.json +63 -0
  193. package/schema/site/foundry-actions.json +15 -0
  194. package/schema/site/foundry-backgrounds.json +47 -0
  195. package/schema/site/foundry-feats.json +15 -0
  196. package/schema/site/foundry-items.json +57 -0
  197. package/schema/site/foundry-optionalfeatures.json +15 -0
  198. package/schema/site/foundry-psionics.json +50 -0
  199. package/schema/site/foundry-races.json +52 -0
  200. package/schema/site/foundry-rewards.json +15 -0
  201. package/schema/site/foundry-vehicles.json +15 -0
  202. package/schema/site/generated/bookref-quick.json +72 -0
  203. package/schema/site/homebrew.json +564 -0
  204. package/schema/site/items-base.json +425 -0
  205. package/schema/site/items-shared.json +259 -0
  206. package/schema/site/items.json +1722 -0
  207. package/schema/site/languages.json +120 -0
  208. package/schema/site/life.json +17 -0
  209. package/schema/site/loot.json +510 -0
  210. package/schema/site/magicvariants.json +355 -0
  211. package/schema/site/makebrew-creature.json +39 -0
  212. package/schema/site/makecards.json +43 -0
  213. package/schema/site/monsterfeatures.json +53 -0
  214. package/schema/site/msbcr.json +60 -0
  215. package/schema/site/names.json +91 -0
  216. package/schema/site/objects.json +165 -0
  217. package/schema/site/optionalfeatures.json +127 -0
  218. package/schema/site/psionics.json +173 -0
  219. package/schema/site/races.json +1708 -0
  220. package/schema/site/recipes.json +185 -0
  221. package/schema/site/renderdemo.json +16 -0
  222. package/schema/site/rewards.json +90 -0
  223. package/schema/site/senses.json +54 -0
  224. package/schema/site/skills.json +54 -0
  225. package/schema/site/spells/fluff-index.json +11 -0
  226. package/schema/site/spells/fluff-spells.json +15 -0
  227. package/schema/site/spells/foundry.json +15 -0
  228. package/schema/site/spells/index.json +11 -0
  229. package/schema/site/spells/roll20.json +112 -0
  230. package/schema/site/spells/spells.json +1238 -0
  231. package/schema/site/tables.json +185 -0
  232. package/schema/site/trapshazards.json +227 -0
  233. package/schema/site/util.json +3857 -0
  234. package/schema/site/variantrules.json +71 -0
  235. package/schema/site/vehicles.json +807 -0
  236. package/schema/site-fast/actions.json +97 -0
  237. package/schema/site-fast/adventure/adventure.json +12 -0
  238. package/schema/site-fast/adventures.json +211 -0
  239. package/schema/site-fast/backgrounds.json +306 -0
  240. package/schema/site-fast/bestiary/bestiary.json +3537 -0
  241. package/schema/site-fast/bestiary/fluff-bestiary.json +15 -0
  242. package/schema/site-fast/bestiary/fluff-index.json +11 -0
  243. package/schema/site-fast/bestiary/foundry.json +15 -0
  244. package/schema/site-fast/bestiary/index.json +11 -0
  245. package/schema/site-fast/bestiary/legendarygroups.json +202 -0
  246. package/schema/site-fast/bestiary/traits.json +85 -0
  247. package/schema/site-fast/book/book.json +12 -0
  248. package/schema/site-fast/books.json +137 -0
  249. package/schema/site-fast/changelog.json +35 -0
  250. package/schema/site-fast/charcreationoptions.json +80 -0
  251. package/schema/site-fast/class/class.json +1792 -0
  252. package/schema/site-fast/class/foundry.json +373 -0
  253. package/schema/site-fast/class/index.json +11 -0
  254. package/schema/site-fast/conditionsdiseases.json +82 -0
  255. package/schema/site-fast/cultsboons.json +172 -0
  256. package/schema/site-fast/deities.json +461 -0
  257. package/schema/site-fast/encounters.json +99 -0
  258. package/schema/site-fast/entry.json +3471 -0
  259. package/schema/site-fast/feats.json +199 -0
  260. package/schema/site-fast/fluff-backgrounds.json +15 -0
  261. package/schema/site-fast/fluff-charcreationoptions.json +43 -0
  262. package/schema/site-fast/fluff-conditionsdiseases.json +43 -0
  263. package/schema/site-fast/fluff-feats.json +15 -0
  264. package/schema/site-fast/fluff-items.json +15 -0
  265. package/schema/site-fast/fluff-languages.json +42 -0
  266. package/schema/site-fast/fluff-objects.json +15 -0
  267. package/schema/site-fast/fluff-races.json +214 -0
  268. package/schema/site-fast/fluff-recipes.json +42 -0
  269. package/schema/site-fast/fluff-vehicles.json +63 -0
  270. package/schema/site-fast/foundry-actions.json +15 -0
  271. package/schema/site-fast/foundry-backgrounds.json +47 -0
  272. package/schema/site-fast/foundry-feats.json +15 -0
  273. package/schema/site-fast/foundry-items.json +57 -0
  274. package/schema/site-fast/foundry-optionalfeatures.json +15 -0
  275. package/schema/site-fast/foundry-psionics.json +50 -0
  276. package/schema/site-fast/foundry-races.json +52 -0
  277. package/schema/site-fast/foundry-rewards.json +15 -0
  278. package/schema/site-fast/foundry-vehicles.json +15 -0
  279. package/schema/site-fast/generated/bookref-quick.json +72 -0
  280. package/schema/site-fast/homebrew.json +562 -0
  281. package/schema/site-fast/items-base.json +425 -0
  282. package/schema/site-fast/items-shared.json +259 -0
  283. package/schema/site-fast/items.json +1722 -0
  284. package/schema/site-fast/languages.json +120 -0
  285. package/schema/site-fast/life.json +17 -0
  286. package/schema/site-fast/loot.json +510 -0
  287. package/schema/site-fast/magicvariants.json +355 -0
  288. package/schema/site-fast/makebrew-creature.json +39 -0
  289. package/schema/site-fast/makecards.json +43 -0
  290. package/schema/site-fast/monsterfeatures.json +53 -0
  291. package/schema/site-fast/msbcr.json +60 -0
  292. package/schema/site-fast/names.json +91 -0
  293. package/schema/site-fast/objects.json +165 -0
  294. package/schema/site-fast/optionalfeatures.json +127 -0
  295. package/schema/site-fast/psionics.json +173 -0
  296. package/schema/site-fast/races.json +1708 -0
  297. package/schema/site-fast/recipes.json +185 -0
  298. package/schema/site-fast/renderdemo.json +16 -0
  299. package/schema/site-fast/rewards.json +90 -0
  300. package/schema/site-fast/senses.json +54 -0
  301. package/schema/site-fast/skills.json +54 -0
  302. package/schema/site-fast/spells/fluff-index.json +11 -0
  303. package/schema/site-fast/spells/fluff-spells.json +15 -0
  304. package/schema/site-fast/spells/foundry.json +15 -0
  305. package/schema/site-fast/spells/index.json +11 -0
  306. package/schema/site-fast/spells/roll20.json +112 -0
  307. package/schema/site-fast/spells/spells.json +1238 -0
  308. package/schema/site-fast/tables.json +185 -0
  309. package/schema/site-fast/trapshazards.json +227 -0
  310. package/schema/site-fast/util.json +3857 -0
  311. package/schema/site-fast/variantrules.json +71 -0
  312. package/schema/site-fast/vehicles.json +807 -0
package/lib/Api.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import {JsonTester} from "./TestJson.js";
2
- import * as Um from "./UtilMisc.js";
2
+ import Um from "./UtilMisc.js";
3
3
  import * as Uf from "./UtilFs.js";
4
4
 
5
5
  export {
package/lib/TestJson.js CHANGED
@@ -7,8 +7,8 @@ import Ajv2020 from "ajv/dist/2020.js";
7
7
  import addFormats from "ajv-formats";
8
8
  import * as jsonSourceMap from "json-source-map";
9
9
 
10
- import * as uf from "./UtilFs.js";
11
- import * as um from "./UtilMisc.js";
10
+ import * as Uf from "./UtilFs.js";
11
+ import Um from "./UtilMisc.js";
12
12
  import {WorkerList, Deferred} from "./WorkerList.js";
13
13
 
14
14
  const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
@@ -23,12 +23,20 @@ class JsonTester {
23
23
 
24
24
  constructor (
25
25
  {
26
- dirSchema,
26
+ fnGetSchemaId,
27
+
28
+ isBrew = false,
29
+ dirSchema = null,
27
30
  tagLog = LOG_TAG,
28
- fnGetSchemaId = () => "homebrew.json",
29
31
  },
30
32
  ) {
31
- this._dirSchema = dirSchema;
33
+ if (isBrew && dirSchema) throw new Error(`"isBrew" and "dirSchema" are mutually exclusive!`);
34
+ if (!fnGetSchemaId) throw new Error(`"fnGetSchemaId" is required!`);
35
+
36
+ this._dirSchema = dirSchema ??
37
+ (isBrew
38
+ ? path.join(__dirname, "..", "schema", "brew")
39
+ : path.join(__dirname, "..", "schema", "site"));
32
40
  this._tagLog = tagLog;
33
41
  this._fnGetSchemaId = fnGetSchemaId;
34
42
 
@@ -98,7 +106,7 @@ class JsonTester {
98
106
  });
99
107
 
100
108
  const error = this._getFileErrors({filePath});
101
- um.error(this._tagLog, error);
109
+ Um.error(this._tagLog, error);
102
110
  out.errors.push(error);
103
111
 
104
112
  return out;
@@ -107,10 +115,10 @@ class JsonTester {
107
115
  _doLoadSchema () {
108
116
  if (this._isSchemaLoaded) return;
109
117
 
110
- uf.listJsonFiles(this._dirSchema)
118
+ Uf.listJsonFiles(this._dirSchema)
111
119
  .forEach(filePath => {
112
120
  filePath = path.normalize(filePath);
113
- const contents = uf.readJSON(filePath);
121
+ const contents = Uf.readJSON(filePath);
114
122
 
115
123
  const relativeFilePath = path.relative(this._dirSchema, filePath)
116
124
  .replace(/\\/g, "/");
@@ -121,12 +129,17 @@ class JsonTester {
121
129
  this._isSchemaLoaded = true;
122
130
  }
123
131
 
132
+ _hasSchema (schemaId) {
133
+ this._doLoadSchema();
134
+ return !!this._ajv.schemas[schemaId];
135
+ }
136
+
124
137
  getFileErrors ({filePath} = {}) {
125
138
  this._doLoadSchema();
126
139
 
127
- um.info(this._tagLog, `\tValidating "${filePath}"...`);
140
+ Um.info(this._tagLog, `\tValidating "${filePath}"...`);
128
141
 
129
- const data = uf.readJSON(filePath);
142
+ const data = Uf.readJSON(filePath);
130
143
  this._addImplicits(data);
131
144
 
132
145
  const isValid = this._ajv.validate(this._fnGetSchemaId(filePath), data);
@@ -136,7 +149,7 @@ class JsonTester {
136
149
  }
137
150
 
138
151
  _doRunOnDir ({isFailFast, dir, errors, errorsFull, ...opts} = {}) {
139
- for (const filePath of uf.listJsonFiles(dir, opts)) {
152
+ for (const filePath of Uf.listJsonFiles(dir, opts)) {
140
153
  const {errors: errorsFile, errorsFull: errorsFullFile} = this.getFileErrors({filePath});
141
154
  errors.push(...errorsFile);
142
155
  errorsFull.push(...errorsFullFile);
@@ -150,7 +163,7 @@ class JsonTester {
150
163
  * @param [opts.dirBlocklist]
151
164
  */
152
165
  getErrors (dir, opts = {}) {
153
- um.info(this._tagLog, `Validating JSON against schema`);
166
+ Um.info(this._tagLog, `Validating JSON against schema`);
154
167
 
155
168
  const errors = [];
156
169
  const errorsFull = [];
@@ -161,12 +174,12 @@ class JsonTester {
161
174
  }
162
175
 
163
176
  getErrorsOnDirs ({isFailFast = false} = {}) {
164
- um.info(this._tagLog, `Validating JSON against schema`);
177
+ Um.info(this._tagLog, `Validating JSON against schema`);
165
178
 
166
179
  const errors = [];
167
180
  const errorsFull = [];
168
181
 
169
- uf.runOnDirs((dir) => {
182
+ Uf.runOnDirs((dir) => {
170
183
  if (isFailFast && errors.length) return;
171
184
  return this._doRunOnDir({isFailFast, errors, errorsFull, dir});
172
185
  });
@@ -174,19 +187,30 @@ class JsonTester {
174
187
  return {errors, errorsFull};
175
188
  }
176
189
 
177
- async pGetErrorsOnDirsWorkers ({isFailFast = false} = {}) {
178
- um.info(this._tagLog, `Validating JSON against schema`);
190
+ async pGetErrorsOnDirsWorkers ({isFailFast = false, fileList = null} = {}) {
191
+ Um.info(this._tagLog, `Validating JSON against schema`);
179
192
 
180
193
  const cntWorkers = Math.max(1, os.cpus().length - 1);
181
194
 
182
195
  const errors = [];
183
196
  const errorsFull = [];
184
197
 
185
- const fileQueue = [];
198
+ const fileQueue = [...(fileList || [])];
186
199
 
187
- uf.runOnDirs((dir) => {
188
- fileQueue.push(...uf.listJsonFiles(dir));
200
+ if (!fileList) {
201
+ Uf.runOnDirs((dir) => {
202
+ fileQueue.push(...Uf.listJsonFiles(dir));
203
+ });
204
+ }
205
+
206
+ // region Verify that every file path maps to a valid schema
207
+ fileQueue.forEach(filePath => {
208
+ const schemaId = this._fnGetSchemaId(filePath);
209
+ if (!schemaId) throw new Error(`Failed to get schema ID for file path "${filePath}"`);
210
+ if (!this._hasSchema(schemaId)) throw new Error(`No schema loaded with schema ID "${schemaId}"`);
211
+ return schemaId;
189
212
  });
213
+ // endregion
190
214
 
191
215
  const workerList = new WorkerList();
192
216
 
package/lib/UtilMisc.js CHANGED
@@ -1,22 +1,41 @@
1
- function _taggedConsole (fn, tag, ...args) {
2
- const expandedTag = tag.padStart(12, " ");
3
- fn(`[${expandedTag}]`, ...args);
4
- }
1
+ class MiscUtil {
2
+ /* -------------------------------------------- */
5
3
 
6
- function warn (tag, ...args) {
7
- _taggedConsole(console.warn, tag, ...args);
8
- }
4
+ // region Logging
5
+ static _taggedConsole (fn, tag, ...args) {
6
+ const expandedTag = tag.padStart(12, " ");
7
+ fn(`[${expandedTag}]`, ...args);
8
+ }
9
9
 
10
- function info (tag, ...args) {
11
- _taggedConsole(console.info, tag, ...args);
12
- }
10
+ static warn (tag, ...args) { this._taggedConsole(console.warn, tag, ...args); }
11
+ static info (tag, ...args) { this._taggedConsole(console.info, tag, ...args); }
12
+ static error (tag, ...args) { this._taggedConsole(console.error, tag, ...args); }
13
+ // endregion
14
+
15
+ /* -------------------------------------------- */
16
+
17
+ static get (object, ...path) {
18
+ if (object == null) return null;
19
+ for (let i = 0; i < path.length; ++i) {
20
+ object = object[path[i]];
21
+ if (object == null) return object;
22
+ }
23
+ return object;
24
+ }
25
+
26
+ /* -------------------------------------------- */
27
+
28
+ static copyFast (obj) {
29
+ if ((typeof obj !== "object") || obj == null) return obj;
30
+
31
+ if (obj instanceof Array) return obj.map(MiscUtil.copyFast);
32
+
33
+ const cpy = {};
34
+ for (const k of Object.keys(obj)) cpy[k] = MiscUtil.copyFast(obj[k]);
35
+ return cpy;
36
+ }
13
37
 
14
- function error (tag, ...args) {
15
- _taggedConsole(console.error, tag, ...args);
38
+ /* -------------------------------------------- */
16
39
  }
17
40
 
18
- export {
19
- warn,
20
- info,
21
- error,
22
- };
41
+ export default MiscUtil;
package/package.json CHANGED
@@ -1,19 +1,21 @@
1
1
  {
2
2
  "name": "5etools-utils",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "Shared utilities for the 5etools ecosystem.",
5
5
  "type": "module",
6
6
  "main": "lib/Api.js",
7
7
  "files": [
8
- "lib"
8
+ "lib",
9
+ "schema"
9
10
  ],
10
11
  "directories": {
11
12
  "lib": "./lib"
12
13
  },
13
14
  "scripts": {
15
+ "build": "node node/compile-schemas.js",
14
16
  "test": "npm run lint:js && npm run test:js",
15
17
  "test:js": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
16
- "lint:js": "eslint lib test --fix"
18
+ "lint:js": "eslint lib node test --fix"
17
19
  },
18
20
  "repository": {
19
21
  "type": "git",
@@ -31,6 +33,7 @@
31
33
  "json-source-map": "^0.6.1"
32
34
  },
33
35
  "devDependencies": {
36
+ "commander": "^9.4.1",
34
37
  "eslint": "^8.11.0",
35
38
  "jest": "^29.3.1"
36
39
  }
@@ -0,0 +1,109 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "actions.json",
4
+ "version": "1.2.0",
5
+ "type": "object",
6
+ "$defs": {
7
+ "action": {
8
+ "type": "object",
9
+ "properties": {
10
+ "name": {
11
+ "type": "string"
12
+ },
13
+ "entries": {
14
+ "type": "array",
15
+ "items": {
16
+ "$ref": "entry.json"
17
+ }
18
+ },
19
+ "source": {
20
+ "type": "string"
21
+ },
22
+ "page": {
23
+ "$ref": "util.json#/$defs/page"
24
+ },
25
+ "fromVariant": {
26
+ "type": "string",
27
+ "description": "UID of a \"variantrule\" to be linked as a footnote in the action."
28
+ },
29
+ "time": {
30
+ "type": "array",
31
+ "items": {
32
+ "oneOf": [
33
+ {
34
+ "type": "string"
35
+ },
36
+ {
37
+ "type": "object",
38
+ "properties": {
39
+ "unit": {
40
+ "type": "string",
41
+ "enum": [
42
+ "action",
43
+ "bonus",
44
+ "reaction"
45
+ ]
46
+ },
47
+ "number": {
48
+ "type": "integer"
49
+ }
50
+ },
51
+ "required": [
52
+ "unit",
53
+ "number"
54
+ ],
55
+ "additionalProperties": false
56
+ }
57
+ ]
58
+ }
59
+ },
60
+ "srd": {
61
+ "$ref": "util.json#/$defs/srd"
62
+ },
63
+ "basicRules": {
64
+ "$ref": "util.json#/$defs/basicRules"
65
+ },
66
+ "seeAlsoAction": {
67
+ "type": "array",
68
+ "items": {
69
+ "type": "string",
70
+ "description": "UIDs of \"action\"s to be linked in a \"See Also\" footnote.\nEx.: \"disarm|dmg\"."
71
+ }
72
+ },
73
+ "foundrySystem": {
74
+ "$ref": "util.json#/$defs/foundrySystemObject"
75
+ },
76
+ "foundryFlags": {
77
+ "$ref": "util.json#/$defs/foundryFlagsObject"
78
+ },
79
+ "foundryEffects": {
80
+ "$ref": "util.json#/$defs/foundryEffectsArray"
81
+ },
82
+ "foundryImg": {
83
+ "$ref": "util.json#/$defs/foundryImg"
84
+ }
85
+ },
86
+ "required": [
87
+ "name",
88
+ "entries",
89
+ "source",
90
+ "page"
91
+ ],
92
+ "additionalProperties": false
93
+ }
94
+ },
95
+ "properties": {
96
+ "action": {
97
+ "type": "array",
98
+ "minItems": 1,
99
+ "uniqueItems": true,
100
+ "items": {
101
+ "$ref": "#/$defs/action"
102
+ }
103
+ }
104
+ },
105
+ "required": [
106
+ "action"
107
+ ],
108
+ "additionalProperties": false
109
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "adventure.json",
4
+ "version": "1.2.0",
5
+ "type": "object",
6
+ "properties": {
7
+ "data": {
8
+ "$ref": "../util.json#/$defs/adventureBookData"
9
+ }
10
+ },
11
+ "additionalProperties": false
12
+ }
@@ -0,0 +1,249 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "adventures.json",
4
+ "version": "1.10.9",
5
+ "type": "object",
6
+ "properties": {
7
+ "adventure": {
8
+ "type": "array",
9
+ "minItems": 1,
10
+ "uniqueItems": true,
11
+ "items": {
12
+ "type": "object",
13
+ "properties": {
14
+ "name": {
15
+ "type": "string"
16
+ },
17
+ "alias": {
18
+ "$ref": "util.json#/$defs/alias"
19
+ },
20
+ "id": {
21
+ "type": "string",
22
+ "description": "An ID that will be used to refer to this adventure in tags."
23
+ },
24
+ "source": {
25
+ "type": "string"
26
+ },
27
+ "parentSource": {
28
+ "type": "string",
29
+ "description": "Used for books that contain multiple adventures, e.g. TftYP"
30
+ },
31
+ "group": {
32
+ "description": "The group under which this adventure should be listed in the navbar.",
33
+ "type": "string",
34
+ "enum": [
35
+ "supplement",
36
+ "supplement-alt",
37
+ "homebrew",
38
+ "other"
39
+ ]
40
+ },
41
+ "contents": {
42
+ "description": "The linked Table of Contents of the adventure.",
43
+ "type": "array",
44
+ "minItems": 1,
45
+ "items": {
46
+ "type": "object",
47
+ "properties": {
48
+ "name": {
49
+ "type": "string"
50
+ },
51
+ "headers": {
52
+ "type": "array",
53
+ "minItems": 1,
54
+ "items": {
55
+ "oneOf": [
56
+ {
57
+ "type": "string"
58
+ },
59
+ {
60
+ "type": "object",
61
+ "properties": {
62
+ "depth": {
63
+ "type": "integer"
64
+ },
65
+ "header": {
66
+ "type": "string"
67
+ },
68
+ "index": {
69
+ "description": "The relative index of this header in the current chapter, i.e. if \"Treasure\" appears twice and you wish the contents entry to link to the second instance, set the \"index\" to 1.",
70
+ "type": "integer"
71
+ }
72
+ },
73
+ "required": [
74
+ "header"
75
+ ]
76
+ }
77
+ ]
78
+ }
79
+ },
80
+ "ordinal": {
81
+ "type": "object",
82
+ "properties": {
83
+ "type": {
84
+ "type": "string",
85
+ "enum": [
86
+ "chapter",
87
+ "appendix",
88
+ "part",
89
+ "episode",
90
+ "level"
91
+ ]
92
+ },
93
+ "identifier": {
94
+ "type": [
95
+ "integer",
96
+ "string"
97
+ ]
98
+ }
99
+ },
100
+ "additionalProperties": false,
101
+ "required": [
102
+ "type",
103
+ "identifier"
104
+ ]
105
+ }
106
+ },
107
+ "additionalProperties": false,
108
+ "required": [
109
+ "name"
110
+ ]
111
+ }
112
+ },
113
+ "level": {
114
+ "description": "The character levels that the adventure ranges across.",
115
+ "oneOf": [
116
+ {
117
+ "type": "object",
118
+ "properties": {
119
+ "start": {
120
+ "type": "integer"
121
+ },
122
+ "end": {
123
+ "type": "integer"
124
+ }
125
+ },
126
+ "additionalProperties": false,
127
+ "required": [
128
+ "start",
129
+ "end"
130
+ ]
131
+ },
132
+ {
133
+ "type": "object",
134
+ "properties": {
135
+ "custom": {
136
+ "type": "string"
137
+ }
138
+ },
139
+ "additionalProperties": false,
140
+ "required": [
141
+ "custom"
142
+ ]
143
+ }
144
+ ]
145
+ },
146
+ "published": {
147
+ "type": "string",
148
+ "format": "date",
149
+ "description": "The date of publication of the adventure, in the format YYYY-MM-DD (RFC3339)."
150
+ },
151
+ "publishedOrder": {
152
+ "description": "A sorting order for adventures within a single source.",
153
+ "type": "integer"
154
+ },
155
+ "coverUrl": {
156
+ "description": "A direct link to an image which should be 300 x 300px in size. Larger images will be centred and cropped.",
157
+ "type": "string"
158
+ },
159
+ "storyline": {
160
+ "type": "string",
161
+ "examples": [
162
+ "Starter Set",
163
+ "Tyranny of Dragons",
164
+ "Elemental Evil",
165
+ "Rage of Demons",
166
+ "Ravenloft",
167
+ "Storm King's Thunder",
168
+ "Tales from the Yawning Portal",
169
+ "Tomb of Annihilation",
170
+ "Waterdeep",
171
+ "Ravnica",
172
+ "Extra Life",
173
+ "Ghosts of Saltmarsh",
174
+ "Acquisitions Incorporated",
175
+ "Essentials Kit",
176
+ "Stranger Things",
177
+ "Baldur's Gate",
178
+ "Eberron",
179
+ "Rick and Morty",
180
+ "Wildemount",
181
+ "Icewind Dale",
182
+ "Mythic Odysseys of Theros",
183
+ "Candlekeep Mysteries",
184
+ "Adventures in the Forgotten Realms",
185
+ "The Wild Beyond the Witchlight",
186
+ "Ixalan",
187
+ "NERDS Restoring Harmony",
188
+ "Strixhaven",
189
+ "Critical Role",
190
+ "Journeys through the Radiant Citadel",
191
+ "Spelljammer",
192
+ "Dragonlance"
193
+ ]
194
+ },
195
+ "alAveragePlayerLevel": {
196
+ "description": "Adventurers League Average Player Level; for use in homebrew.",
197
+ "type": "integer"
198
+ },
199
+ "alLength": {
200
+ "description": "Adventurers League length (in hours); for use in homebrew.",
201
+ "type": "object",
202
+ "oneOf": [
203
+ {
204
+ "properties": {
205
+ "min": {
206
+ "type": "integer"
207
+ },
208
+ "max": {
209
+ "type": "integer"
210
+ }
211
+ },
212
+ "required": [
213
+ "min",
214
+ "max"
215
+ ]
216
+ },
217
+ {
218
+ "properties": {
219
+ "exact": {
220
+ "type": "integer"
221
+ }
222
+ },
223
+ "required": [
224
+ "exact"
225
+ ]
226
+ }
227
+ ]
228
+ },
229
+ "alId": {
230
+ "description": "Adventurers League ID; for use in homebrew.",
231
+ "type": "string"
232
+ }
233
+ },
234
+ "additionalProperties": false,
235
+ "required": [
236
+ "name",
237
+ "id",
238
+ "source",
239
+ "contents",
240
+ "level",
241
+ "published",
242
+ "storyline",
243
+ "group"
244
+ ]
245
+ }
246
+ }
247
+ },
248
+ "additionalProperties": false
249
+ }