@minecraft/api-docs-generator 1.0.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 (157) hide show
  1. package/CHANGELOG.json +20 -0
  2. package/CHANGELOG.md +13 -0
  3. package/README.md +92 -0
  4. package/lib/ChangelogStrategy.d.ts +39 -0
  5. package/lib/ChangelogStrategy.js +114 -0
  6. package/lib/ChangelogStrategy.js.map +1 -0
  7. package/lib/Config.d.ts +76 -0
  8. package/lib/Config.js +68 -0
  9. package/lib/Config.js.map +1 -0
  10. package/lib/Context.d.ts +28 -0
  11. package/lib/Context.js +323 -0
  12. package/lib/Context.js.map +1 -0
  13. package/lib/FileLoader.d.ts +13 -0
  14. package/lib/FileLoader.js +91 -0
  15. package/lib/FileLoader.js.map +1 -0
  16. package/lib/Logger.d.ts +65 -0
  17. package/lib/Logger.js +179 -0
  18. package/lib/Logger.js.map +1 -0
  19. package/lib/MinecraftRelease.d.ts +37 -0
  20. package/lib/MinecraftRelease.js +157 -0
  21. package/lib/MinecraftRelease.js.map +1 -0
  22. package/lib/PrettierConfiguration.d.ts +2 -0
  23. package/lib/PrettierConfiguration.js +17 -0
  24. package/lib/PrettierConfiguration.js.map +1 -0
  25. package/lib/changelog.d.ts +11 -0
  26. package/lib/changelog.js +459 -0
  27. package/lib/changelog.js.map +1 -0
  28. package/lib/cli.d.ts +2 -0
  29. package/lib/cli.js +172 -0
  30. package/lib/cli.js.map +1 -0
  31. package/lib/filters/CommandFilters.d.ts +2 -0
  32. package/lib/filters/CommandFilters.js +171 -0
  33. package/lib/filters/CommandFilters.js.map +1 -0
  34. package/lib/filters/CommonFilters.d.ts +2 -0
  35. package/lib/filters/CommonFilters.js +2518 -0
  36. package/lib/filters/CommonFilters.js.map +1 -0
  37. package/lib/filters/Filters.d.ts +17 -0
  38. package/lib/filters/Filters.js +5 -0
  39. package/lib/filters/Filters.js.map +1 -0
  40. package/lib/filters/MarkdownFilters.d.ts +2 -0
  41. package/lib/filters/MarkdownFilters.js +63 -0
  42. package/lib/filters/MarkdownFilters.js.map +1 -0
  43. package/lib/filters/TypeScriptFilters.d.ts +2 -0
  44. package/lib/filters/TypeScriptFilters.js +387 -0
  45. package/lib/filters/TypeScriptFilters.js.map +1 -0
  46. package/lib/filters/index.d.ts +4 -0
  47. package/lib/filters/index.js +23 -0
  48. package/lib/filters/index.js.map +1 -0
  49. package/lib/generator.d.ts +8 -0
  50. package/lib/generator.js +511 -0
  51. package/lib/generator.js.map +1 -0
  52. package/lib/index.d.ts +16 -0
  53. package/lib/index.js +50 -0
  54. package/lib/index.js.map +1 -0
  55. package/lib/modules/IMinecraftModule.d.ts +123 -0
  56. package/lib/modules/IMinecraftModule.js +71 -0
  57. package/lib/modules/IMinecraftModule.js.map +1 -0
  58. package/lib/modules/KeyToTypeMapping.d.ts +77 -0
  59. package/lib/modules/KeyToTypeMapping.js +5 -0
  60. package/lib/modules/KeyToTypeMapping.js.map +1 -0
  61. package/lib/modules/MinecraftAfterEventsOrderModule.d.ts +57 -0
  62. package/lib/modules/MinecraftAfterEventsOrderModule.js +28 -0
  63. package/lib/modules/MinecraftAfterEventsOrderModule.js.map +1 -0
  64. package/lib/modules/MinecraftBlockModule.d.ts +139 -0
  65. package/lib/modules/MinecraftBlockModule.js +37 -0
  66. package/lib/modules/MinecraftBlockModule.js.map +1 -0
  67. package/lib/modules/MinecraftChangelogTypes.d.ts +60 -0
  68. package/lib/modules/MinecraftChangelogTypes.js +17 -0
  69. package/lib/modules/MinecraftChangelogTypes.js.map +1 -0
  70. package/lib/modules/MinecraftCommandModule.d.ts +270 -0
  71. package/lib/modules/MinecraftCommandModule.js +87 -0
  72. package/lib/modules/MinecraftCommandModule.js.map +1 -0
  73. package/lib/modules/MinecraftDimensionsModule.d.ts +44 -0
  74. package/lib/modules/MinecraftDimensionsModule.js +11 -0
  75. package/lib/modules/MinecraftDimensionsModule.js.map +1 -0
  76. package/lib/modules/MinecraftDocsTypes.d.ts +475 -0
  77. package/lib/modules/MinecraftDocsTypes.js +77 -0
  78. package/lib/modules/MinecraftDocsTypes.js.map +1 -0
  79. package/lib/modules/MinecraftEffectsModule.d.ts +44 -0
  80. package/lib/modules/MinecraftEffectsModule.js +11 -0
  81. package/lib/modules/MinecraftEffectsModule.js.map +1 -0
  82. package/lib/modules/MinecraftEnchantmentsModule.d.ts +44 -0
  83. package/lib/modules/MinecraftEnchantmentsModule.js +11 -0
  84. package/lib/modules/MinecraftEnchantmentsModule.js.map +1 -0
  85. package/lib/modules/MinecraftEngineDataModules.d.ts +2 -0
  86. package/lib/modules/MinecraftEngineDataModules.js +5 -0
  87. package/lib/modules/MinecraftEngineDataModules.js.map +1 -0
  88. package/lib/modules/MinecraftEntitiesModule.d.ts +44 -0
  89. package/lib/modules/MinecraftEntitiesModule.js +11 -0
  90. package/lib/modules/MinecraftEntitiesModule.js.map +1 -0
  91. package/lib/modules/MinecraftItemsModule.d.ts +44 -0
  92. package/lib/modules/MinecraftItemsModule.js +11 -0
  93. package/lib/modules/MinecraftItemsModule.js.map +1 -0
  94. package/lib/modules/MinecraftSchemaObject.d.ts +16 -0
  95. package/lib/modules/MinecraftSchemaObject.js +5 -0
  96. package/lib/modules/MinecraftSchemaObject.js.map +1 -0
  97. package/lib/modules/MinecraftScriptModule.d.ts +3677 -0
  98. package/lib/modules/MinecraftScriptModule.js +374 -0
  99. package/lib/modules/MinecraftScriptModule.js.map +1 -0
  100. package/lib/modules/MinecraftVanillaDataModules.d.ts +4 -0
  101. package/lib/modules/MinecraftVanillaDataModules.js +9 -0
  102. package/lib/modules/MinecraftVanillaDataModules.js.map +1 -0
  103. package/lib/modules/index.d.ts +15 -0
  104. package/lib/modules/index.js +34 -0
  105. package/lib/modules/index.js.map +1 -0
  106. package/lib/plugins/MarkupGenerator.d.ts +28 -0
  107. package/lib/plugins/MarkupGenerator.js +5 -0
  108. package/lib/plugins/MarkupGenerator.js.map +1 -0
  109. package/lib/plugins/Plugin.d.ts +16 -0
  110. package/lib/plugins/Plugin.js +5 -0
  111. package/lib/plugins/Plugin.js.map +1 -0
  112. package/lib/plugins/index.d.ts +2 -0
  113. package/lib/plugins/index.js +21 -0
  114. package/lib/plugins/index.js.map +1 -0
  115. package/lib/test/commonFilterUnitTests.spec.d.ts +1 -0
  116. package/lib/test/commonFilterUnitTests.spec.js +85 -0
  117. package/lib/test/commonFilterUnitTests.spec.js.map +1 -0
  118. package/lib/test/diffingUnitTests.test.d.ts +1 -0
  119. package/lib/test/diffingUnitTests.test.js +238 -0
  120. package/lib/test/diffingUnitTests.test.js.map +1 -0
  121. package/lib/test/scanObjectUnitTests.test.d.ts +1 -0
  122. package/lib/test/scanObjectUnitTests.test.js +162 -0
  123. package/lib/test/scanObjectUnitTests.test.js.map +1 -0
  124. package/lib/test/versionParsing.test.d.ts +1 -0
  125. package/lib/test/versionParsing.test.js +147 -0
  126. package/lib/test/versionParsing.test.js.map +1 -0
  127. package/lib/utilities/AppendVersion.d.ts +8 -0
  128. package/lib/utilities/AppendVersion.js +46 -0
  129. package/lib/utilities/AppendVersion.js.map +1 -0
  130. package/lib/utilities/Complete.d.ts +7 -0
  131. package/lib/utilities/Complete.js +5 -0
  132. package/lib/utilities/Complete.js.map +1 -0
  133. package/lib/utilities/DeepCopyJson.d.ts +4 -0
  134. package/lib/utilities/DeepCopyJson.js +46 -0
  135. package/lib/utilities/DeepCopyJson.js.map +1 -0
  136. package/lib/utilities/GetFiles.d.ts +3 -0
  137. package/lib/utilities/GetFiles.js +44 -0
  138. package/lib/utilities/GetFiles.js.map +1 -0
  139. package/lib/utilities/LongestCommonSubsequence.d.ts +3 -0
  140. package/lib/utilities/LongestCommonSubsequence.js +123 -0
  141. package/lib/utilities/LongestCommonSubsequence.js.map +1 -0
  142. package/lib/utilities/MergeArrays.d.ts +1 -0
  143. package/lib/utilities/MergeArrays.js +15 -0
  144. package/lib/utilities/MergeArrays.js.map +1 -0
  145. package/lib/utilities/RemoveProperty.d.ts +1 -0
  146. package/lib/utilities/RemoveProperty.js +16 -0
  147. package/lib/utilities/RemoveProperty.js.map +1 -0
  148. package/lib/utilities/ScanObject.d.ts +13 -0
  149. package/lib/utilities/ScanObject.js +101 -0
  150. package/lib/utilities/ScanObject.js.map +1 -0
  151. package/lib/utilities/SortComparers.d.ts +3 -0
  152. package/lib/utilities/SortComparers.js +21 -0
  153. package/lib/utilities/SortComparers.js.map +1 -0
  154. package/lib/utilities/index.d.ts +9 -0
  155. package/lib/utilities/index.js +28 -0
  156. package/lib/utilities/index.js.map +1 -0
  157. package/package.json +72 -0
