@@ -20,12 +20,17 @@ import {
20
20
getFieldDifferencesRow ,
21
21
} from "./builder.utils" ;
22
22
import { IndexType } from "../../../utils/cache2" ;
23
+ import {
24
+ NamedPerArchiveLoadable ,
25
+ PerArchiveLoadable ,
26
+ } from "../../../utils/cache2/Loadable" ;
23
27
import { capitalize } from "../../../utils/string" ;
24
28
import {
25
29
ArchiveDifferences ,
26
30
CacheDifferences ,
27
31
ChangedResult ,
28
32
Difference ,
33
+ IndexDifferences ,
29
34
Result ,
30
35
} from "../differences.types" ;
31
36
@@ -61,26 +66,69 @@ const differencesBuilder = (
61
66
Object . keys ( differences ) . forEach ( ( index ) => {
62
67
const indexFeatureMap = indexNameMap [ index as unknown as IndexType ] ;
63
68
if ( indexFeatureMap ) {
64
- const archives = differences [ index as unknown as number ] ;
65
- Object . keys ( archives ) . forEach ( ( archive ) => {
66
- const archiveNumber = archive as unknown as number ;
67
- const archiveDifferences = archives [ archiveNumber ] ;
68
- const indexFeature =
69
- "name" in indexFeatureMap
70
- ? indexFeatureMap
71
- : indexFeatureMap [ archiveNumber ] ;
72
- if ( indexFeature ) {
73
- builder . addContents (
74
- buildArchiveDifferences ( archiveDifferences , indexFeature )
75
- ) ;
76
- }
77
- } ) ;
69
+ const indexDifferences = differences [ index as unknown as number ] ;
70
+ if ( "name" in indexFeatureMap ) {
71
+ const indexFeature = indexFeatureMap as IndexFeatures ;
72
+ builder . addContents (
73
+ buildIndexDifferences ( indexDifferences , indexFeature )
74
+ ) ;
75
+ } else {
76
+ Object . keys ( indexDifferences ) . forEach ( ( archive ) => {
77
+ const archiveNumber = archive as unknown as number ;
78
+ const archiveDifferences = indexDifferences [ archiveNumber ] ;
79
+ const indexFeature = indexFeatureMap [ archiveNumber ] ;
80
+ if ( indexFeature ) {
81
+ builder . addContents (
82
+ buildArchiveDifferences ( archiveDifferences , indexFeature )
83
+ ) ;
84
+ }
85
+ } ) ;
86
+ }
78
87
}
79
88
} ) ;
80
-
81
89
return builder ;
82
90
} ;
83
91
92
+ /**
93
+ * Build the media wiki content for the differences in two cache index's archives.
94
+ * @param indexDifferences Differences between two cache's index's archives.
95
+ * @param indexFeatures Meta deta for indexes
96
+ * @returns {MediaWikiContent[] }
97
+ */
98
+ const buildIndexDifferences = (
99
+ indexDifferences : IndexDifferences ,
100
+ indexFeatures : IndexFeatures
101
+ ) : MediaWikiContent [ ] => {
102
+ const fileDifferences = Object . values ( indexDifferences ) . map (
103
+ ( archive ) => archive [ 0 ]
104
+ ) ;
105
+ const addedResults : Result [ ] = _ . pluck ( fileDifferences , "added" ) . filter (
106
+ ( entry ) => entry !== null && entry !== undefined
107
+ ) ;
108
+
109
+ const removedResults : Result [ ] = _ . pluck ( fileDifferences , "removed" ) . filter (
110
+ ( entry ) => entry !== null && entry !== undefined
111
+ ) ;
112
+
113
+ const changedResults : ChangedResult [ ] = _ . pluck (
114
+ fileDifferences ,
115
+ "changed"
116
+ ) . filter (
117
+ ( entry ) =>
118
+ entry !== null && entry !== undefined && Object . keys ( entry ) . length > 0
119
+ ) ;
120
+
121
+ const content : MediaWikiContent [ ] = [
122
+ new MediaWikiHeader ( indexFeatures . name , 2 ) ,
123
+ new MediaWikiBreak ( ) ,
124
+ ...buildResultTable ( addedResults , indexFeatures , "added" ) ,
125
+ ...buildResultTable ( removedResults , indexFeatures , "removed" ) ,
126
+ ...buildChangedResultTable ( changedResults , indexFeatures ) ,
127
+ ] ;
128
+
129
+ return content ;
130
+ } ;
131
+
84
132
/**
85
133
* Build the media wiki content for the differences in two cache archive files.
86
134
* @param archiveDifferences Differences between two cache's archives
@@ -91,12 +139,30 @@ const buildArchiveDifferences = (
91
139
archiveDifferences : ArchiveDifferences ,
92
140
indexFeatures : IndexFeatures
93
141
) : MediaWikiContent [ ] => {
142
+ const addedResults : Result [ ] = _ . pluck (
143
+ Object . values ( archiveDifferences ) ,
144
+ "added"
145
+ ) . filter ( ( entry ) => entry !== null && entry !== undefined ) ;
146
+
147
+ const removedResults : Result [ ] = _ . pluck (
148
+ Object . values ( archiveDifferences ) ,
149
+ "removed"
150
+ ) . filter ( ( entry ) => entry !== null && entry !== undefined ) ;
151
+
152
+ const changedResults : ChangedResult [ ] = _ . pluck (
153
+ Object . values ( archiveDifferences ) ,
154
+ "changed"
155
+ ) . filter (
156
+ ( entry ) =>
157
+ entry !== null && entry !== undefined && Object . keys ( entry ) . length > 0
158
+ ) ;
159
+
94
160
const content : MediaWikiContent [ ] = [
95
161
new MediaWikiHeader ( indexFeatures . name , 2 ) ,
96
162
new MediaWikiBreak ( ) ,
97
- ...buildFullResultTable ( archiveDifferences , indexFeatures , "added" ) ,
98
- ...buildFullResultTable ( archiveDifferences , indexFeatures , "removed" ) ,
99
- ...buildChangedResultTable ( archiveDifferences , indexFeatures ) ,
163
+ ...buildResultTable ( addedResults , indexFeatures , "added" ) ,
164
+ ...buildResultTable ( removedResults , indexFeatures , "removed" ) ,
165
+ ...buildChangedResultTable ( changedResults , indexFeatures ) ,
100
166
] ;
101
167
102
168
return content ;
@@ -110,22 +176,15 @@ const buildArchiveDifferences = (
110
176
* @returns {MediaWikiContent[] }
111
177
*/
112
178
const buildChangedResultTable = (
113
- archiveDifferences : ArchiveDifferences ,
179
+ changedResults : ChangedResult [ ] ,
114
180
indexFeatures : IndexFeatures
115
181
) => {
116
182
const differenceName = resultNameMap . changed ;
117
183
const content : MediaWikiContent [ ] = [ ] ;
118
- const entries : ChangedResult [ ] = _ . pluck (
119
- Object . values ( archiveDifferences ) ,
120
- "changed"
121
- ) . filter (
122
- ( entry ) =>
123
- entry !== null && entry !== undefined && Object . keys ( entry ) . length > 0
124
- ) ;
125
184
126
185
const rows : MediaWikiTableRow [ ] =
127
- entries ?. length > 0
128
- ? entries
186
+ changedResults ?. length > 0
187
+ ? changedResults
129
188
. map < MediaWikiTableRow [ ] > ( ( entry ) => {
130
189
const diffKeys = Object . keys ( entry ) . filter ( ( key ) => {
131
190
const isIdentifier = (
@@ -214,23 +273,19 @@ const buildChangedResultTable = (
214
273
* @param type Definition for added or removed content
215
274
* @returns
216
275
*/
217
- const buildFullResultTable = (
218
- archiveDifferences : ArchiveDifferences ,
276
+ const buildResultTable = (
277
+ results : Result [ ] ,
219
278
indexFeatures : IndexFeatures ,
220
279
type : Difference
221
280
) : MediaWikiContent [ ] => {
222
281
const differenceName = resultNameMap [ type ] ;
223
282
const tableFields = indexFeatures . fields . map ( ( field ) => field . toString ( ) ) ;
224
283
const fields = [ ...indexFeatures . identifiers , ...tableFields ] ;
225
284
const content : MediaWikiContent [ ] = [ ] ;
226
- const entries : Result [ ] = _ . pluck (
227
- Object . values ( archiveDifferences ) ,
228
- type
229
- ) . filter ( ( entry ) => entry !== null && entry !== undefined ) ;
230
285
231
286
const rows : MediaWikiTableRow [ ] =
232
- entries ?. length > 0
233
- ? entries . map ( ( entry ) => {
287
+ results ?. length > 0
288
+ ? results . map ( ( entry ) => {
234
289
const identifierCells = indexFeatures . identifiers . map (
235
290
( identifier ) => ( {
236
291
content : formatEntryIdentifier (
0 commit comments