@@ -0,0 +1,2518 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || function (mod) {
21
+ if (mod && mod.__esModule) return mod;
22
+ var result = {};
23
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
+ __setModuleDefault(result, mod);
25
+ return result;
26
+ };
27
+ var __importDefault = (this && this.__importDefault) || function (mod) {
28
+ return (mod && mod.__esModule) ? mod : { "default": mod };
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.CommonFilters = void 0;
32
+ const path_1 = __importDefault(require("path"));
33
+ const rt = __importStar(require("runtypes"));
34
+ const semver_1 = __importDefault(require("semver"));
35
+ const word_wrap_1 = __importDefault(require("word-wrap"));
36
+ const log = __importStar(require("../Logger"));
37
+ const MinecraftRelease_1 = require("../MinecraftRelease");
38
+ const MinecraftAfterEventsOrderModule_1 = require("../modules/MinecraftAfterEventsOrderModule");
39
+ const CommandFilters_1 = require("./CommandFilters");
40
+ const MinecraftChangelogTypes_1 = require("../modules/MinecraftChangelogTypes");
41
+ const MinecraftDocsTypes_1 = require("../modules/MinecraftDocsTypes");
42
+ const MinecraftScriptModule_1 = require("../modules/MinecraftScriptModule");
43
+ const utils = __importStar(require("../utilities"));
44
+ const LINK_TAG = '@link';
45
+ const LINK_REGEX = new RegExp(`\\{${LINK_TAG} ([^\\s]+)\\}`, 'g');
46
+ function formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, memberJson, submemberJson) {
47
+ let result = str;
48
+ for (let i = linkMatches.length - 1; i >= 0; --i) {
49
+ const currentMatch = linkMatches[i];
50
+ const matchedString = currentMatch[0];
51
+ const matchedSymbol = currentMatch[1];
52
+ if (memberJson && submemberJson) {
53
+ // ModuleName.ClassName.MemberName
54
+ const pattern = `${moduleJson.name}.${memberJson.name}.${submemberJson.name}`;
55
+ if (matchedSymbol === pattern) {
56
+ result = result.replace(matchedString, formatter(fromModule, moduleJson, memberJson, submemberJson));
57
+ linkMatches.splice(i, 1);
58
+ }
59
+ }
60
+ else if (!memberJson && submemberJson) {
61
+ // ModuleName.MemberName
62
+ const pattern = `${moduleJson.name}.${submemberJson.name}`;
63
+ if (matchedSymbol === pattern) {
64
+ result = result.replace(matchedString, formatter(fromModule, moduleJson, undefined, submemberJson));
65
+ linkMatches.splice(i, 1);
66
+ }
67
+ }
68
+ else if (memberJson) {
69
+ // ModuleName.ClassName
70
+ const patternRegex = `${moduleJson.name}.${memberJson.name}`;
71
+ if (matchedSymbol === patternRegex) {
72
+ result = result.replace(matchedString, formatter(fromModule, moduleJson, memberJson, undefined));
73
+ linkMatches.splice(i, 1);
74
+ }
75
+ }
76
+ else if (!memberJson && !submemberJson) {
77
+ // ModuleName
78
+ const pattern = `${moduleJson.name}`;
79
+ if (matchedSymbol === pattern) {
80
+ result = result.replace(matchedString, formatter(fromModule, moduleJson, undefined, undefined));
81
+ linkMatches.splice(i, 1);
82
+ }
83
+ }
84
+ }
85
+ return result;
86
+ }
87
+ function linkSymbols(description, formatter, fromModule, allModules) {
88
+ const result = [];
89
+ for (let str of description) {
90
+ if (!str.includes(LINK_TAG)) {
91
+ result.push(str);
92
+ continue;
93
+ }
94
+ const linkMatches = [...str.matchAll(LINK_REGEX)];
95
+ moduleLoop: for (const moduleJson of allModules) {
96
+ if (!str.includes(moduleJson.name)) {
97
+ continue;
98
+ }
99
+ for (const functionJson of moduleJson.functions ?? []) {
100
+ if (linkMatches.length === 0) {
101
+ break moduleLoop;
102
+ }
103
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, undefined, functionJson);
104
+ }
105
+ for (const memberJson of moduleJson.classes ?? []) {
106
+ for (const functionJson of memberJson.functions ?? []) {
107
+ if (linkMatches.length === 0) {
108
+ break moduleLoop;
109
+ }
110
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, memberJson, functionJson);
111
+ }
112
+ for (const propertyJson of memberJson.properties ?? []) {
113
+ if (linkMatches.length === 0) {
114
+ break moduleLoop;
115
+ }
116
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, memberJson, propertyJson);
117
+ }
118
+ for (const constantJson of memberJson.constants ?? []) {
119
+ if (linkMatches.length === 0) {
120
+ break moduleLoop;
121
+ }
122
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, memberJson, constantJson);
123
+ }
124
+ if (linkMatches.length === 0) {
125
+ break moduleLoop;
126
+ }
127
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, memberJson);
128
+ }
129
+ for (const interfaceJson of moduleJson.interfaces ?? []) {
130
+ for (const propertiesJson of interfaceJson.properties ?? []) {
131
+ if (linkMatches.length === 0) {
132
+ break moduleLoop;
133
+ }
134
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, interfaceJson, propertiesJson);
135
+ }
136
+ if (linkMatches.length === 0) {
137
+ break moduleLoop;
138
+ }
139
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, interfaceJson);
140
+ }
141
+ for (const enumJson of moduleJson.enums ?? []) {
142
+ for (const constantJson of enumJson.constants ?? []) {
143
+ if (linkMatches.length === 0) {
144
+ break moduleLoop;
145
+ }
146
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, enumJson, constantJson);
147
+ }
148
+ if (linkMatches.length === 0) {
149
+ break moduleLoop;
150
+ }
151
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, enumJson);
152
+ }
153
+ for (const objectJson of moduleJson.objects ?? []) {
154
+ if (linkMatches.length === 0) {
155
+ break moduleLoop;
156
+ }
157
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, undefined, objectJson);
158
+ }
159
+ for (const constantJson of moduleJson.constants ?? []) {
160
+ if (linkMatches.length === 0) {
161
+ break moduleLoop;
162
+ }
163
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, undefined, constantJson);
164
+ }
165
+ for (const typeAliasJson of moduleJson.type_aliases ?? []) {
166
+ if (linkMatches.length === 0) {
167
+ break moduleLoop;
168
+ }
169
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson, undefined, typeAliasJson);
170
+ }
171
+ if (linkMatches.length === 0) {
172
+ break moduleLoop;
173
+ }
174
+ str = formatSymbolReference(str, linkMatches, formatter, fromModule, moduleJson);
175
+ }
176
+ result.push(str);
177
+ }
178
+ return result;
179
+ }
180
+ function generateMSDocsLink(_fromModule, moduleJson, classJson, memberJson) {
181
+ if (classJson && memberJson) {
182
+ // Class Member
183
+ return `[*${moduleJson.name}.${classJson.name}.${memberJson.name}*](../../../${moduleJson.from_module.folder_path}/${moduleJson.filepath_name}/${classJson.name}.md#${memberJson.bookmark_name})`;
184
+ }
185
+ else if (!classJson && memberJson) {
186
+ // Module Member
187
+ return `[*${moduleJson.name}.${memberJson.name}*](../../../${moduleJson.from_module.folder_path}/${moduleJson.filepath_name}/${moduleJson.bookmark_name}.md#${memberJson.bookmark_name})`;
188
+ }
189
+ else if (classJson) {
190
+ // Class
191
+ return `[*${moduleJson.name}.${classJson.name}*](../../../${moduleJson.from_module.folder_path}/${moduleJson.filepath_name}/${classJson.name}.md)`;
192
+ }
193
+ else {
194
+ // Module
195
+ return `[*${moduleJson.name}*](../../../${moduleJson.from_module.folder_path}/${moduleJson.filepath_name}/${moduleJson.bookmark_name}.md)`;
196
+ }
197
+ }
198
+ function generateTSDocsLink(fromModule, moduleJson, classJson, memberJson) {
199
+ const isSameModule = fromModule.uuid === moduleJson.uuid;
200
+ const isDependencyModule = fromModule.dependencies.some(dep => dep.name === moduleJson.name) ||
201
+ fromModule.peer_dependencies.some(dep => dep.name === moduleJson.name);
202
+ if (classJson && memberJson) {
203
+ if (isSameModule) {
204
+ return `{@link ${classJson.name}.${memberJson.name}}`;
205
+ }
206
+ else if (isDependencyModule) {
207
+ return `{@link ${moduleJson.variable_name}.${classJson.name}.${memberJson.name}}`;
208
+ }
209
+ else {
210
+ return `{@link ${moduleJson.name}.${classJson.name}.${memberJson.name}}`;
211
+ }
212
+ }
213
+ else if (!classJson && memberJson) {
214
+ if (isSameModule) {
215
+ return `{@link ${memberJson.name}}`;
216
+ }
217
+ else if (isDependencyModule) {
218
+ return `{@link ${moduleJson.variable_name}#${memberJson.name}}`;
219
+ }
220
+ else {
221
+ return `{@link ${moduleJson.name}#${memberJson.name}}`;
222
+ }
223
+ }
224
+ else if (classJson) {
225
+ if (isSameModule) {
226
+ return `{@link ${classJson.name}}`;
227
+ }
228
+ else if (isDependencyModule) {
229
+ return `{@link ${moduleJson.variable_name}.${classJson.name}}`;
230
+ }
231
+ else {
232
+ return `{@link ${moduleJson.name}.${classJson.name}}`;
233
+ }
234
+ }
235
+ else {
236
+ if (isDependencyModule) {
237
+ return `{@link ${moduleJson.variable_name}}`;
238
+ }
239
+ else {
240
+ return `{@link ${moduleJson.name}}`;
241
+ }
242
+ }
243
+ }
244
+ function splitStringByNewline(description) {
245
+ if (typeof description === 'string') {
246
+ return description.split('\n');
247
+ }
248
+ return description;
249
+ }
250
+ function parseScriptRawTSDocText(scriptObject, re) {
251
+ let result = undefined;
252
+ if (scriptObject.is_script_generated && scriptObject.raw_tsdoc_text) {
253
+ const regexp = re ?? /\/\*\*\n\s\*\s(\w.+?)\n/;
254
+ const match = scriptObject.raw_tsdoc_text.match(regexp);
255
+ if (match) {
256
+ result = splitStringByNewline(match[1]);
257
+ }
258
+ }
259
+ return result;
260
+ }
261
+ function addDescriptionFields(jsonObject, description, descriptionKey, moduleJson, allModules) {
262
+ jsonObject[descriptionKey] = description;
263
+ const mdDescription = linkSymbols(description, generateMSDocsLink, moduleJson, allModules);
264
+ jsonObject[`${descriptionKey}_md`] = mdDescription;
265
+ const tsDescription = linkSymbols(description, generateTSDocsLink, moduleJson, allModules);
266
+ const tsDescriptionWrapped = [];
267
+ for (const line of tsDescription) {
268
+ const wrappedLines = (0, word_wrap_1.default)(line, { width: 60, indent: '', trim: true });
269
+ tsDescriptionWrapped.push(...wrappedLines.split('\n'));
270
+ }
271
+ jsonObject[`${descriptionKey}_ts`] = tsDescriptionWrapped;
272
+ }
273
+ /**
274
+ * Parses 'info.json' files and validates data structure according to layout.
275
+ *
276
+ * Example:
277
+ * ```
278
+ * {
279
+ * "default": {...} // For unmatched versions
280
+ * "1": {...} // Major version 1
281
+ * "2": {...} // Major version 2
282
+ * "beta": {...}
283
+ * "alpha": {...}
284
+ * "internal": {...}
285
+ * }
286
+ * ```
287
+ */
288
+ function parseInfoJsonSafe(fileLoader, jsonPath, scriptModuleVersion, validator, nestedValidator) {
289
+ if (fileLoader.canLoadFile(jsonPath)) {
290
+ try {
291
+ const fileData = fileLoader.readFile(jsonPath);
292
+ const json = JSON.parse(fileData.toString());
293
+ try {
294
+ if (json['description'] || json['arguments'] || json['return']) {
295
+ return nestedValidator.check(json);
296
+ }
297
+ validator.check(json);
298
+ const keys = Object.keys(json)
299
+ .sort((key1, key2) => key1.localeCompare(key2))
300
+ .reverse();
301
+ for (const key of keys) {
302
+ if (key === 'default') {
303
+ continue;
304
+ }
305
+ if (key === scriptModuleVersion.major.toString()) {
306
+ return nestedValidator.check(json[key]);
307
+ }
308
+ if ((key === 'beta' || key === 'alpha' || key === 'internal') &&
309
+ scriptModuleVersion.prerelease.some(prereleaseTag => {
310
+ return prereleaseTag.toString().includes(key);
311
+ })) {
312
+ return nestedValidator.check(json[key]);
313
+ }
314
+ }
315
+ return nestedValidator.check(json['default']);
316
+ }
317
+ catch (e) {
318
+ if (e instanceof rt.ValidationError) {
319
+ log.error(`JSON file '${jsonPath}' does not match expected format: ${e.message}`);
320
+ }
321
+ }
322
+ }
323
+ catch (e) {
324
+ if (e instanceof Error) {
325
+ log.error(`JSON file '${jsonPath}' had errors: ${e.message}`);
326
+ }
327
+ }
328
+ }
329
+ else {
330
+ log.printOption(`JSON file '${jsonPath}' does not exist.`, 'undocumentedApis');
331
+ }
332
+ return undefined;
333
+ }
334
+ function parseJsonSafe(fileLoader, jsonPath, validator) {
335
+ if (fileLoader.canLoadFile(jsonPath)) {
336
+ try {
337
+ const fileData = fileLoader.readFile(jsonPath);
338
+ const json = JSON.parse(fileData.toString());
339
+ try {
340
+ return validator.check(json);
341
+ }
342
+ catch (e) {
343
+ if (e instanceof rt.ValidationError) {
344
+ log.error(`JSON file '${jsonPath}' does not match expected format: ${e.message}`);
345
+ }
346
+ }
347
+ }
348
+ catch (e) {
349
+ if (e instanceof Error) {
350
+ log.error(`JSON file '${jsonPath}' had errors: ${e.message}`);
351
+ }
352
+ }
353
+ }
354
+ else {
355
+ log.printOption(`JSON file '${jsonPath}' does not exist.`, 'undocumentedApis');
356
+ }
357
+ return undefined;
358
+ }
359
+ function getDescriptionOrTSDoc(jsonObject, infoJson) {
360
+ let result;
361
+ if (infoJson && infoJson.description) {
362
+ result = splitStringByNewline(infoJson.description);
363
+ }
364
+ else if (jsonObject.raw_tsdoc_text) {
365
+ result = parseScriptRawTSDocText(jsonObject);
366
+ }
367
+ return result;
368
+ }
369
+ function getDeprecatedDescriptionOrTSDoc(jsonObject, infoJson) {
370
+ let result;
371
+ if (infoJson && infoJson.deprecated) {
372
+ if (jsonObject.is_deprecated) {
373
+ if (infoJson.deprecated.description) {
374
+ result = splitStringByNewline(infoJson.deprecated.description);
375
+ }
376
+ else {
377
+ log.warn(`${jsonObject.name} has 'deprecated' field with no description`);
378
+ }
379
+ }
380
+ else {
381
+ log.warn(`${jsonObject.name} has 'deprecated' field but is not a deprecated API`);
382
+ }
383
+ }
384
+ else if (jsonObject.raw_tsdoc_text) {
385
+ result = parseScriptRawTSDocText(jsonObject, /@deprecated\s(.+?)\n/);
386
+ }
387
+ return result;
388
+ }
389
+ function getThrowsDescriptionOrTSDoc(jsonObject, infoJson) {
390
+ let result;
391
+ if (infoJson && infoJson.throws) {
392
+ if (infoJson.throws.description) {
393
+ result = splitStringByNewline(infoJson.throws.description);
394
+ }
395
+ else {
396
+ log.warn(`${jsonObject.name} has 'throws' field with no description`);
397
+ }
398
+ }
399
+ else if (jsonObject.raw_tsdoc_text) {
400
+ result = parseScriptRawTSDocText(jsonObject, /@throws\s(.+?)\n/);
401
+ }
402
+ return result;
403
+ }
404
+ function getReturnsDescriptionOrTSDoc(jsonObject, infoJson) {
405
+ let result;
406
+ if (infoJson && infoJson.returns) {
407
+ if (infoJson.returns.description) {
408
+ result = splitStringByNewline(infoJson.returns.description);
409
+ }
410
+ else {
411
+ log.warn(`${jsonObject.name} has 'returns' field with no description`);
412
+ }
413
+ }
414
+ else if (jsonObject.raw_tsdoc_text) {
415
+ result = parseScriptRawTSDocText(jsonObject, /@returns\s(.+?)\n/);
416
+ }
417
+ return result;
418
+ }
419
+ const ArrayOfStrings = rt.Array(rt.String);
420
+ function addExamples(fileLoader, metadataJson, metadataFolder, moduleFolderPath) {
421
+ const exampleFilePaths = [];
422
+ const examplesDirectory = path_1.default.join(metadataFolder, '_examples');
423
+ const exampleFilesFromExamplesDirectory = utils.getFiles(fileLoader.joinToRoot(examplesDirectory));
424
+ for (const exampleFilePath of exampleFilesFromExamplesDirectory) {
425
+ exampleFilePaths.push(path_1.default.join(examplesDirectory, path_1.default.basename(exampleFilePath)));
426
+ }
427
+ const externalExamplesFile = path_1.default.join(metadataFolder, '_example_files.json');
428
+ const externalExampleFilePaths = parseJsonSafe(fileLoader, externalExamplesFile, ArrayOfStrings);
429
+ if (externalExampleFilePaths) {
430
+ for (const exampleFilePath of externalExampleFilePaths) {
431
+ exampleFilePaths.push(path_1.default.join(moduleFolderPath, '_shared_examples', exampleFilePath));
432
+ }
433
+ }
434
+ if (exampleFilePaths.length > 0) {
435
+ for (const examplePath of exampleFilePaths) {
436
+ const exampleName = path_1.default.basename(examplePath);
437
+ const exampleFileData = fileLoader.readFile(examplePath);
438
+ const exampleFileStrings = exampleFileData
439
+ .toString()
440
+ .split('\n')
441
+ .map(line => line.replace(/\n|\r/, ''));
442
+ if (exampleFileStrings.at(-1) === '') {
443
+ exampleFileStrings.splice(-1); // Remove newline at end of example file
444
+ }
445
+ const escapedExampleFileStrings = exampleFileStrings.map(line => line.replace(/\/\*/g, `/\\*`).replace(/\*\//g, `*\\/`));
446
+ metadataJson.has_comments = true;
447
+ metadataJson.examples.push({
448
+ name: exampleName,
449
+ code: {
450
+ text: exampleFileStrings,
451
+ escaped_text: escapedExampleFileStrings,
452
+ },
453
+ });
454
+ }
455
+ }
456
+ }
457
+ function addModuleDescriptions(fileLoader, moduleJson, allModules) {
458
+ moduleJson.examples = [];
459
+ moduleJson.has_comments = false;
460
+ const moduleFolder = moduleJson.name;
461
+ const infoPath = path_1.default.join(moduleFolder, 'info.json');
462
+ const infoJson = parseInfoJsonSafe(fileLoader, infoPath, semver_1.default.parse(moduleJson.version), MinecraftDocsTypes_1.ScriptCommonDocsValidator, MinecraftDocsTypes_1.ScriptNestedCommonDocsValidator);
463
+ const moduleDescription = getDescriptionOrTSDoc(moduleJson, infoJson);
464
+ if (moduleDescription) {
465
+ moduleJson.has_comments = true;
466
+ addDescriptionFields(moduleJson, moduleDescription, 'module_description', moduleJson, allModules);
467
+ }
468
+ addExamples(fileLoader, moduleJson, moduleFolder, moduleFolder);
469
+ }
470
+ function addFunctionDescriptions(fileLoader, functionJson, functionFolder, moduleJson, allModules) {
471
+ functionJson.examples = [];
472
+ functionJson.has_comments = false;
473
+ const infoPath = path_1.default.join(functionFolder, 'info.json');
474
+ const infoJson = parseInfoJsonSafe(fileLoader, infoPath, semver_1.default.parse(moduleJson.version), MinecraftDocsTypes_1.ScriptFunctionDocsValidator, MinecraftDocsTypes_1.ScriptNestedFunctionDocsValidator);
475
+ const functionDescription = getDescriptionOrTSDoc(functionJson, infoJson);
476
+ if (functionDescription) {
477
+ functionJson.has_comments = true;
478
+ addDescriptionFields(functionJson, functionDescription, 'function_description', moduleJson, allModules);
479
+ }
480
+ const deprecatedDescription = getDeprecatedDescriptionOrTSDoc(functionJson, infoJson);
481
+ if (deprecatedDescription) {
482
+ functionJson.has_comments = true;
483
+ addDescriptionFields(functionJson, deprecatedDescription, 'deprecated_description', moduleJson, allModules);
484
+ }
485
+ const throwsDescription = getThrowsDescriptionOrTSDoc(functionJson, infoJson);
486
+ if (throwsDescription) {
487
+ functionJson.has_comments = true;
488
+ addDescriptionFields(functionJson, throwsDescription, 'throws_description', moduleJson, allModules);
489
+ }
490
+ const returnsDescription = getReturnsDescriptionOrTSDoc(functionJson, infoJson);
491
+ if (returnsDescription) {
492
+ functionJson.has_comments = true;
493
+ addDescriptionFields(functionJson, returnsDescription, 'returns_description', moduleJson, allModules);
494
+ }
495
+ const argumentsDescriptions = new Map();
496
+ if (functionJson.raw_tsdoc_text) {
497
+ const argumentsRegExp = /@param\s(\w+?)\s-\s(.+?)\n/g;
498
+ let argumentsMatch = undefined;
499
+ do {
500
+ argumentsMatch = argumentsRegExp.exec(functionJson.raw_tsdoc_text);
501
+ if (argumentsMatch) {
502
+ argumentsDescriptions.set(argumentsMatch[1], splitStringByNewline(argumentsMatch[2]));
503
+ }
504
+ } while (argumentsMatch);
505
+ }
506
+ if (infoJson && infoJson.arguments) {
507
+ if (functionJson.arguments) {
508
+ for (const argumentJson of functionJson.arguments) {
509
+ const argumentInfoJson = infoJson.arguments[argumentJson.name];
510
+ if (argumentInfoJson) {
511
+ if (argumentInfoJson.description) {
512
+ argumentsDescriptions.set(argumentJson.name, splitStringByNewline(argumentInfoJson.description));
513
+ }
514
+ if (argumentInfoJson.valid_values) {
515
+ const validValues = [];
516
+ for (let i = 0; i < argumentInfoJson.valid_values.length; ++i) {
517
+ validValues.push({
518
+ argument_valid_value: argumentInfoJson.valid_values[i],
519
+ argument_valid_value_end: i >= argumentInfoJson.valid_values.length - 1,
520
+ });
521
+ }
522
+ argumentJson.argument_valid_values = validValues;
523
+ }
524
+ }
525
+ }
526
+ }
527
+ }
528
+ for (const argumentJson of functionJson.arguments) {
529
+ const argumentDescription = argumentsDescriptions.get(argumentJson.name);
530
+ if (argumentDescription) {
531
+ functionJson.has_comments = true;
532
+ argumentJson.has_comments = true;
533
+ addDescriptionFields(argumentJson, argumentDescription, 'argument_description', moduleJson, allModules);
534
+ }
535
+ }
536
+ addExamples(fileLoader, functionJson, functionFolder, moduleJson.name);
537
+ }
538
+ function addPropertyDescriptions(fileLoader, propertyJson, propertyFolder, moduleJson, allModules) {
539
+ propertyJson.examples = [];
540
+ propertyJson.has_comments = false;
541
+ const infoPath = path_1.default.join(propertyFolder, 'info.json');
542
+ const infoJson = parseInfoJsonSafe(fileLoader, infoPath, semver_1.default.parse(moduleJson.version), MinecraftDocsTypes_1.ScriptCommonDocsValidator, MinecraftDocsTypes_1.ScriptNestedCommonDocsValidator);
543
+ const propertyDescription = getDescriptionOrTSDoc(propertyJson, infoJson);
544
+ if (propertyDescription) {
545
+ propertyJson.has_comments = true;
546
+ addDescriptionFields(propertyJson, propertyDescription, 'property_description', moduleJson, allModules);
547
+ }
548
+ const deprecatedDescription = getDeprecatedDescriptionOrTSDoc(propertyJson, infoJson);
549
+ if (deprecatedDescription) {
550
+ propertyJson.has_comments = true;
551
+ addDescriptionFields(propertyJson, deprecatedDescription, 'deprecated_description', moduleJson, allModules);
552
+ }
553
+ const throwsDescription = getThrowsDescriptionOrTSDoc(propertyJson, infoJson);
554
+ if (throwsDescription) {
555
+ propertyJson.has_comments = true;
556
+ addDescriptionFields(propertyJson, throwsDescription, 'throws_description', moduleJson, allModules);
557
+ }
558
+ addExamples(fileLoader, propertyJson, propertyFolder, moduleJson.name);
559
+ }
560
+ function addClassDescriptions(fileLoader, classJson, moduleJson, allModules) {
561
+ classJson.examples = [];
562
+ classJson.has_comments = false;
563
+ const classFolder = path_1.default.join(moduleJson.name, classJson.name);
564
+ const infoPath = path_1.default.join(classFolder, 'info.json');
565
+ const infoJson = parseInfoJsonSafe(fileLoader, infoPath, semver_1.default.parse(moduleJson.version), MinecraftDocsTypes_1.ScriptCommonDocsValidator, MinecraftDocsTypes_1.ScriptNestedCommonDocsValidator);
566
+ const classDescription = getDescriptionOrTSDoc(classJson, infoJson);
567
+ if (classDescription) {
568
+ classJson.has_comments = true;
569
+ addDescriptionFields(classJson, classDescription, 'class_description', moduleJson, allModules);
570
+ }
571
+ const deprecatedDescription = getDeprecatedDescriptionOrTSDoc(classJson, infoJson);
572
+ if (deprecatedDescription) {
573
+ classJson.has_comments = true;
574
+ addDescriptionFields(classJson, deprecatedDescription, 'deprecated_description', moduleJson, allModules);
575
+ }
576
+ addExamples(fileLoader, classJson, classFolder, moduleJson.name);
577
+ if (classJson.properties) {
578
+ for (const propertyJson of classJson.properties) {
579
+ const constantFolder = path_1.default.join(classFolder, propertyJson.name);
580
+ addPropertyDescriptions(fileLoader, propertyJson, constantFolder, moduleJson, allModules);
581
+ }
582
+ }
583
+ if ((0, MinecraftScriptModule_1.hasConstants)(classJson)) {
584
+ for (const constantJson of classJson.constants) {
585
+ const constantFolder = path_1.default.join(classFolder, constantJson.name);
586
+ addPropertyDescriptions(fileLoader, constantJson, constantFolder, moduleJson, allModules);
587
+ }
588
+ }
589
+ if ((0, MinecraftScriptModule_1.hasFunctions)(classJson)) {
590
+ for (const functionJson of classJson.functions) {
591
+ const functionFolder = path_1.default.join(classFolder, functionJson.name);
592
+ addFunctionDescriptions(fileLoader, functionJson, functionFolder, moduleJson, allModules);
593
+ }
594
+ }
595
+ }
596
+ function addEnumDescriptions(fileLoader, enumJson, moduleJson, allModules) {
597
+ enumJson.examples = [];
598
+ enumJson.has_comments = false;
599
+ const enumFolder = path_1.default.join(moduleJson.name, enumJson.name);
600
+ const infoPath = path_1.default.join(enumFolder, 'info.json');
601
+ const infoJson = parseInfoJsonSafe(fileLoader, infoPath, semver_1.default.parse(moduleJson.version), MinecraftDocsTypes_1.ScriptCommonDocsValidator, MinecraftDocsTypes_1.ScriptNestedCommonDocsValidator);
602
+ const enumDescription = getDescriptionOrTSDoc(enumJson, infoJson);
603
+ if (enumDescription) {
604
+ enumJson.has_comments = true;
605
+ addDescriptionFields(enumJson, enumDescription, 'enum_description', moduleJson, allModules);
606
+ }
607
+ const deprecatedDescription = getDeprecatedDescriptionOrTSDoc(enumJson, infoJson);
608
+ if (deprecatedDescription) {
609
+ enumJson.has_comments = true;
610
+ addDescriptionFields(enumJson, deprecatedDescription, 'deprecated_description', moduleJson, allModules);
611
+ }
612
+ for (const constantJson of enumJson.constants) {
613
+ const constantFolder = path_1.default.join(enumFolder, constantJson.name);
614
+ addPropertyDescriptions(fileLoader, constantJson, constantFolder, moduleJson, allModules);
615
+ }
616
+ }
617
+ function addTypeAliasDescriptions(fileLoader, aliasJson, moduleJson, allModules) {
618
+ aliasJson.examples = [];
619
+ aliasJson.has_comments = false;
620
+ const aliasFolder = path_1.default.join(moduleJson.name, aliasJson.name);
621
+ const infoPath = path_1.default.join(aliasFolder, 'info.json');
622
+ const infoJson = parseInfoJsonSafe(fileLoader, infoPath, semver_1.default.parse(moduleJson.version), MinecraftDocsTypes_1.ScriptCommonDocsValidator, MinecraftDocsTypes_1.ScriptNestedCommonDocsValidator);
623
+ const aliasDescription = getDescriptionOrTSDoc(aliasJson, infoJson);
624
+ if (aliasDescription) {
625
+ aliasJson.has_comments = true;
626
+ addDescriptionFields(aliasJson, aliasDescription, 'alias_description', moduleJson, allModules);
627
+ }
628
+ const deprecatedDescription = getDeprecatedDescriptionOrTSDoc(aliasJson, infoJson);
629
+ if (deprecatedDescription) {
630
+ aliasJson.has_comments = true;
631
+ addDescriptionFields(aliasJson, deprecatedDescription, 'deprecated_description', moduleJson, allModules);
632
+ }
633
+ addExamples(fileLoader, aliasJson, aliasFolder, moduleJson.name);
634
+ }
635
+ function addCommandEnumDescriptions(fileLoader, enumJson, moduleFolderPath) {
636
+ enumJson.has_comments = false;
637
+ const enumName = enumJson.name;
638
+ const enumFolderPath = path_1.default.join(moduleFolderPath, 'command_enums', enumName);
639
+ const infoPath = path_1.default.join(enumFolderPath, 'info.json');
640
+ const infoJson = parseJsonSafe(fileLoader, infoPath, MinecraftDocsTypes_1.CommandEnumDocsValidator);
641
+ if (infoJson) {
642
+ if (infoJson.description) {
643
+ enumJson.has_comments = true;
644
+ enumJson.enum_description = splitStringByNewline(infoJson.description);
645
+ }
646
+ if (infoJson.values) {
647
+ for (const valueJson of enumJson.values) {
648
+ const valueInfoJson = infoJson.values.find(v => valueJson.value === v.name);
649
+ if (valueInfoJson && valueInfoJson.description) {
650
+ valueJson.has_comments = true;
651
+ valueJson.value_description = splitStringByNewline(valueInfoJson.description);
652
+ }
653
+ }
654
+ }
655
+ }
656
+ }
657
+ function addCommandTypeDescriptions(fileLoader, typeJson, moduleFolderPath) {
658
+ typeJson.has_comments = false;
659
+ const typeName = typeJson.name;
660
+ const typeFolderPath = path_1.default.join(moduleFolderPath, 'command_types', typeName);
661
+ const infoPath = path_1.default.join(typeFolderPath, 'info.json');
662
+ const infoJson = parseJsonSafe(fileLoader, infoPath, MinecraftDocsTypes_1.CommonDocsDescriptionValidator);
663
+ if (infoJson && infoJson.description) {
664
+ typeJson.has_comments = true;
665
+ typeJson.type_description = splitStringByNewline(infoJson.description);
666
+ }
667
+ }
668
+ function addCommandDescriptions(fileLoader, commandJson, moduleFolderPath) {
669
+ commandJson.has_comments = false;
670
+ const commandName = commandJson.name;
671
+ const commandFolderPath = path_1.default.join(moduleFolderPath, 'commands', commandName);
672
+ const infoPath = path_1.default.join(commandFolderPath, 'info.json');
673
+ const infoJson = parseJsonSafe(fileLoader, infoPath, MinecraftDocsTypes_1.CommandDocsValidator);
674
+ if (infoJson) {
675
+ if (infoJson.description) {
676
+ commandJson.has_comments = true;
677
+ commandJson.command_description = splitStringByNewline(infoJson.description);
678
+ }
679
+ if (infoJson.overloads) {
680
+ for (const overloadJson of commandJson.overloads) {
681
+ const overloadInfoJson = infoJson.overloads.find(o => Number(overloadJson.name) === o.id);
682
+ if (overloadInfoJson && overloadInfoJson.description) {
683
+ overloadJson.has_comments = true;
684
+ overloadJson.overload_description = splitStringByNewline(overloadInfoJson.description);
685
+ if (overloadInfoJson.header) {
686
+ overloadJson.overload_header = overloadInfoJson.header;
687
+ }
688
+ }
689
+ }
690
+ }
691
+ if (infoJson.arguments) {
692
+ for (const argumentJson of commandJson.arguments) {
693
+ const argInfoJson = infoJson.arguments.find(a => argumentJson.directory_name === a.name);
694
+ if (argInfoJson && argInfoJson.description) {
695
+ argumentJson.has_comments = true;
696
+ argumentJson.argument_description = splitStringByNewline(argInfoJson.description);
697
+ }
698
+ }
699
+ }
700
+ }
701
+ if (commandJson.command_enums) {
702
+ for (const enumJson of commandJson.command_enums) {
703
+ addCommandEnumDescriptions(fileLoader, enumJson, commandFolderPath);
704
+ }
705
+ }
706
+ }
707
+ function addBlockPropertyDescriptions(fileLoader, blockPropertyJson, moduleFolderPath) {
708
+ blockPropertyJson.has_comments = false;
709
+ const propertyName = blockPropertyJson.name;
710
+ const propertyFolderPath = path_1.default.join(moduleFolderPath, 'block_properties', propertyName);
711
+ const infoPath = path_1.default.join(propertyFolderPath, 'info.json');
712
+ const infoJson = parseJsonSafe(fileLoader, infoPath, MinecraftDocsTypes_1.BlockPropertyDocsValidator);
713
+ if (infoJson) {
714
+ if (infoJson.description) {
715
+ blockPropertyJson.has_comments = true;
716
+ blockPropertyJson.property_description = splitStringByNewline(infoJson.description);
717
+ }
718
+ blockPropertyJson.int_value_display_as_range = !!infoJson.int_value_display_as_range;
719
+ if (infoJson.values) {
720
+ for (const valueJson of blockPropertyJson.values) {
721
+ const valInfoJson = infoJson.values.find(v => valueJson.value === v.name);
722
+ if (valInfoJson && valInfoJson.description) {
723
+ valueJson.has_comments = true;
724
+ valueJson.value_description = splitStringByNewline(valInfoJson.description);
725
+ }
726
+ }
727
+ }
728
+ }
729
+ }
730
+ function addBlockDescriptions(fileLoader, blockJson, moduleFolderPath) {
731
+ blockJson.has_comments = false;
732
+ const blockName = blockJson.name;
733
+ const blockFolderPath = path_1.default.join(moduleFolderPath, 'blocks', blockName);
734
+ const infoPath = path_1.default.join(blockFolderPath, 'info.json');
735
+ const infoJson = parseJsonSafe(fileLoader, infoPath, MinecraftDocsTypes_1.BlockDocsValidator);
736
+ if (infoJson) {
737
+ if (infoJson.description) {
738
+ blockJson.has_comments = true;
739
+ blockJson.block_description = splitStringByNewline(infoJson.description);
740
+ }
741
+ if (infoJson.properties) {
742
+ for (const propJson of blockJson.properties) {
743
+ const propInfoJson = infoJson.properties.find(p => propJson.name === p.name);
744
+ if (propInfoJson && propInfoJson.description) {
745
+ propJson.has_comments = true;
746
+ propJson.property_description = splitStringByNewline(propInfoJson.description);
747
+ }
748
+ }
749
+ }
750
+ }
751
+ }
752
+ function getLatestDependentScriptModules(allModules, moduleJson) {
753
+ const dependentModules = allModules.filter(sm => {
754
+ if (sm === moduleJson) {
755
+ return true;
756
+ }
757
+ for (const dep of moduleJson.dependencies.concat(moduleJson.peer_dependencies)) {
758
+ if (dep.uuid === sm.uuid) {
759
+ for (const depVersion of dep.versions) {
760
+ if (semver_1.default.major(sm.version) === semver_1.default.major(depVersion.version)) {
761
+ return true;
762
+ }
763
+ }
764
+ }
765
+ }
766
+ return false;
767
+ });
768
+ return (0, MinecraftRelease_1.getLatestScriptModules)(dependentModules);
769
+ }
770
+ /**
771
+ * Process documentation files and add descriptions and examples to each API.
772
+ */
773
+ function addDescriptionsAndExamples(releases, fileLoader) {
774
+ if (!fileLoader) {
775
+ return;
776
+ }
777
+ for (const release of releases) {
778
+ for (const moduleJson of release.script_modules) {
779
+ const dependentModules = getLatestDependentScriptModules(release.script_modules, moduleJson);
780
+ addModuleDescriptions(fileLoader, moduleJson, dependentModules);
781
+ if (moduleJson.classes) {
782
+ for (const classJson of moduleJson.classes) {
783
+ addClassDescriptions(fileLoader, classJson, moduleJson, dependentModules);
784
+ }
785
+ }
786
+ if (moduleJson.interfaces) {
787
+ for (const interfaceJson of moduleJson.interfaces) {
788
+ addClassDescriptions(fileLoader, interfaceJson, moduleJson, dependentModules);
789
+ }
790
+ }
791
+ if (moduleJson.errors) {
792
+ for (const errorJson of moduleJson.errors) {
793
+ addClassDescriptions(fileLoader, errorJson, moduleJson, dependentModules);
794
+ }
795
+ }
796
+ if (moduleJson.type_aliases) {
797
+ for (const aliasJson of moduleJson.type_aliases) {
798
+ addTypeAliasDescriptions(fileLoader, aliasJson, moduleJson, dependentModules);
799
+ }
800
+ }
801
+ if (moduleJson.functions) {
802
+ for (const functionJson of moduleJson.functions) {
803
+ const functionFolder = path_1.default.join(moduleJson.name, functionJson.name);
804
+ addFunctionDescriptions(fileLoader, functionJson, functionFolder, moduleJson, dependentModules);
805
+ }
806
+ }
807
+ if (moduleJson.constants) {
808
+ for (const constantJson of moduleJson.constants) {
809
+ const constantFolder = path_1.default.join(moduleJson.name, constantJson.name);
810
+ addPropertyDescriptions(fileLoader, constantJson, constantFolder, moduleJson, dependentModules);
811
+ }
812
+ }
813
+ if (moduleJson.objects) {
814
+ for (const objectJson of moduleJson.objects) {
815
+ const objectFolder = path_1.default.join(moduleJson.name, objectJson.name);
816
+ addPropertyDescriptions(fileLoader, objectJson, objectFolder, moduleJson, dependentModules);
817
+ }
818
+ }
819
+ if (moduleJson.enums) {
820
+ for (const enumJson of moduleJson.enums) {
821
+ addEnumDescriptions(fileLoader, enumJson, moduleJson, dependentModules);
822
+ }
823
+ }
824
+ }
825
+ for (const moduleJson of release.command_modules) {
826
+ for (const commandJson of moduleJson.commands ?? []) {
827
+ addCommandDescriptions(fileLoader, commandJson, moduleJson.name);
828
+ }
829
+ for (const enumJson of moduleJson.command_enums ?? []) {
830
+ addCommandEnumDescriptions(fileLoader, enumJson, moduleJson.name);
831
+ }
832
+ for (const typeJson of moduleJson.command_types ?? []) {
833
+ addCommandTypeDescriptions(fileLoader, typeJson, moduleJson.name);
834
+ }
835
+ }
836
+ for (const moduleJson of release.block_modules) {
837
+ for (const dataItemsJson of moduleJson.data_items ?? []) {
838
+ addBlockDescriptions(fileLoader, dataItemsJson, moduleJson.name);
839
+ }
840
+ for (const blockPropertyJson of moduleJson.block_properties ?? []) {
841
+ addBlockPropertyDescriptions(fileLoader, blockPropertyJson, moduleJson.name);
842
+ }
843
+ }
844
+ }
845
+ }
846
+ function blockFilters(releases) {
847
+ for (const release of releases) {
848
+ for (const moduleJson of release.block_modules) {
849
+ moduleJson.data_items.forEach((dataItemsJson) => {
850
+ const split = dataItemsJson.name.split(':');
851
+ dataItemsJson.namespace = split[0];
852
+ dataItemsJson.name = split[1];
853
+ });
854
+ moduleJson.block_properties.forEach(blockPropertyJson => {
855
+ if (blockPropertyJson.type === 'int') {
856
+ blockPropertyJson.min_value = blockPropertyJson.values.at(0).value;
857
+ blockPropertyJson.max_value = blockPropertyJson.values.at(-1).value;
858
+ }
859
+ });
860
+ }
861
+ }
862
+ }
863
+ function markupCategoriesOnScriptModule(moduleJson) {
864
+ moduleJson.module_name = moduleJson.name;
865
+ if (moduleJson.constants) {
866
+ for (const constantJson of moduleJson.constants) {
867
+ constantJson.property_name = constantJson.name;
868
+ }
869
+ moduleJson.constants.sort(utils.nameSortComparer);
870
+ }
871
+ if (moduleJson.functions) {
872
+ for (const functionJson of moduleJson.functions) {
873
+ functionJson.function_name = functionJson.name;
874
+ }
875
+ moduleJson.functions.sort(utils.nameSortComparer);
876
+ }
877
+ if (moduleJson.type_aliases) {
878
+ for (const aliasJson of moduleJson.type_aliases) {
879
+ aliasJson.alias_name = aliasJson.name;
880
+ }
881
+ moduleJson.type_aliases.sort(utils.nameSortComparer);
882
+ }
883
+ if (moduleJson.classes) {
884
+ for (const classJson of moduleJson.classes) {
885
+ classJson.class_name = classJson.name;
886
+ if (classJson.properties) {
887
+ for (const propertyJson of classJson.properties) {
888
+ propertyJson.property_name = propertyJson.name;
889
+ }
890
+ classJson.properties.sort(utils.nameSortComparer);
891
+ }
892
+ if (classJson.constants) {
893
+ for (const constantJson of classJson.constants) {
894
+ constantJson.property_name = constantJson.name;
895
+ }
896
+ classJson.constants.sort(utils.nameSortComparer);
897
+ }
898
+ if (classJson.functions) {
899
+ for (const functionJson of classJson.functions) {
900
+ functionJson.function_name = functionJson.name;
901
+ }
902
+ classJson.functions.sort(utils.nameSortComparer);
903
+ }
904
+ }
905
+ moduleJson.classes.sort(utils.nameSortComparer);
906
+ }
907
+ if (moduleJson.interfaces) {
908
+ for (const interfaceJson of moduleJson.interfaces) {
909
+ interfaceJson.class_name = interfaceJson.name;
910
+ if (interfaceJson.properties) {
911
+ for (const propertyJson of interfaceJson.properties) {
912
+ propertyJson.property_name = propertyJson.name;
913
+ }
914
+ interfaceJson.properties.sort(utils.nameSortComparer);
915
+ }
916
+ if (interfaceJson.functions) {
917
+ for (const functionJson of interfaceJson.functions) {
918
+ functionJson.function_name = functionJson.name;
919
+ }
920
+ interfaceJson.functions.sort(utils.nameSortComparer);
921
+ }
922
+ }
923
+ moduleJson.interfaces.sort(utils.nameSortComparer);
924
+ }
925
+ if (moduleJson.enums) {
926
+ for (const enumJson of moduleJson.enums) {
927
+ enumJson.enum_name = enumJson.name;
928
+ enumJson.is_enum = true;
929
+ if (enumJson.constants) {
930
+ for (const constantJson of enumJson.constants) {
931
+ constantJson.property_name = constantJson.name;
932
+ }
933
+ enumJson.constants.sort((lhs, rhs) => {
934
+ if (typeof lhs.value === 'string' && typeof rhs.value === 'string') {
935
+ return lhs.value.localeCompare(rhs.value);
936
+ }
937
+ else {
938
+ return lhs.value - rhs.value;
939
+ }
940
+ });
941
+ }
942
+ }
943
+ moduleJson.enums.sort(utils.nameSortComparer);
944
+ }
945
+ if (moduleJson.errors) {
946
+ for (const errorJson of moduleJson.errors) {
947
+ errorJson.class_name = errorJson.name;
948
+ if (errorJson.properties) {
949
+ for (const propertyJson of errorJson.properties) {
950
+ propertyJson.property_name = propertyJson.name;
951
+ }
952
+ errorJson.properties.sort(utils.nameSortComparer);
953
+ }
954
+ }
955
+ moduleJson.errors.sort(utils.nameSortComparer);
956
+ }
957
+ }
958
+ function markupCategoriesOnCommandsModule(moduleJson) {
959
+ moduleJson.module_name = moduleJson.name;
960
+ if (moduleJson.commands) {
961
+ for (const commandJson of moduleJson.commands) {
962
+ commandJson.command_name = commandJson.name;
963
+ if (commandJson.overloads) {
964
+ for (const overloadJson of commandJson.overloads) {
965
+ for (const paramJson of overloadJson.params) {
966
+ paramJson.param_name = paramJson.type.is_keyword ? paramJson.type.keyword_name : paramJson.name;
967
+ }
968
+ }
969
+ }
970
+ if (commandJson.arguments) {
971
+ for (const paramJson of commandJson.arguments) {
972
+ paramJson.param_name = paramJson.type.is_keyword ? paramJson.type.keyword_name : paramJson.name;
973
+ }
974
+ commandJson.arguments.sort(utils.nameSortComparer);
975
+ }
976
+ if (commandJson.command_enums) {
977
+ for (const enumJson of commandJson.command_enums) {
978
+ enumJson.enum_name = enumJson.name;
979
+ }
980
+ commandJson.command_enums.sort(utils.nameSortComparer);
981
+ }
982
+ }
983
+ moduleJson.commands.sort(utils.nameSortComparer);
984
+ }
985
+ if (moduleJson.command_enums) {
986
+ for (const enumJson of moduleJson.command_enums) {
987
+ enumJson.enum_name = enumJson.name;
988
+ }
989
+ moduleJson.command_enums.sort(utils.nameSortComparer);
990
+ }
991
+ if (moduleJson.command_types) {
992
+ for (const typeJson of moduleJson.command_types) {
993
+ typeJson.type_name = typeJson.name;
994
+ }
995
+ moduleJson.command_types.sort(utils.nameSortComparer);
996
+ }
997
+ }
998
+ function markupCategoriesOnBlocksModule(moduleJson) {
999
+ moduleJson.module_name = moduleJson.name;
1000
+ if (moduleJson.data_items) {
1001
+ for (const blockJson of moduleJson.data_items) {
1002
+ blockJson.block_name = blockJson.name;
1003
+ }
1004
+ }
1005
+ if (moduleJson.block_properties) {
1006
+ for (const blockPropertyJson of moduleJson.block_properties) {
1007
+ blockPropertyJson.property_name = blockPropertyJson.name;
1008
+ }
1009
+ }
1010
+ }
1011
+ function markupCategories(releases) {
1012
+ for (const release of releases) {
1013
+ for (const moduleJson of release.script_modules) {
1014
+ markupCategoriesOnScriptModule(moduleJson);
1015
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(moduleJson)) {
1016
+ for (const changelog of moduleJson.changelog) {
1017
+ markupCategoriesOnScriptModule(changelog);
1018
+ }
1019
+ }
1020
+ }
1021
+ for (const moduleJson of release.command_modules) {
1022
+ markupCategoriesOnCommandsModule(moduleJson);
1023
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(moduleJson)) {
1024
+ for (const changelog of moduleJson.changelog) {
1025
+ markupCategoriesOnCommandsModule(changelog);
1026
+ }
1027
+ }
1028
+ }
1029
+ for (const moduleJson of release.block_modules) {
1030
+ markupCategoriesOnBlocksModule(moduleJson);
1031
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(moduleJson)) {
1032
+ for (const changelog of moduleJson.changelog) {
1033
+ markupCategoriesOnBlocksModule(changelog);
1034
+ }
1035
+ }
1036
+ }
1037
+ }
1038
+ }
1039
+ function constructors(releases) {
1040
+ const markConstructorsOnModule = (moduleJson) => {
1041
+ if (moduleJson.classes) {
1042
+ for (const classJson of moduleJson.classes) {
1043
+ if (classJson.functions) {
1044
+ for (const functionJson of classJson.functions) {
1045
+ if (functionJson.is_constructor) {
1046
+ functionJson.name = 'constructor';
1047
+ }
1048
+ if (functionJson.is_constructor) {
1049
+ classJson.has_constructor = true;
1050
+ }
1051
+ }
1052
+ }
1053
+ }
1054
+ }
1055
+ };
1056
+ for (const release of releases) {
1057
+ for (const scriptModule of release.script_modules) {
1058
+ markConstructorsOnModule(scriptModule);
1059
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(scriptModule)) {
1060
+ for (const changelog of scriptModule.changelog) {
1061
+ markConstructorsOnModule(changelog);
1062
+ }
1063
+ }
1064
+ }
1065
+ }
1066
+ }
1067
+ function markupLatestModules(releases) {
1068
+ for (const release of releases) {
1069
+ const latestModulesByUUID = {};
1070
+ for (const latestScriptModule of release.getLatestScriptModules()) {
1071
+ latestModulesByUUID[latestScriptModule.uuid] = latestScriptModule;
1072
+ latestScriptModule.is_latest_module = true;
1073
+ }
1074
+ for (const scriptModule of release.script_modules) {
1075
+ if (latestModulesByUUID[scriptModule.uuid]) {
1076
+ const latestScriptModule = latestModulesByUUID[scriptModule.uuid];
1077
+ const latestMajor = semver_1.default.major(latestScriptModule.version);
1078
+ if (semver_1.default.major(scriptModule.version) === latestMajor) {
1079
+ scriptModule.is_latest_major = true;
1080
+ }
1081
+ else {
1082
+ scriptModule.from_module.prior_version = `${semver_1.default.major(scriptModule.from_module.version)}.x.x`;
1083
+ }
1084
+ }
1085
+ for (const dep of scriptModule.dependencies.concat(scriptModule.peer_dependencies)) {
1086
+ if (!dep.is_vanilla_data && latestModulesByUUID[dep.uuid]) {
1087
+ const latestDependentModule = latestModulesByUUID[dep.uuid];
1088
+ const latestMajor = semver_1.default.major(latestDependentModule.version);
1089
+ if (semver_1.default.major(dep.from_module.version) === latestMajor) {
1090
+ dep.is_latest_major = true;
1091
+ }
1092
+ else {
1093
+ dep.from_module.prior_version = `${semver_1.default.major(dep.from_module.version)}.x.x`;
1094
+ }
1095
+ }
1096
+ }
1097
+ }
1098
+ }
1099
+ }
1100
+ /**
1101
+ * Marks up additional name field formats.
1102
+ */
1103
+ function markupNames(releases) {
1104
+ for (const release of releases) {
1105
+ for (const scriptModule of release.script_modules) {
1106
+ utils.scanObjectForMemberWithName(scriptModule, 'name', jsonObject => {
1107
+ const bookmarkName = jsonObject.name
1108
+ .replaceAll(' ', '-')
1109
+ .replaceAll('/', '-')
1110
+ .replaceAll('@', '')
1111
+ .toLowerCase();
1112
+ jsonObject.bookmark_name = bookmarkName;
1113
+ jsonObject.filepath_name = bookmarkName.startsWith('minecraft-')
1114
+ ? `minecraft/${bookmarkName.substring(10)}`
1115
+ : bookmarkName;
1116
+ jsonObject.variable_name = jsonObject.name
1117
+ .replaceAll('-', '')
1118
+ .replaceAll(' ', '')
1119
+ .replaceAll('@', '')
1120
+ .replaceAll('/', '')
1121
+ .toLowerCase();
1122
+ });
1123
+ scriptModule.from_module.folder_path = scriptModule.is_latest_major ? 'scriptapi' : 'priorscriptapi';
1124
+ if (!scriptModule.is_latest_major) {
1125
+ scriptModule.filepath_name += `-${semver_1.default.major(scriptModule.version)}xx`;
1126
+ }
1127
+ for (const dep of scriptModule.dependencies.concat(scriptModule.peer_dependencies)) {
1128
+ if (!dep.is_vanilla_data) {
1129
+ dep.from_module.folder_path = dep.is_latest_major ? 'scriptapi' : 'priorscriptapi';
1130
+ if (!dep.is_latest_major) {
1131
+ dep.filepath_name += `-${semver_1.default.major(dep.from_module.version)}xx`;
1132
+ }
1133
+ }
1134
+ }
1135
+ }
1136
+ }
1137
+ }
1138
+ /**
1139
+ * Marks up arrays of objects with 'index', 'order', 'is_first', 'is_last' for mustache template usage.
1140
+ */
1141
+ function arrayIndexes(releases) {
1142
+ for (const release of releases) {
1143
+ for (const module of release.getAllModules()) {
1144
+ utils.scanObjectForMemberArray(module, (jsonObject, memberName) => {
1145
+ const arrayJson = jsonObject[memberName];
1146
+ if (arrayJson.length !== 0) {
1147
+ if (typeof arrayJson[0] === 'object') {
1148
+ try {
1149
+ for (let i = 0; i < arrayJson.length; ++i) {
1150
+ const object = arrayJson[i];
1151
+ object.index = i;
1152
+ object.order = i + 1;
1153
+ object.is_first = i === 0;
1154
+ object.is_last = i === arrayJson.length - 1;
1155
+ }
1156
+ }
1157
+ catch (e) {
1158
+ if (e instanceof Error) {
1159
+ log.error(`Failed to assign lengths to array '${memberName}': ${e.message} @ ${e.stack}`);
1160
+ }
1161
+ }
1162
+ }
1163
+ }
1164
+ });
1165
+ }
1166
+ }
1167
+ }
1168
+ function typeAliasMarkup(releases) {
1169
+ const markTypeAlias = (typeAliasJson) => {
1170
+ typeAliasJson.alias_type = typeAliasJson.alias_type ?? MinecraftScriptModule_1.MinecraftTypeAliasTypes.ScriptGenerated;
1171
+ switch (typeAliasJson.alias_type) {
1172
+ case MinecraftScriptModule_1.MinecraftTypeAliasTypes.TypeMap: {
1173
+ typeAliasJson.is_type_map = true;
1174
+ const mappingsWithoutNamespacedKeys = [];
1175
+ for (const typeMappingJson of typeAliasJson.mappings ?? []) {
1176
+ const namespaceSepIndex = typeMappingJson.name.indexOf(':');
1177
+ if (namespaceSepIndex !== -1) {
1178
+ const keyWithoutNamespace = typeMappingJson.name.substring(namespaceSepIndex + 1);
1179
+ const typeMappingJsonCopy = JSON.parse(JSON.stringify(typeMappingJson));
1180
+ typeMappingJsonCopy.name = keyWithoutNamespace;
1181
+ mappingsWithoutNamespacedKeys.push(typeMappingJsonCopy);
1182
+ }
1183
+ }
1184
+ typeAliasJson.mappings = typeAliasJson.mappings
1185
+ .concat(mappingsWithoutNamespacedKeys)
1186
+ .sort(utils.nameSortComparer);
1187
+ break;
1188
+ }
1189
+ default: {
1190
+ if (!typeAliasJson.is_script_generated) {
1191
+ throw new Error(`Native type alias without 'alias_type' not supported.`);
1192
+ }
1193
+ }
1194
+ }
1195
+ };
1196
+ for (const release of releases) {
1197
+ for (const moduleJson of release.script_modules) {
1198
+ for (const typeAliasJson of moduleJson.type_aliases ?? []) {
1199
+ markTypeAlias(typeAliasJson);
1200
+ }
1201
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(moduleJson)) {
1202
+ for (const changelog of moduleJson.changelog) {
1203
+ for (const typeAliasJson of changelog.type_aliases ?? []) {
1204
+ markTypeAlias(typeAliasJson);
1205
+ }
1206
+ }
1207
+ }
1208
+ }
1209
+ }
1210
+ }
1211
+ /**
1212
+ * Adds 'is_<type>' flags to APIs based on the type field.
1213
+ */
1214
+ function typeFlags(releases) {
1215
+ const fixType = (typeJson) => {
1216
+ typeJson.is_string = typeJson.is_string ?? false;
1217
+ typeJson.is_undefined = typeJson.is_undefined ?? false;
1218
+ typeJson.is_any = typeJson.is_any ?? false;
1219
+ typeJson.is_closure = typeJson.is_closure ?? false;
1220
+ typeJson.is_array = typeJson.is_array ?? false;
1221
+ typeJson.is_promise = typeJson.is_promise ?? false;
1222
+ typeJson.is_variant = typeJson.is_variant ?? false;
1223
+ typeJson.is_optional_type = typeJson.is_optional_type ?? false;
1224
+ typeJson.is_optional = typeJson.is_optional ?? false;
1225
+ typeJson.is_iterator = typeJson.is_iterator ?? false;
1226
+ typeJson.is_iterator_result = typeJson.is_iterator_result ?? false;
1227
+ typeJson.is_map = typeJson.is_map ?? false;
1228
+ typeJson.is_generator = typeJson.is_generator ?? false;
1229
+ typeJson.is_data_buffer = typeJson.is_data_buffer ?? false;
1230
+ if (typeJson.name === 'string') {
1231
+ typeJson.is_string = true;
1232
+ }
1233
+ else if (typeJson.name === 'undefined') {
1234
+ typeJson.is_undefined = true;
1235
+ }
1236
+ else if (typeJson.name === 'any') {
1237
+ typeJson.is_any = true;
1238
+ }
1239
+ else if (typeJson.name === 'closure') {
1240
+ typeJson.is_closure = true;
1241
+ }
1242
+ else if (typeJson.name === 'array') {
1243
+ typeJson.is_array = true;
1244
+ }
1245
+ else if (typeJson.name === 'promise') {
1246
+ typeJson.is_promise = true;
1247
+ }
1248
+ else if (typeJson.name === 'variant') {
1249
+ typeJson.is_variant = true;
1250
+ }
1251
+ else if (typeJson.name === 'optional') {
1252
+ typeJson.is_optional_type = true;
1253
+ typeJson.is_optional = true;
1254
+ }
1255
+ else if (typeJson.name === 'iterator_result') {
1256
+ typeJson.is_iterator_result = true;
1257
+ }
1258
+ else if (typeJson.name === 'iterator') {
1259
+ typeJson.is_iterator = true;
1260
+ }
1261
+ else if (typeJson.name === 'map') {
1262
+ typeJson.is_map = true;
1263
+ }
1264
+ else if (typeJson.name === 'generator') {
1265
+ typeJson.is_generator = true;
1266
+ }
1267
+ else if (typeJson.name === 'data_buffer') {
1268
+ typeJson.is_data_buffer = true;
1269
+ }
1270
+ };
1271
+ for (const release of releases) {
1272
+ for (const scriptModule of release.script_modules) {
1273
+ utils.scanObjectForMemberWithAnyNamesFromList(scriptModule, MinecraftScriptModule_1.MinecraftTypeKeyList, (jsonObject, propertyName) => {
1274
+ const typeJson = jsonObject[propertyName];
1275
+ if (Array.isArray(typeJson)) {
1276
+ typeJson.forEach(fixType);
1277
+ }
1278
+ else {
1279
+ fixType(typeJson);
1280
+ }
1281
+ });
1282
+ }
1283
+ }
1284
+ }
1285
+ /**
1286
+ * Marks up APIs that have default values with 'has_defaults'.
1287
+ */
1288
+ function defaultValues(releases) {
1289
+ for (const release of releases) {
1290
+ for (const scriptModule of release.script_modules) {
1291
+ for (const classJson of scriptModule.classes ?? []) {
1292
+ for (const functionJson of classJson.functions ?? []) {
1293
+ for (const argumentJson of functionJson.arguments) {
1294
+ if (!argumentJson.details) {
1295
+ continue;
1296
+ }
1297
+ if (argumentJson.details.default_value !== undefined) {
1298
+ argumentJson.type.is_optional = true;
1299
+ if (argumentJson.details.default_value !== 'null') {
1300
+ functionJson.has_defaults = true;
1301
+ argumentJson.has_defaults = true;
1302
+ }
1303
+ if (Array.isArray(argumentJson.details.default_value)) {
1304
+ const wrappedDefaultValue = [];
1305
+ for (const v of argumentJson.details.default_value) {
1306
+ wrappedDefaultValue.push({ value: v });
1307
+ }
1308
+ argumentJson.details.default_value = wrappedDefaultValue;
1309
+ }
1310
+ argumentJson.details.default_value = {
1311
+ type: JSON.parse(JSON.stringify(argumentJson.type)),
1312
+ value: argumentJson.details.default_value,
1313
+ };
1314
+ }
1315
+ if (argumentJson.details.supported_values !== undefined) {
1316
+ if (Array.isArray(argumentJson.details.supported_values)) {
1317
+ const wrappedSupportedValues = [];
1318
+ for (const v of argumentJson.details.supported_values) {
1319
+ wrappedSupportedValues.push({ value: v });
1320
+ }
1321
+ argumentJson.details.supported_values = wrappedSupportedValues;
1322
+ }
1323
+ }
1324
+ }
1325
+ }
1326
+ }
1327
+ // Interface property defaults
1328
+ for (const interfaceJson of scriptModule.interfaces ?? []) {
1329
+ for (const propertyJson of interfaceJson.properties ?? []) {
1330
+ if (propertyJson.default_value !== undefined) {
1331
+ propertyJson.type.is_optional = true;
1332
+ if (propertyJson.default_value !== 'null') {
1333
+ propertyJson.has_defaults = true;
1334
+ }
1335
+ if (Array.isArray(propertyJson.default_value)) {
1336
+ const wrappedDefaultValue = [];
1337
+ for (const v of propertyJson.default_value) {
1338
+ wrappedDefaultValue.push({ value: v });
1339
+ }
1340
+ propertyJson.default_value = wrappedDefaultValue;
1341
+ }
1342
+ propertyJson.default_value = {
1343
+ type: JSON.parse(JSON.stringify(propertyJson.type)),
1344
+ value: propertyJson.default_value,
1345
+ };
1346
+ }
1347
+ }
1348
+ }
1349
+ }
1350
+ }
1351
+ }
1352
+ function constantValues(releases) {
1353
+ const markupConstantValueObjects = (constants) => {
1354
+ for (const constantJson of constants) {
1355
+ // eslint-disable-next-line eqeqeq, unicorn/no-null
1356
+ if (constantJson.is_static && constantJson.value != null) {
1357
+ constantJson.constant_value = { value: constantJson.value };
1358
+ }
1359
+ }
1360
+ };
1361
+ const markConstantValuesOnModule = (moduleJson) => {
1362
+ if (moduleJson.constants) {
1363
+ markupConstantValueObjects(moduleJson.constants);
1364
+ }
1365
+ if (moduleJson.classes) {
1366
+ for (const classJson of moduleJson.classes) {
1367
+ if (classJson.constants) {
1368
+ markupConstantValueObjects(classJson.constants);
1369
+ }
1370
+ }
1371
+ }
1372
+ if (moduleJson.enums) {
1373
+ for (const enumJson of moduleJson.enums) {
1374
+ markupConstantValueObjects(enumJson.constants);
1375
+ }
1376
+ }
1377
+ };
1378
+ for (const release of releases) {
1379
+ for (const scriptModule of release.script_modules) {
1380
+ markConstantValuesOnModule(scriptModule);
1381
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(scriptModule)) {
1382
+ for (const changelog of scriptModule.changelog) {
1383
+ markConstantValuesOnModule(changelog);
1384
+ }
1385
+ }
1386
+ }
1387
+ }
1388
+ }
1389
+ /**
1390
+ * Populates 'derived_types' in order to be able to add links to derived APIs.
1391
+ */
1392
+ function linkDerivedTypes(releases) {
1393
+ for (const release of releases) {
1394
+ release.script_modules.forEach(moduleJson => {
1395
+ moduleJson.classes.forEach(classJson => {
1396
+ if (classJson.base_types) {
1397
+ classJson.base_types.forEach(baseTypeJson => {
1398
+ let foundBaseClassJson = false;
1399
+ const baseTypeModule = baseTypeJson.from_module ?? moduleJson;
1400
+ release.script_modules.forEach(baseClassModuleJson => {
1401
+ if (baseClassModuleJson.uuid === baseTypeModule.uuid &&
1402
+ semver_1.default.major(baseClassModuleJson.version) === semver_1.default.major(baseTypeModule.version) &&
1403
+ semver_1.default.minor(baseClassModuleJson.version) >= semver_1.default.minor(baseTypeModule.version)) {
1404
+ baseClassModuleJson.classes.forEach(baseTypeClassJson => {
1405
+ if (baseTypeJson.name === baseTypeClassJson.name) {
1406
+ if (!baseTypeClassJson.derived_types) {
1407
+ baseTypeClassJson.derived_types = [];
1408
+ }
1409
+ const copiedDerivedType = JSON.parse(JSON.stringify(classJson.type));
1410
+ copiedDerivedType.from_module = {
1411
+ name: moduleJson.name,
1412
+ uuid: moduleJson.uuid,
1413
+ version: moduleJson.version,
1414
+ };
1415
+ if (!baseTypeClassJson.derived_types.some(derived_type => derived_type.name === copiedDerivedType.name &&
1416
+ derived_type.from_module.name === moduleJson.name)) {
1417
+ baseTypeClassJson.derived_types.push(copiedDerivedType);
1418
+ }
1419
+ foundBaseClassJson = true;
1420
+ }
1421
+ });
1422
+ }
1423
+ });
1424
+ if (!foundBaseClassJson) {
1425
+ log.warn(`Failed to find base class '${baseTypeJson.name}' in module '${baseTypeModule.name}@${baseTypeModule.version}' for class '${classJson.name}'.`);
1426
+ }
1427
+ });
1428
+ }
1429
+ });
1430
+ });
1431
+ }
1432
+ }
1433
+ function fromExternalModule(releases) {
1434
+ for (const release of releases) {
1435
+ for (const scriptModule of release.script_modules) {
1436
+ utils.scanObjectForMemberWithName(scriptModule, 'from_module', (jsonObject) => {
1437
+ const fromModule = jsonObject.from_module;
1438
+ fromModule.is_external_module = fromModule.uuid !== scriptModule.uuid;
1439
+ });
1440
+ }
1441
+ }
1442
+ }
1443
+ /**
1444
+ * Add 'from_module' to dependency objects so that they can be marked up.
1445
+ */
1446
+ function addFromModuleToDependencies(releases) {
1447
+ for (const release of releases) {
1448
+ for (const scriptModule of release.script_modules) {
1449
+ for (const dep of scriptModule.dependencies.concat(scriptModule.peer_dependencies)) {
1450
+ const sortedVersions = dep.versions.toSorted(utils.reverseSemVerSortComparer('version'));
1451
+ const latestVersion = sortedVersions[0].version;
1452
+ dep.from_module = {
1453
+ name: dep.name,
1454
+ uuid: dep.uuid,
1455
+ version: latestVersion,
1456
+ };
1457
+ dep.is_vanilla_data = dep.name === '@minecraft/vanilla-data';
1458
+ for (const version of dep.versions) {
1459
+ version.version_selector = !dep.is_vanilla_data
1460
+ ? '^'
1461
+ : !semver_1.default.prerelease(version.version)
1462
+ ? '>='
1463
+ : undefined;
1464
+ }
1465
+ }
1466
+ }
1467
+ }
1468
+ }
1469
+ /**
1470
+ * Aligns 'from_module' for types with the module that the script module actually depends on.
1471
+ *
1472
+ * This is for the case where gametest depends on server's vector3, which came out in 1.x.x. Rather than
1473
+ * linking gametest to server 1.x.x's vector3, we want to link to the version of server that gametest
1474
+ * depends on.
1475
+ */
1476
+ function setFromModuleToDependentModules(releases) {
1477
+ const ignoredTypes = ['Error'];
1478
+ for (const release of releases) {
1479
+ for (const scriptModule of release.script_modules) {
1480
+ const dependentModules = getLatestDependentScriptModules(release.script_modules, scriptModule);
1481
+ const dependentModulesByUUID = {};
1482
+ for (const latestModule of dependentModules) {
1483
+ dependentModulesByUUID[latestModule.uuid] = latestModule;
1484
+ }
1485
+ utils.scanObjectForMembersWithNamesNoChangelog(scriptModule, 'name', 'from_module', (jsonObject) => {
1486
+ const name = jsonObject.name;
1487
+ if (name === scriptModule.name || ignoredTypes.includes(name)) {
1488
+ return;
1489
+ }
1490
+ const dependentModule = dependentModulesByUUID[jsonObject.from_module.uuid];
1491
+ if (!dependentModule) {
1492
+ log.printOption(`Failed to find dependent module '${jsonObject.from_module.name}@${jsonObject.from_module.version}' for '${scriptModule.name}@${scriptModule.version}'.`, 'unresolvedDependencies');
1493
+ return;
1494
+ }
1495
+ if (name === dependentModule.name) {
1496
+ return;
1497
+ }
1498
+ for (const c of [
1499
+ dependentModule.classes,
1500
+ dependentModule.interfaces,
1501
+ dependentModule.errors,
1502
+ dependentModule.enums,
1503
+ dependentModule.type_aliases,
1504
+ ]) {
1505
+ for (const named of c) {
1506
+ if (named.name === name) {
1507
+ jsonObject.from_module.name = dependentModule.name;
1508
+ jsonObject.from_module.version = dependentModule.version;
1509
+ return;
1510
+ }
1511
+ }
1512
+ }
1513
+ log.printOption(`Could not find type '${name}' but '${scriptModule.name}@${scriptModule.version}' depends on it.`, 'unresolvedTypes');
1514
+ });
1515
+ }
1516
+ }
1517
+ }
1518
+ /**
1519
+ * Nest changed type values in an object with the same key so other filters fix them up.
1520
+ */
1521
+ function nestChangedTypes(releases) {
1522
+ for (const release of releases) {
1523
+ for (const scriptModule of release.script_modules) {
1524
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(scriptModule)) {
1525
+ for (const changelog of scriptModule.changelog) {
1526
+ utils.scanObjectForMemberWithAnyNamesFromList(changelog, MinecraftScriptModule_1.MinecraftTypeKeyList, (jsonObject, propertyName) => {
1527
+ const typeJson = jsonObject[propertyName];
1528
+ // Determines if type object has been modified by changelogging
1529
+ if (typeof typeJson === 'object' && (0, MinecraftChangelogTypes_1.isValueChangelogEntry)(typeJson)) {
1530
+ typeJson.$old = {
1531
+ [propertyName]: typeJson.$old,
1532
+ };
1533
+ typeJson.$new = {
1534
+ [propertyName]: typeJson.$new,
1535
+ };
1536
+ }
1537
+ });
1538
+ }
1539
+ }
1540
+ }
1541
+ }
1542
+ }
1543
+ const CHANGELOG_KEYS = ['$changed', '$added', '$removed'];
1544
+ function flagChanges(rootJson, jsonToApplyChangeFlag) {
1545
+ rootJson.has_changes = rootJson.has_changes ?? false;
1546
+ for (const changelogKey of CHANGELOG_KEYS) {
1547
+ rootJson[changelogKey] = rootJson[changelogKey] ?? false;
1548
+ }
1549
+ if (jsonToApplyChangeFlag && jsonToApplyChangeFlag.length > 0) {
1550
+ utils.scanObjectForMemberWithAnyNamesFromList(rootJson, CHANGELOG_KEYS, (changedObjectJson, propertyName) => {
1551
+ for (const objectJson of jsonToApplyChangeFlag) {
1552
+ objectJson.has_changes = objectJson.has_changes || changedObjectJson[propertyName] !== false;
1553
+ }
1554
+ });
1555
+ }
1556
+ }
1557
+ function flagArraySubmemberChanges(jsonObject, memberName, jsonHierarchy) {
1558
+ if (jsonObject[memberName] === undefined) {
1559
+ jsonObject[memberName] = [];
1560
+ }
1561
+ const objectArray = jsonObject[memberName];
1562
+ if (Array.isArray(objectArray)) {
1563
+ for (const submemberJson of objectArray) {
1564
+ flagChanges(submemberJson, [submemberJson, ...jsonHierarchy]);
1565
+ }
1566
+ }
1567
+ }
1568
+ function flagSimpleOrderedArraySubmemberChanges(jsonObject, memberName) {
1569
+ const obj = jsonObject[memberName];
1570
+ if (!obj || (Array.isArray(obj) && obj.length === 0)) {
1571
+ jsonObject[memberName] = {
1572
+ array: [],
1573
+ $changed: false,
1574
+ };
1575
+ }
1576
+ else {
1577
+ if (typeof obj === 'object' && '$old' in obj && '$new' in obj && '$key' in obj) {
1578
+ jsonObject[memberName] = {
1579
+ $changed: true,
1580
+ array: utils.diffArray(obj.$old, obj.$new, obj.$key),
1581
+ };
1582
+ }
1583
+ }
1584
+ }
1585
+ function flagValueSubmemberChanges(jsonObject, memberName, jsonHierarchy) {
1586
+ if (jsonObject[memberName] === undefined) {
1587
+ jsonObject[memberName] = {};
1588
+ }
1589
+ flagChanges(jsonObject, [jsonObject, ...jsonHierarchy]);
1590
+ }
1591
+ /**
1592
+ * Marks up APIs that have changelog changes with 'has_changes', moving up the metadata
1593
+ * hierarchy to mark up to the module containing that API.
1594
+ */
1595
+ function flagChangelogChanges(releases) {
1596
+ for (const release of releases) {
1597
+ const afterEventsOrderingModule = (0, MinecraftAfterEventsOrderModule_1.getAfterEventsOrderingModuleFrom)(release.engine_data_modules);
1598
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(afterEventsOrderingModule)) {
1599
+ flagChanges(afterEventsOrderingModule);
1600
+ for (const changelogModuleJson of afterEventsOrderingModule.changelog) {
1601
+ flagArraySubmemberChanges(changelogModuleJson, 'after_events_order_by_version', [changelogModuleJson]);
1602
+ for (const orderJson of changelogModuleJson.after_events_order_by_version) {
1603
+ flagSimpleOrderedArraySubmemberChanges(orderJson, 'event_order');
1604
+ }
1605
+ }
1606
+ }
1607
+ for (const scriptModule of release.script_modules) {
1608
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(scriptModule)) {
1609
+ flagChanges(scriptModule);
1610
+ for (const changelogModuleJson of scriptModule.changelog) {
1611
+ flagArraySubmemberChanges(changelogModuleJson, 'dependencies', [changelogModuleJson]);
1612
+ for (const dependencyJson of changelogModuleJson.dependencies) {
1613
+ flagArraySubmemberChanges(dependencyJson, 'versions', [changelogModuleJson, dependencyJson]);
1614
+ }
1615
+ flagArraySubmemberChanges(changelogModuleJson, 'peer_dependencies', [changelogModuleJson]);
1616
+ for (const dependencyJson of changelogModuleJson.peer_dependencies) {
1617
+ flagArraySubmemberChanges(dependencyJson, 'versions', [changelogModuleJson, dependencyJson]);
1618
+ flagValueSubmemberChanges(dependencyJson, 'types_only', [changelogModuleJson, dependencyJson]);
1619
+ }
1620
+ flagArraySubmemberChanges(changelogModuleJson, 'constants', [changelogModuleJson]);
1621
+ for (const constantJson of changelogModuleJson.constants) {
1622
+ flagValueSubmemberChanges(constantJson, 'value', [changelogModuleJson]);
1623
+ }
1624
+ flagArraySubmemberChanges(changelogModuleJson, 'functions', [changelogModuleJson]);
1625
+ for (const functionJson of changelogModuleJson.functions) {
1626
+ flagArraySubmemberChanges(functionJson, 'arguments', [changelogModuleJson, functionJson]);
1627
+ for (const argumentJson of functionJson.arguments) {
1628
+ flagValueSubmemberChanges(argumentJson, 'type', [changelogModuleJson, functionJson]);
1629
+ }
1630
+ flagValueSubmemberChanges(functionJson, 'return_type', [changelogModuleJson]);
1631
+ flagValueSubmemberChanges(functionJson, 'call_privilege', [changelogModuleJson]);
1632
+ }
1633
+ flagArraySubmemberChanges(changelogModuleJson, 'classes', [changelogModuleJson]);
1634
+ for (const classJson of changelogModuleJson.classes) {
1635
+ flagArraySubmemberChanges(classJson, 'properties', [changelogModuleJson, classJson]);
1636
+ for (const propertyJson of classJson.properties) {
1637
+ flagValueSubmemberChanges(propertyJson, 'type', [changelogModuleJson, classJson]);
1638
+ flagValueSubmemberChanges(propertyJson, 'get_privilege', [changelogModuleJson, classJson]);
1639
+ flagValueSubmemberChanges(propertyJson, 'set_privilege', [changelogModuleJson, classJson]);
1640
+ }
1641
+ flagArraySubmemberChanges(classJson, 'constants', [changelogModuleJson, classJson]);
1642
+ for (const constantJson of classJson.constants) {
1643
+ flagValueSubmemberChanges(constantJson, 'value', [changelogModuleJson, classJson]);
1644
+ }
1645
+ flagArraySubmemberChanges(classJson, 'functions', [changelogModuleJson, classJson]);
1646
+ for (const functionJson of classJson.functions) {
1647
+ flagArraySubmemberChanges(functionJson, 'arguments', [
1648
+ changelogModuleJson,
1649
+ classJson,
1650
+ functionJson,
1651
+ ]);
1652
+ for (const argumentJson of functionJson.arguments) {
1653
+ flagValueSubmemberChanges(argumentJson, 'type', [
1654
+ changelogModuleJson,
1655
+ classJson,
1656
+ functionJson,
1657
+ ]);
1658
+ }
1659
+ flagValueSubmemberChanges(functionJson, 'return_type', [changelogModuleJson, classJson]);
1660
+ flagValueSubmemberChanges(functionJson, 'call_privilege', [changelogModuleJson, classJson]);
1661
+ }
1662
+ }
1663
+ flagArraySubmemberChanges(changelogModuleJson, 'interfaces', [changelogModuleJson]);
1664
+ for (const interfaceJson of changelogModuleJson.interfaces) {
1665
+ flagArraySubmemberChanges(interfaceJson, 'properties', [changelogModuleJson, interfaceJson]);
1666
+ }
1667
+ flagArraySubmemberChanges(changelogModuleJson, 'errors', [changelogModuleJson]);
1668
+ for (const errorJson of changelogModuleJson.errors) {
1669
+ flagArraySubmemberChanges(errorJson, 'properties', [changelogModuleJson, errorJson]);
1670
+ for (const propertyJson of errorJson.properties) {
1671
+ flagValueSubmemberChanges(propertyJson, 'get_privilege', [changelogModuleJson, errorJson]);
1672
+ flagValueSubmemberChanges(propertyJson, 'set_privilege', [changelogModuleJson, errorJson]);
1673
+ }
1674
+ }
1675
+ flagArraySubmemberChanges(changelogModuleJson, 'objects', [changelogModuleJson]);
1676
+ for (const objectJson of changelogModuleJson.objects) {
1677
+ flagValueSubmemberChanges(objectJson, 'type', [changelogModuleJson]);
1678
+ }
1679
+ flagArraySubmemberChanges(changelogModuleJson, 'enums', [changelogModuleJson]);
1680
+ for (const enumJson of changelogModuleJson.enums) {
1681
+ flagArraySubmemberChanges(enumJson, 'constants', [changelogModuleJson, enumJson]);
1682
+ for (const constantJson of enumJson.constants) {
1683
+ flagValueSubmemberChanges(constantJson, 'value', [changelogModuleJson, enumJson]);
1684
+ }
1685
+ }
1686
+ flagArraySubmemberChanges(changelogModuleJson, 'type_aliases', [changelogModuleJson]);
1687
+ for (const typeJson of changelogModuleJson.type_aliases) {
1688
+ flagValueSubmemberChanges(typeJson, 'type', [changelogModuleJson]);
1689
+ for (const mappingJson of typeJson.mappings ?? []) {
1690
+ flagValueSubmemberChanges(mappingJson, 'value', [changelogModuleJson, typeJson]);
1691
+ }
1692
+ }
1693
+ }
1694
+ }
1695
+ }
1696
+ for (const commandModule of release.command_modules) {
1697
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(commandModule)) {
1698
+ flagChanges(commandModule);
1699
+ for (const changelogModuleJson of commandModule.changelog) {
1700
+ flagArraySubmemberChanges(changelogModuleJson, 'commands', [changelogModuleJson]);
1701
+ flagArraySubmemberChanges(changelogModuleJson, 'command_enums', [changelogModuleJson]);
1702
+ for (const commandJson of changelogModuleJson.commands) {
1703
+ flagChanges(commandJson, [changelogModuleJson, commandJson]);
1704
+ flagArraySubmemberChanges(commandJson, 'aliases', [changelogModuleJson, commandJson]);
1705
+ for (const aliasJson of commandJson.aliases) {
1706
+ flagValueSubmemberChanges(aliasJson, 'name', [changelogModuleJson, commandJson]);
1707
+ }
1708
+ flagArraySubmemberChanges(commandJson, 'overloads', [changelogModuleJson, commandJson]);
1709
+ for (const overloadJson of commandJson.overloads) {
1710
+ flagArraySubmemberChanges(overloadJson, 'params', [changelogModuleJson, commandJson]);
1711
+ for (const paramJson of overloadJson.params) {
1712
+ flagValueSubmemberChanges(paramJson, 'type', [
1713
+ changelogModuleJson,
1714
+ commandJson,
1715
+ overloadJson,
1716
+ ]);
1717
+ flagValueSubmemberChanges(paramJson, 'is_optional', [
1718
+ changelogModuleJson,
1719
+ commandJson,
1720
+ overloadJson,
1721
+ ]);
1722
+ }
1723
+ }
1724
+ flagValueSubmemberChanges(commandJson, 'permission_level', [changelogModuleJson, commandJson]);
1725
+ flagValueSubmemberChanges(commandJson, 'requires_cheats', [changelogModuleJson, commandJson]);
1726
+ }
1727
+ }
1728
+ }
1729
+ }
1730
+ for (const vanillaDataModule of release.vanilla_data_modules) {
1731
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(vanillaDataModule)) {
1732
+ flagChanges(vanillaDataModule);
1733
+ for (const changelogModuleJson of vanillaDataModule.changelog) {
1734
+ flagArraySubmemberChanges(changelogModuleJson, 'data_items', [
1735
+ vanillaDataModule,
1736
+ changelogModuleJson,
1737
+ ]);
1738
+ for (const dataItemJson of changelogModuleJson.data_items) {
1739
+ flagValueSubmemberChanges(dataItemJson, 'name', [vanillaDataModule, changelogModuleJson]);
1740
+ if (vanillaDataModule.has_properties) {
1741
+ flagArraySubmemberChanges(dataItemJson, 'properties', [
1742
+ vanillaDataModule,
1743
+ changelogModuleJson,
1744
+ ]);
1745
+ for (const propertyJson of dataItemJson.properties) {
1746
+ flagValueSubmemberChanges(propertyJson, 'properties', [
1747
+ vanillaDataModule,
1748
+ changelogModuleJson,
1749
+ dataItemJson,
1750
+ ]);
1751
+ }
1752
+ }
1753
+ }
1754
+ if (vanillaDataModule.name === 'mojang-block') {
1755
+ flagArraySubmemberChanges(changelogModuleJson, 'block_properties', [
1756
+ vanillaDataModule,
1757
+ changelogModuleJson,
1758
+ ]);
1759
+ for (const blockPropJson of vanillaDataModule.block_properties) {
1760
+ flagValueSubmemberChanges(blockPropJson, 'type', [
1761
+ vanillaDataModule,
1762
+ changelogModuleJson,
1763
+ blockPropJson,
1764
+ ]);
1765
+ flagArraySubmemberChanges(blockPropJson, 'values', [
1766
+ vanillaDataModule,
1767
+ changelogModuleJson,
1768
+ blockPropJson,
1769
+ ]);
1770
+ }
1771
+ }
1772
+ }
1773
+ }
1774
+ }
1775
+ }
1776
+ }
1777
+ function markObjectAsErrorable(metadataJson) {
1778
+ metadataJson.has_errors = metadataJson.has_errors ?? false;
1779
+ if ('type' in metadataJson) {
1780
+ if (metadataJson.type.is_errorable) {
1781
+ metadataJson.has_errors = true;
1782
+ }
1783
+ }
1784
+ else if ('return_type' in metadataJson) {
1785
+ if (metadataJson.return_type.is_errorable) {
1786
+ metadataJson.has_errors = true;
1787
+ }
1788
+ }
1789
+ }
1790
+ /**
1791
+ * Marks up 'has_errors' on APIs that have errorable types.
1792
+ */
1793
+ function markErrorable(releases) {
1794
+ for (const release of releases) {
1795
+ for (const moduleJson of release.script_modules) {
1796
+ for (const functionJson of moduleJson.functions ?? []) {
1797
+ markObjectAsErrorable(functionJson);
1798
+ }
1799
+ for (const classJson of moduleJson.classes ?? []) {
1800
+ for (const functionJson of classJson.functions ?? []) {
1801
+ markObjectAsErrorable(functionJson);
1802
+ }
1803
+ for (const propertyJson of classJson.properties ?? []) {
1804
+ markObjectAsErrorable(propertyJson);
1805
+ }
1806
+ }
1807
+ for (const interfaceJson of moduleJson.interfaces ?? []) {
1808
+ for (const propertyJson of interfaceJson.properties ?? []) {
1809
+ markObjectAsErrorable(propertyJson);
1810
+ }
1811
+ }
1812
+ }
1813
+ }
1814
+ }
1815
+ function markObjectAsPrerelease(metadataJson, changelogKey) {
1816
+ metadataJson.is_prerelease = false;
1817
+ metadataJson.prerelease = undefined;
1818
+ if (changelogKey in metadataJson) {
1819
+ for (const changelog of metadataJson[changelogKey]) {
1820
+ const changelogVersionPrerelease = semver_1.default.prerelease(changelog.version);
1821
+ if (!changelogVersionPrerelease) {
1822
+ break;
1823
+ }
1824
+ if (changelog.$added) {
1825
+ metadataJson.is_prerelease = true;
1826
+ metadataJson.prerelease = changelogVersionPrerelease[0];
1827
+ }
1828
+ }
1829
+ }
1830
+ }
1831
+ /**
1832
+ * Marks up APIs as prerelease by using the changelog to determine if they are added
1833
+ * in a prerelease version.
1834
+ */
1835
+ function markPrerelease(releases) {
1836
+ for (const release of releases) {
1837
+ for (const moduleJson of release.script_modules) {
1838
+ const modulePrereleaseTag = semver_1.default.prerelease(moduleJson.version);
1839
+ if (!modulePrereleaseTag ||
1840
+ (modulePrereleaseTag[0] !== 'alpha' &&
1841
+ modulePrereleaseTag[0] !== 'internal' &&
1842
+ modulePrereleaseTag[0] !== 'beta' &&
1843
+ modulePrereleaseTag[0] !== 'rc')) {
1844
+ continue;
1845
+ }
1846
+ markObjectAsPrerelease(moduleJson, 'changelog');
1847
+ for (const constantJson of moduleJson.constants ?? []) {
1848
+ markObjectAsPrerelease(constantJson, 'constant_changelog');
1849
+ }
1850
+ for (const functionJson of moduleJson.functions ?? []) {
1851
+ markObjectAsPrerelease(functionJson, 'function_changelog');
1852
+ }
1853
+ for (const objectJson of moduleJson.objects ?? []) {
1854
+ markObjectAsPrerelease(objectJson, 'object_changelog');
1855
+ }
1856
+ for (const aliasJson of moduleJson.type_aliases ?? []) {
1857
+ markObjectAsPrerelease(aliasJson, 'alias_changelog');
1858
+ }
1859
+ const markupObjectsAsPrerelease = (objectKey, changelogKey) => {
1860
+ if (objectKey in moduleJson) {
1861
+ for (const objectJson of moduleJson[objectKey]) {
1862
+ markObjectAsPrerelease(objectJson, changelogKey);
1863
+ if ((0, MinecraftScriptModule_1.hasConstants)(objectJson)) {
1864
+ for (const constantJson of objectJson.constants) {
1865
+ markObjectAsPrerelease(constantJson, 'constant_changelog');
1866
+ }
1867
+ }
1868
+ if ((0, MinecraftScriptModule_1.hasFunctions)(objectJson)) {
1869
+ for (const functionJson of objectJson.functions) {
1870
+ markObjectAsPrerelease(functionJson, 'function_changelog');
1871
+ }
1872
+ }
1873
+ if ((0, MinecraftScriptModule_1.hasProperties)(objectJson)) {
1874
+ for (const propertyJson of objectJson.properties) {
1875
+ markObjectAsPrerelease(propertyJson, 'property_changelog');
1876
+ }
1877
+ }
1878
+ }
1879
+ }
1880
+ };
1881
+ markupObjectsAsPrerelease('classes', 'class_changelog');
1882
+ markupObjectsAsPrerelease('interfaces', 'interface_changelog');
1883
+ markupObjectsAsPrerelease('enums', 'enum_changelog');
1884
+ markupObjectsAsPrerelease('errors', 'error_changelog');
1885
+ }
1886
+ }
1887
+ }
1888
+ function markObjectAsDeprecated(metadataJson, changelogKey, metadataHierarchy, moduleName, modules) {
1889
+ const markObjectAsDeprecatedRecursive = (objectJson, changelogKey, deprecatedVersion, metadataHierarchy) => {
1890
+ if (metadataHierarchy.key in objectJson) {
1891
+ const objectArray = objectJson[metadataHierarchy.key];
1892
+ const subObjectIndex = objectArray.map(subObjectJson => subObjectJson.name).indexOf(metadataHierarchy.name);
1893
+ if (subObjectIndex !== -1) {
1894
+ const subObjectJson = objectArray[subObjectIndex];
1895
+ if (!metadataHierarchy.child) {
1896
+ let addedInPrerelease = false;
1897
+ if (changelogKey in subObjectJson) {
1898
+ for (const changelog of subObjectJson[changelogKey]) {
1899
+ const changelogVersionPrerelease = semver_1.default.prerelease(changelog.version);
1900
+ if (!changelogVersionPrerelease) {
1901
+ break;
1902
+ }
1903
+ if (changelog.$added) {
1904
+ addedInPrerelease = true;
1905
+ }
1906
+ }
1907
+ }
1908
+ if (!addedInPrerelease) {
1909
+ subObjectJson.is_deprecated = true;
1910
+ subObjectJson.deprecated_version = deprecatedVersion;
1911
+ }
1912
+ }
1913
+ else {
1914
+ markObjectAsDeprecatedRecursive(subObjectJson, changelogKey, deprecatedVersion, metadataHierarchy.child);
1915
+ }
1916
+ }
1917
+ }
1918
+ };
1919
+ if (changelogKey in metadataJson) {
1920
+ for (const changelog of metadataJson[changelogKey]) {
1921
+ const changelogVersion = semver_1.default.parse(changelog.version);
1922
+ if (changelogVersion && changelog.$removed) {
1923
+ for (const moduleJson of modules) {
1924
+ if (moduleJson.name === moduleName && semver_1.default.lt(moduleJson.version, changelogVersion)) {
1925
+ const deprecatedVersion = `${changelogVersion.major}.0.0`;
1926
+ markObjectAsDeprecatedRecursive(moduleJson, changelogKey, deprecatedVersion, metadataHierarchy);
1927
+ }
1928
+ }
1929
+ break;
1930
+ }
1931
+ }
1932
+ }
1933
+ }
1934
+ /**
1935
+ * Marks up APIs as deprecated in past version by using the changelog to determine if they
1936
+ * have been removed in a future version.
1937
+ */
1938
+ function markDeprecated(releases) {
1939
+ for (const release of releases) {
1940
+ for (const moduleJson of release.script_modules) {
1941
+ for (const constantJson of moduleJson.constants ?? []) {
1942
+ markObjectAsDeprecated(constantJson, 'constant_changelog', { key: 'constants', name: constantJson.name }, moduleJson.name, release.script_modules);
1943
+ }
1944
+ for (const functionJson of moduleJson.functions ?? []) {
1945
+ markObjectAsDeprecated(functionJson, 'function_changelog', { key: 'functions', name: functionJson.name }, moduleJson.name, release.script_modules);
1946
+ }
1947
+ for (const objectJson of moduleJson.objects ?? []) {
1948
+ markObjectAsDeprecated(objectJson, 'object_changelog', { key: 'objects', name: objectJson.name }, moduleJson.name, release.script_modules);
1949
+ }
1950
+ for (const aliasJson of moduleJson.type_aliases ?? []) {
1951
+ markObjectAsDeprecated(aliasJson, 'alias_changelog', { key: 'type_aliases', name: aliasJson.name }, moduleJson.name, release.script_modules);
1952
+ }
1953
+ const markupObjectsAsDeprecated = (objectKey, changelogKey) => {
1954
+ if (objectKey in moduleJson) {
1955
+ for (const objectJson of moduleJson[objectKey]) {
1956
+ markObjectAsDeprecated(objectJson, changelogKey, { key: objectKey, name: objectJson.name }, moduleJson.name, release.script_modules);
1957
+ if ((0, MinecraftScriptModule_1.hasConstants)(objectJson)) {
1958
+ for (const constantJson of objectJson.constants) {
1959
+ markObjectAsDeprecated(constantJson, 'constant_changelog', {
1960
+ key: objectKey,
1961
+ name: objectJson.name,
1962
+ child: { key: 'constants', name: constantJson.name },
1963
+ }, moduleJson.name, release.script_modules);
1964
+ }
1965
+ }
1966
+ if ((0, MinecraftScriptModule_1.hasFunctions)(objectJson)) {
1967
+ for (const functionJson of objectJson.functions) {
1968
+ markObjectAsDeprecated(functionJson, 'function_changelog', {
1969
+ key: objectKey,
1970
+ name: objectJson.name,
1971
+ child: { key: 'functions', name: functionJson.name },
1972
+ }, moduleJson.name, release.script_modules);
1973
+ }
1974
+ }
1975
+ if ((0, MinecraftScriptModule_1.hasProperties)(objectJson)) {
1976
+ for (const propertyJson of objectJson.properties) {
1977
+ markObjectAsDeprecated(propertyJson, 'property_changelog', {
1978
+ key: objectKey,
1979
+ name: objectJson.name,
1980
+ child: { key: 'properties', name: propertyJson.name },
1981
+ }, moduleJson.name, release.script_modules);
1982
+ }
1983
+ }
1984
+ }
1985
+ }
1986
+ };
1987
+ markupObjectsAsDeprecated('classes', 'class_changelog');
1988
+ markupObjectsAsDeprecated('interfaces', 'interface_changelog');
1989
+ markupObjectsAsDeprecated('enums', 'enum_changelog');
1990
+ markupObjectsAsDeprecated('errors', 'error_changelog');
1991
+ }
1992
+ }
1993
+ }
1994
+ function addChangelogToMetadata(metadataList, changelogList, changelogVersion, changelogDestinationKey) {
1995
+ for (const changedProperty of changelogList) {
1996
+ const objectPropertyIndex = metadataList.map(propertyJson => propertyJson.name).indexOf(changedProperty.name);
1997
+ if (objectPropertyIndex !== -1) {
1998
+ const baseChangelog = {
1999
+ version: changelogVersion,
2000
+ };
2001
+ for (const changedDataType in changedProperty) {
2002
+ baseChangelog[changedDataType] = changedProperty[changedDataType];
2003
+ }
2004
+ const propertyJson = metadataList[objectPropertyIndex];
2005
+ propertyJson[changelogDestinationKey] = propertyJson[changelogDestinationKey] ?? [];
2006
+ const propertyChangelogList = propertyJson[changelogDestinationKey];
2007
+ propertyChangelogList.push(baseChangelog);
2008
+ propertyJson.has_changes = propertyJson.has_changes || changedProperty['has_changes'];
2009
+ }
2010
+ }
2011
+ }
2012
+ /**
2013
+ * Copy changelog objects from the root module 'changelog' to the associated object
2014
+ * as '<type>_changelog' fields in the actual metadata.
2015
+ */
2016
+ function copyChangelogsToObjectMetadata(releases) {
2017
+ for (const release of releases) {
2018
+ for (const scriptModule of release.script_modules) {
2019
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(scriptModule)) {
2020
+ for (const changelog of scriptModule.changelog) {
2021
+ if ((0, MinecraftScriptModule_1.hasConstants)(changelog) && (0, MinecraftScriptModule_1.hasConstants)(scriptModule)) {
2022
+ for (const constantJson of scriptModule.constants) {
2023
+ constantJson.has_changes = constantJson.has_changes ?? false;
2024
+ }
2025
+ addChangelogToMetadata(scriptModule.constants, changelog.constants, changelog.version, 'constant_changelog');
2026
+ }
2027
+ if ((0, MinecraftScriptModule_1.hasFunctions)(changelog) && (0, MinecraftScriptModule_1.hasFunctions)(scriptModule)) {
2028
+ for (const functionJson of scriptModule.functions) {
2029
+ functionJson.has_changes = functionJson.has_changes ?? false;
2030
+ }
2031
+ addChangelogToMetadata(scriptModule.functions, changelog.functions, changelog.version, 'function_changelog');
2032
+ }
2033
+ if ((0, MinecraftScriptModule_1.hasObjects)(changelog) && (0, MinecraftScriptModule_1.hasObjects)(scriptModule)) {
2034
+ for (const objectJson of scriptModule.objects) {
2035
+ objectJson.has_changes = objectJson.has_changes ?? false;
2036
+ }
2037
+ addChangelogToMetadata(scriptModule.objects, changelog.objects, changelog.version, 'object_changelog');
2038
+ }
2039
+ if ((0, MinecraftScriptModule_1.hasTypeAliases)(changelog) && (0, MinecraftScriptModule_1.hasTypeAliases)(scriptModule)) {
2040
+ for (const aliasJson of scriptModule.type_aliases) {
2041
+ aliasJson.has_changes = aliasJson.has_changes ?? false;
2042
+ }
2043
+ addChangelogToMetadata(scriptModule.type_aliases, changelog.type_aliases, changelog.version, 'alias_changelog');
2044
+ }
2045
+ const addObjectMetadata = (objectKey, changelogKey) => {
2046
+ if (objectKey in scriptModule && objectKey in changelog) {
2047
+ for (const changedObject of changelog[objectKey]) {
2048
+ const moduleObjectIndex = scriptModule[objectKey]
2049
+ .map(objectJson => objectJson.name)
2050
+ .indexOf(changedObject.name);
2051
+ if (moduleObjectIndex !== -1) {
2052
+ const objectJson = scriptModule[objectKey][moduleObjectIndex];
2053
+ objectJson[changelogKey] = objectJson[changelogKey] ?? [];
2054
+ const objectChangelog = {
2055
+ version: changelog.version,
2056
+ };
2057
+ let changedDataType;
2058
+ for (changedDataType in changedObject) {
2059
+ objectChangelog[changedDataType] = changedObject[changedDataType];
2060
+ }
2061
+ const objectChangelogList = objectJson[changelogKey];
2062
+ objectChangelogList.push(objectChangelog);
2063
+ objectJson.has_changes = objectJson.has_changes || objectChangelog.has_changes;
2064
+ if ((0, MinecraftScriptModule_1.hasConstants)(changedObject) && (0, MinecraftScriptModule_1.hasConstants)(objectJson)) {
2065
+ for (const constantJson of objectJson.constants) {
2066
+ constantJson.has_changes = constantJson.has_changes ?? false;
2067
+ }
2068
+ addChangelogToMetadata(objectJson.constants, changedObject.constants, changelog.version, 'constant_changelog');
2069
+ }
2070
+ if ((0, MinecraftScriptModule_1.hasFunctions)(changedObject) && (0, MinecraftScriptModule_1.hasFunctions)(objectJson)) {
2071
+ for (const functionJson of objectJson.functions) {
2072
+ functionJson.has_changes = functionJson.has_changes ?? false;
2073
+ }
2074
+ addChangelogToMetadata(objectJson.functions, changedObject.functions, changelog.version, 'function_changelog');
2075
+ }
2076
+ if ((0, MinecraftScriptModule_1.hasProperties)(changedObject) && (0, MinecraftScriptModule_1.hasProperties)(objectJson)) {
2077
+ for (const propertyJson of objectJson.properties) {
2078
+ propertyJson.has_changes = propertyJson.has_changes ?? false;
2079
+ }
2080
+ addChangelogToMetadata(objectJson.properties, changedObject.properties, changelog.version, 'property_changelog');
2081
+ }
2082
+ }
2083
+ }
2084
+ }
2085
+ };
2086
+ addObjectMetadata('classes', 'class_changelog');
2087
+ addObjectMetadata('interfaces', 'interface_changelog');
2088
+ addObjectMetadata('enums', 'enum_changelog');
2089
+ addObjectMetadata('errors', 'error_changelog');
2090
+ }
2091
+ }
2092
+ }
2093
+ }
2094
+ }
2095
+ /**
2096
+ * Add 'is_member' and 'has_member_*' fields for functions and constants
2097
+ * to mark whether they belong to a class/interface.
2098
+ */
2099
+ function markMembers(releases) {
2100
+ const markMembersOnModule = (scriptModule) => {
2101
+ if (scriptModule.classes) {
2102
+ for (const classJson of scriptModule.classes) {
2103
+ if (classJson.functions && classJson.functions.length > 0) {
2104
+ classJson.has_member_functions = true;
2105
+ for (const functionJson of classJson.functions) {
2106
+ functionJson.is_member = true;
2107
+ }
2108
+ }
2109
+ if (classJson.constants && classJson.constants.length > 0) {
2110
+ classJson.has_member_constants = true;
2111
+ for (const constantJson of classJson.constants) {
2112
+ constantJson.is_member = true;
2113
+ }
2114
+ }
2115
+ if (classJson.properties) {
2116
+ for (const propertyJson of classJson.properties) {
2117
+ propertyJson.is_member = true;
2118
+ }
2119
+ }
2120
+ }
2121
+ }
2122
+ if (scriptModule.interfaces) {
2123
+ for (const interfaceJson of scriptModule.interfaces) {
2124
+ if (interfaceJson.is_script_generated &&
2125
+ interfaceJson.functions &&
2126
+ interfaceJson.functions.length > 0) {
2127
+ interfaceJson.has_member_functions = true;
2128
+ for (const functionJson of interfaceJson.functions) {
2129
+ functionJson.is_member = true;
2130
+ }
2131
+ }
2132
+ if (interfaceJson.properties) {
2133
+ for (const propertyJson of interfaceJson.properties) {
2134
+ propertyJson.is_member = true;
2135
+ }
2136
+ }
2137
+ }
2138
+ }
2139
+ if (scriptModule.functions) {
2140
+ for (const functionJson of scriptModule.functions) {
2141
+ functionJson.is_member = false;
2142
+ }
2143
+ }
2144
+ };
2145
+ for (const release of releases) {
2146
+ for (const scriptModule of release.script_modules) {
2147
+ markMembersOnModule(scriptModule);
2148
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(scriptModule)) {
2149
+ for (const changelog of scriptModule.changelog) {
2150
+ markMembersOnModule(changelog);
2151
+ }
2152
+ }
2153
+ }
2154
+ }
2155
+ }
2156
+ function markInterfaceTypes(releases) {
2157
+ const markInterfacesOnModule = (scriptModule) => {
2158
+ if (scriptModule.interfaces) {
2159
+ for (const interfaceJson of scriptModule.interfaces) {
2160
+ interfaceJson.is_interface = true;
2161
+ }
2162
+ }
2163
+ };
2164
+ for (const release of releases) {
2165
+ for (const scriptModule of release.script_modules) {
2166
+ markInterfacesOnModule(scriptModule);
2167
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(scriptModule)) {
2168
+ for (const changelog of scriptModule.changelog) {
2169
+ markInterfacesOnModule(changelog);
2170
+ }
2171
+ }
2172
+ }
2173
+ }
2174
+ }
2175
+ /**
2176
+ * Inserts empty arrays for module API categories that do not exist.
2177
+ */
2178
+ function defaultModuleCategories(releases) {
2179
+ const insertEmptyArrayIfNotExist = (objectJson, member) => {
2180
+ if (!objectJson[member]) {
2181
+ objectJson[member] = [];
2182
+ }
2183
+ };
2184
+ for (const release of releases) {
2185
+ for (const scriptModule of release.script_modules) {
2186
+ const scriptModuleCategories = [
2187
+ 'classes',
2188
+ 'interfaces',
2189
+ 'enums',
2190
+ 'errors',
2191
+ 'constants',
2192
+ 'functions',
2193
+ 'objects',
2194
+ 'type_aliases',
2195
+ 'dependencies',
2196
+ 'peer_dependencies',
2197
+ ];
2198
+ for (const categoryName of scriptModuleCategories) {
2199
+ insertEmptyArrayIfNotExist(scriptModule, categoryName);
2200
+ }
2201
+ insertEmptyArrayIfNotExist(scriptModule, 'changelog');
2202
+ if ((0, MinecraftChangelogTypes_1.moduleHasChangelog)(scriptModule)) {
2203
+ for (const changelog of scriptModule.changelog) {
2204
+ for (const categoryName of scriptModuleCategories) {
2205
+ insertEmptyArrayIfNotExist(changelog, categoryName);
2206
+ }
2207
+ }
2208
+ }
2209
+ }
2210
+ for (const commandsModule of release.command_modules) {
2211
+ insertEmptyArrayIfNotExist(commandsModule, 'commands');
2212
+ insertEmptyArrayIfNotExist(commandsModule, 'command_enums');
2213
+ insertEmptyArrayIfNotExist(commandsModule, 'command_types');
2214
+ }
2215
+ for (const blockModule of release.block_modules) {
2216
+ insertEmptyArrayIfNotExist(blockModule, 'data_items');
2217
+ insertEmptyArrayIfNotExist(blockModule, 'block_properties');
2218
+ }
2219
+ }
2220
+ }
2221
+ /**
2222
+ * Adds 'from_module' to the root of the module, to allow mustache to
2223
+ * look up the tree to access module data.
2224
+ */
2225
+ function addFromModuleToRoot(releases) {
2226
+ for (const release of releases) {
2227
+ release.script_modules.forEach(moduleJson => {
2228
+ const module = {
2229
+ name: moduleJson.name,
2230
+ uuid: moduleJson.uuid,
2231
+ version: moduleJson.version,
2232
+ };
2233
+ moduleJson.from_module = structuredClone(module);
2234
+ const addModuleToReturnType = (returnType) => {
2235
+ for (const error of returnType.error_types ?? []) {
2236
+ if (!error.from_module) {
2237
+ error.from_module = structuredClone(module);
2238
+ }
2239
+ }
2240
+ };
2241
+ for (const classJson of moduleJson.classes ?? []) {
2242
+ classJson.from_module = structuredClone(module);
2243
+ for (const functionJson of classJson.functions ?? []) {
2244
+ addModuleToReturnType(functionJson.return_type);
2245
+ }
2246
+ for (const propertyJson of classJson.properties ?? []) {
2247
+ addModuleToReturnType(propertyJson.type);
2248
+ }
2249
+ }
2250
+ for (const functionJson of moduleJson.functions ?? []) {
2251
+ addModuleToReturnType(functionJson.return_type);
2252
+ }
2253
+ for (const interfaceJson of moduleJson.interfaces ?? []) {
2254
+ interfaceJson.from_module = structuredClone(module);
2255
+ for (const functionJson of interfaceJson.functions ?? []) {
2256
+ addModuleToReturnType(functionJson.return_type);
2257
+ }
2258
+ }
2259
+ for (const enumJson of moduleJson.enums ?? []) {
2260
+ enumJson.from_module = structuredClone(module);
2261
+ }
2262
+ for (const typeAlias of moduleJson.type_aliases ?? []) {
2263
+ typeAlias.from_module = structuredClone(module);
2264
+ }
2265
+ for (const errors of moduleJson.errors ?? []) {
2266
+ errors.from_module = structuredClone(module);
2267
+ }
2268
+ });
2269
+ }
2270
+ }
2271
+ /**
2272
+ * Marks up modules that have 'prerelease' semver tags.
2273
+ */
2274
+ function markModulesWithPrerelease(releases) {
2275
+ const markUpModule = (moduleJson) => {
2276
+ const prereleaseTag = semver_1.default.prerelease(moduleJson.version);
2277
+ if (prereleaseTag) {
2278
+ moduleJson.version_is_prerelease = true;
2279
+ if (prereleaseTag[0] === 'beta' || prereleaseTag[0] === 'alpha' || prereleaseTag[0] === 'internal') {
2280
+ moduleJson.module_prerelease_tag = prereleaseTag[0];
2281
+ }
2282
+ else if (prereleaseTag[0] === 'rc') {
2283
+ moduleJson.module_prerelease_tag = 'preview';
2284
+ }
2285
+ else {
2286
+ throw new Error(`Unexpected prerelease tag ${prereleaseTag[0]} on module: ${moduleJson.version}`);
2287
+ }
2288
+ }
2289
+ else {
2290
+ moduleJson.version_is_prerelease = false;
2291
+ }
2292
+ };
2293
+ for (const release of releases) {
2294
+ release.script_modules.forEach(markUpModule);
2295
+ const afterEventsOrderModule = (0, MinecraftAfterEventsOrderModule_1.getAfterEventsOrderingModuleFrom)(release.engine_data_modules);
2296
+ if (afterEventsOrderModule) {
2297
+ afterEventsOrderModule.after_events_order_by_version.forEach(markUpModule);
2298
+ }
2299
+ }
2300
+ }
2301
+ /**
2302
+ * Generates list of module versions per release.
2303
+ */
2304
+ function generateAvailableModuleLists(releases) {
2305
+ for (const release of releases) {
2306
+ const moduleVersionsPerMajorVersionPerUUID = {};
2307
+ release.script_modules.forEach(moduleJson => {
2308
+ if (!moduleVersionsPerMajorVersionPerUUID[moduleJson.uuid]) {
2309
+ moduleVersionsPerMajorVersionPerUUID[moduleJson.uuid] = [];
2310
+ }
2311
+ const moduleVersionsPerMajorVersion = moduleVersionsPerMajorVersionPerUUID[moduleJson.uuid];
2312
+ const major = semver_1.default.major(moduleJson.version);
2313
+ if (!moduleVersionsPerMajorVersion[major]) {
2314
+ moduleVersionsPerMajorVersion[major] = [];
2315
+ }
2316
+ moduleVersionsPerMajorVersion[major].push(moduleJson);
2317
+ moduleJson.major_version = major;
2318
+ });
2319
+ for (const uuid in moduleVersionsPerMajorVersionPerUUID) {
2320
+ for (const major in moduleVersionsPerMajorVersionPerUUID[uuid]) {
2321
+ moduleVersionsPerMajorVersionPerUUID[uuid][major].sort(function (element1, element2) {
2322
+ return semver_1.default.compare(element2.version, element1.version);
2323
+ });
2324
+ }
2325
+ }
2326
+ release.script_modules.forEach(moduleJson => {
2327
+ moduleJson.available_module_versions = moduleVersionsPerMajorVersionPerUUID[moduleJson.uuid][semver_1.default.major(moduleJson.version)].map(module => module.version);
2328
+ let major = semver_1.default.major(moduleJson.version) - 1;
2329
+ moduleJson.previous_module_version_chunks = [];
2330
+ while (major > 0 && moduleJson.is_latest_major) {
2331
+ if (!moduleVersionsPerMajorVersionPerUUID[moduleJson.uuid][major]) {
2332
+ major--;
2333
+ continue;
2334
+ }
2335
+ const previousMajor = moduleVersionsPerMajorVersionPerUUID[moduleJson.uuid][major][0];
2336
+ const filePath = generateMSDocsLink(undefined, previousMajor, undefined, undefined);
2337
+ moduleJson.previous_module_version_chunks.push({
2338
+ versions: moduleVersionsPerMajorVersionPerUUID[moduleJson.uuid][major].map(module => module.version),
2339
+ prior_version_link: filePath,
2340
+ });
2341
+ major--;
2342
+ }
2343
+ const available_stable_module_versions = moduleJson.available_module_versions.filter(version => !semver_1.default.prerelease(version));
2344
+ if (available_stable_module_versions.length > 0) {
2345
+ moduleJson.manifest_example_version_md = available_stable_module_versions[0];
2346
+ }
2347
+ else {
2348
+ moduleJson.manifest_example_version_md = moduleJson.available_module_versions[0];
2349
+ }
2350
+ const moduleSemVer = semver_1.default.parse(moduleJson.version);
2351
+ if (moduleSemVer.prerelease.length > 1) {
2352
+ if (moduleSemVer.prerelease[0] !== 'rc') {
2353
+ moduleSemVer.prerelease = [moduleSemVer.prerelease[0]];
2354
+ }
2355
+ else {
2356
+ moduleSemVer.prerelease = [];
2357
+ }
2358
+ }
2359
+ moduleJson.manifest_example_version_ts = moduleSemVer.format();
2360
+ });
2361
+ }
2362
+ }
2363
+ /**
2364
+ * Marks up all 'from_module' fields with data from actual modules.
2365
+ */
2366
+ function populateFromModuleData(releases) {
2367
+ const moduleKeyToData = {};
2368
+ for (const release of releases) {
2369
+ for (const scriptModule of release.script_modules) {
2370
+ log.assert(scriptModule.from_module.folder_path !== undefined, "Module's folder path should not be undefined");
2371
+ moduleKeyToData[`${scriptModule.uuid}_${scriptModule.version}`] = {
2372
+ name: scriptModule.name,
2373
+ filepath_name: scriptModule.filepath_name,
2374
+ folder_path: scriptModule.from_module.folder_path,
2375
+ prior_version: scriptModule.from_module.prior_version,
2376
+ version: scriptModule.version,
2377
+ uuid: scriptModule.uuid,
2378
+ };
2379
+ }
2380
+ }
2381
+ for (const release of releases) {
2382
+ for (const scriptModule of release.script_modules) {
2383
+ utils.scanObjectForMemberWithName(scriptModule, 'from_module', (objectJson) => {
2384
+ const moduleKey = `${objectJson.from_module.uuid}_${objectJson.from_module.version}`;
2385
+ const moduleData = moduleKeyToData[moduleKey];
2386
+ if (moduleData) {
2387
+ objectJson.from_module.name = moduleData.name;
2388
+ objectJson.from_module.filepath_name = moduleData.filepath_name;
2389
+ objectJson.from_module.folder_path = moduleData.folder_path;
2390
+ objectJson.from_module.prior_version = moduleData.prior_version;
2391
+ }
2392
+ else {
2393
+ log.printOption(`Could not populate from_module for module '${objectJson.from_module.name}@${objectJson.from_module.version}' in '${scriptModule.name}@${scriptModule.version}'.`, 'unresolvedDependencies');
2394
+ }
2395
+ });
2396
+ }
2397
+ }
2398
+ }
2399
+ function addPrivilegeFlags(releases) {
2400
+ const contains = (search, priv) => {
2401
+ if (priv === undefined) {
2402
+ return false;
2403
+ }
2404
+ for (const p of priv) {
2405
+ if (p.name === search) {
2406
+ return true;
2407
+ }
2408
+ }
2409
+ return false;
2410
+ };
2411
+ const checkPropertyPrivileges = (prop) => {
2412
+ if (!prop.is_read_only) {
2413
+ prop.set_disallowed_in_read_only = !contains('read_only', prop.set_privilege);
2414
+ prop.get_disallowed_in_read_only = !contains('read_only', prop.get_privilege);
2415
+ prop.has_privilege_comments = prop.set_disallowed_in_read_only || prop.get_disallowed_in_read_only;
2416
+ }
2417
+ prop.set_allowed_in_early_execution = contains('early_execution', prop.set_privilege);
2418
+ prop.get_allowed_in_early_execution = contains('early_execution', prop.get_privilege);
2419
+ prop.has_privilege_comments =
2420
+ prop.set_allowed_in_early_execution || prop.get_allowed_in_early_execution || prop.has_privilege_comments;
2421
+ };
2422
+ const checkFunctionPrivileges = (func) => {
2423
+ func.call_disallowed_in_read_only = !contains('read_only', func.call_privilege);
2424
+ func.call_allowed_in_early_execution = contains('early_execution', func.call_privilege);
2425
+ func.has_privilege_comments = func.call_disallowed_in_read_only || func.call_allowed_in_early_execution;
2426
+ };
2427
+ for (const release of releases ?? []) {
2428
+ for (const scriptModule of release.script_modules ?? []) {
2429
+ for (const classMetadata of scriptModule.classes ?? []) {
2430
+ for (const prop of classMetadata.properties ?? []) {
2431
+ checkPropertyPrivileges(prop);
2432
+ }
2433
+ for (const func of classMetadata.functions ?? []) {
2434
+ checkFunctionPrivileges(func);
2435
+ }
2436
+ }
2437
+ for (const errorMetadata of scriptModule.errors ?? []) {
2438
+ for (const prop of errorMetadata.properties ?? []) {
2439
+ checkPropertyPrivileges(prop);
2440
+ }
2441
+ }
2442
+ for (const func of scriptModule.functions ?? []) {
2443
+ checkFunctionPrivileges(func);
2444
+ }
2445
+ }
2446
+ }
2447
+ }
2448
+ function addRuntimeConditionsFlag(releases) {
2449
+ for (const release of releases) {
2450
+ for (const scriptModule of release.script_modules) {
2451
+ for (const interfaceMetadata of scriptModule.interfaces ?? []) {
2452
+ interfaceMetadata.has_runtime_conditions =
2453
+ interfaceMetadata.runtime_conditions !== undefined &&
2454
+ interfaceMetadata.runtime_conditions.length > 0;
2455
+ }
2456
+ for (const classMetadata of scriptModule.classes ?? []) {
2457
+ classMetadata.has_runtime_conditions =
2458
+ classMetadata.runtime_conditions !== undefined && classMetadata.runtime_conditions.length > 0;
2459
+ for (const functionMetadata of classMetadata.functions ?? []) {
2460
+ const culledFunctionRuntimeConditions = [];
2461
+ for (const functionRuntimeCondition of functionMetadata.runtime_conditions ?? []) {
2462
+ let functionRuntimeConditionMatchedClass = false;
2463
+ for (const classRuntimeCondition of classMetadata.runtime_conditions ?? []) {
2464
+ if (functionRuntimeCondition === classRuntimeCondition) {
2465
+ functionRuntimeConditionMatchedClass = true;
2466
+ break;
2467
+ }
2468
+ }
2469
+ if (!functionRuntimeConditionMatchedClass) {
2470
+ culledFunctionRuntimeConditions.push(functionRuntimeCondition);
2471
+ }
2472
+ }
2473
+ functionMetadata.runtime_conditions = culledFunctionRuntimeConditions;
2474
+ functionMetadata.has_runtime_conditions =
2475
+ functionMetadata.runtime_conditions !== undefined &&
2476
+ functionMetadata.runtime_conditions.length > 0;
2477
+ }
2478
+ }
2479
+ }
2480
+ }
2481
+ }
2482
+ exports.CommonFilters = {
2483
+ id: 'common',
2484
+ filters: [
2485
+ ['mark_prerelease_modules', markModulesWithPrerelease], // No dependencies
2486
+ ['default_module_categories', defaultModuleCategories], // No dependencies
2487
+ ['link_derived_types', linkDerivedTypes], // No dependencies
2488
+ ['add_from_module_to_root', addFromModuleToRoot], // No dependencies
2489
+ ['external_module_flag', fromExternalModule], // Depends on link_derived_types, add_from_module_to_root
2490
+ ['add_from_module_to_dependencies', addFromModuleToDependencies], // No dependencies
2491
+ ['set_from_module_to_dependent_modules', setFromModuleToDependentModules], // No dependencies
2492
+ ['markup_latest_modules', markupLatestModules], // Depends on add_from_module_to_root, add_from_module_to_dependencies, set_from_module_to_dependent_modules
2493
+ ['markup_names', markupNames], // Depends on add_from_module_to_dependencies, markup_latest_modules
2494
+ ['populate_from_module_data', populateFromModuleData], // Depends on add_from_module_to_root, set_from_module_to_dependent_modules, markup_names
2495
+ ['generate_available_module_lists', generateAvailableModuleLists], // Depends on populate_from_module_data
2496
+ ['mark_members', markMembers],
2497
+ ['mark_interfaces', markInterfaceTypes],
2498
+ ['flag_changelog_changes', flagChangelogChanges],
2499
+ ['nest_changed_types', nestChangedTypes],
2500
+ ['copy_changelogs', copyChangelogsToObjectMetadata],
2501
+ ['mark_errorable', markErrorable],
2502
+ ['mark_prerelease', markPrerelease],
2503
+ ['mark_deprecated', markDeprecated],
2504
+ CommandFilters_1.CommandMarkupFilter,
2505
+ ['block_filters', blockFilters],
2506
+ ['constant_values', constantValues],
2507
+ ['default_values', defaultValues],
2508
+ ['markup_categories', markupCategories],
2509
+ ['type_alias_markup', typeAliasMarkup],
2510
+ ['type_flags', typeFlags],
2511
+ ['constructors', constructors],
2512
+ ['array_indexes', arrayIndexes],
2513
+ ['add_privilege_flags', addPrivilegeFlags],
2514
+ ['add_descriptions_and_examples', addDescriptionsAndExamples],
2515
+ ['add_runtime_conditions_flag', addRuntimeConditionsFlag],
2516
+ ],
2517
+ };
2518
+ //# sourceMappingURL=CommonFilters.js.map