glossarist 0.4.48 → 0.4.50
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.
- package/package.json +1 -1
- package/src/concept-collection.ts +7 -1
- package/src/concept-parser.ts +7 -1
- package/src/concept-reader.ts +4 -3
- package/src/concept-serializer.ts +12 -1
- package/src/concept-writer.ts +5 -1
- package/src/diff/collection-diff.ts +49 -1
- package/src/diff/concept-diff.ts +152 -1
- package/src/diff/diff-patch.ts +17 -1
- package/src/diff/diff-renderer.ts +56 -1
- package/src/gcr-reader.ts +26 -1
- package/src/gcr-writer.ts +3 -1
- package/src/managed-concept-collection.ts +36 -1
- package/src/rdf/agents-emitter.ts +8 -5
- package/src/rdf/bibliography-emitter.ts +2 -3
- package/src/rdf/curie.ts +1 -1
- package/src/rdf/document-writer.ts +1 -2
- package/src/rdf/gloss-concept.ts +3 -3
- package/src/rdf/gloss-designation.ts +2 -3
- package/src/rdf/gloss-non-verbal-rep.ts +11 -1
- package/src/rdf/sections-builder.ts +13 -1
- package/src/rdf/shacl.ts +2 -1
- package/src/rdf/write-turtle-sync.ts +13 -1
- package/src/reference-resolver.ts +31 -1
- package/src/render-classification.ts +10 -1
- package/src/v1-reader.ts +3 -1
- package/src/validators/asset-index.ts +6 -1
- package/src/validators/concept-validator.ts +2 -1
- package/src/validators/gcr-validator.ts +2 -1
- package/src/validators/v3-rules.ts +5 -1
package/src/diff/concept-diff.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
2
1
|
import { GlossaristModel } from '../models/base.js';
|
|
3
2
|
import { PartitiveHyperedge } from '../models/partitive-hyperedge.js';
|
|
4
3
|
import { GenericHyperedge } from '../models/generic-hyperedge.js';
|
|
@@ -35,17 +34,25 @@ const LOCALIZATION_METADATA_FIELDS = Object.freeze([
|
|
|
35
34
|
export class DiffStats extends GlossaristModel {
|
|
36
35
|
constructor(data: Record<string, unknown> = {}) {
|
|
37
36
|
super();
|
|
37
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
38
38
|
this._added = data.added ?? 0;
|
|
39
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
39
40
|
this._removed = data.removed ?? 0;
|
|
41
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
40
42
|
this._changed = data.changed ?? 0;
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
43
46
|
get added() { return this._added; }
|
|
47
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
44
48
|
get removed() { return this._removed; }
|
|
49
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
45
50
|
get changed() { return this._changed; }
|
|
51
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
46
52
|
get total() { return this._added + this._removed + this._changed; }
|
|
47
53
|
|
|
48
54
|
toJSON() {
|
|
55
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
49
56
|
return { added: this._added, removed: this._removed, changed: this._changed };
|
|
50
57
|
}
|
|
51
58
|
|
|
@@ -57,26 +64,32 @@ export class DiffStats extends GlossaristModel {
|
|
|
57
64
|
export class MetadataDiff extends GlossaristModel {
|
|
58
65
|
constructor(data: Record<string, unknown> = {}) {
|
|
59
66
|
super();
|
|
67
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
60
68
|
this._changes = {};
|
|
61
69
|
const raw = data.changes ?? data ?? {};
|
|
62
70
|
for (const [field, change] of Object.entries(raw)) {
|
|
71
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
63
72
|
this._changes[field] = change instanceof Changed ? change : Changed.fromJSON(change);
|
|
64
73
|
}
|
|
65
74
|
}
|
|
66
75
|
|
|
67
76
|
get changes() {
|
|
77
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
68
78
|
return this._changes;
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
get hasChanges() {
|
|
82
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
72
83
|
return Object.keys(this._changes).length > 0;
|
|
73
84
|
}
|
|
74
85
|
|
|
75
86
|
get count() {
|
|
87
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
76
88
|
return Object.keys(this._changes).length;
|
|
77
89
|
}
|
|
78
90
|
|
|
79
91
|
*walk(section) {
|
|
92
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
80
93
|
for (const [field, change] of Object.entries(this._changes)) {
|
|
81
94
|
const path = section ? `${section}.${field}` : field;
|
|
82
95
|
yield { path, change };
|
|
@@ -85,7 +98,9 @@ export class MetadataDiff extends GlossaristModel {
|
|
|
85
98
|
|
|
86
99
|
toJSON() {
|
|
87
100
|
const obj = {};
|
|
101
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
88
102
|
for (const [field, change] of Object.entries(this._changes)) {
|
|
103
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
89
104
|
obj[field] = change.toJSON();
|
|
90
105
|
}
|
|
91
106
|
return obj;
|
|
@@ -99,8 +114,11 @@ export class MetadataDiff extends GlossaristModel {
|
|
|
99
114
|
export class ConceptLevelDiff extends GlossaristModel {
|
|
100
115
|
constructor(data: Record<string, unknown> = {}) {
|
|
101
116
|
super();
|
|
117
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
102
118
|
this._sources = wrapListDiff(data.sources);
|
|
119
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
103
120
|
this._dates = wrapListDiff(data.dates);
|
|
121
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
104
122
|
this._relatedConcepts = wrapListDiff(data.relatedConcepts ?? data.related_concepts);
|
|
105
123
|
// Unified hyperedge diff. Accepts:
|
|
106
124
|
// - data.relations (new unified shape)
|
|
@@ -110,6 +128,7 @@ export class ConceptLevelDiff extends GlossaristModel {
|
|
|
110
128
|
// data.partitive_hyperedges (legacy partitive-only shape)
|
|
111
129
|
// Old diffs only had partitive, so the legacy fallback treats them
|
|
112
130
|
// as a unified list with one type present.
|
|
131
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
113
132
|
this._relations = wrapListDiff(
|
|
114
133
|
data.relations
|
|
115
134
|
?? data.partitiveRelations
|
|
@@ -117,18 +136,26 @@ export class ConceptLevelDiff extends GlossaristModel {
|
|
|
117
136
|
?? data.partitiveHyperedges
|
|
118
137
|
?? data.partitive_hyperedges,
|
|
119
138
|
);
|
|
139
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
120
140
|
this._groups = wrapListDiff(data.groups);
|
|
141
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
121
142
|
this._sections = wrapListDiff(data.sections);
|
|
143
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
122
144
|
this._tags = wrapListDiff(data.tags);
|
|
145
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
123
146
|
this._metadata = data.metadata instanceof MetadataDiff
|
|
124
147
|
? data.metadata
|
|
125
148
|
: MetadataDiff.fromJSON(data.metadata ?? {});
|
|
126
149
|
}
|
|
127
150
|
|
|
151
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
128
152
|
get sources() { return this._sources; }
|
|
153
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
129
154
|
get dates() { return this._dates; }
|
|
155
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
130
156
|
get relatedConcepts() { return this._relatedConcepts; }
|
|
131
157
|
/** Unified hyperedge diff (PartitiveHyperedge + GenericHyperedge). */
|
|
158
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
132
159
|
get relations() { return this._relations; }
|
|
133
160
|
/**
|
|
134
161
|
* Filtered view of `relations` containing only PartitiveHyperedge
|
|
@@ -136,6 +163,7 @@ export class ConceptLevelDiff extends GlossaristModel {
|
|
|
136
163
|
* directly on a ConceptLevelDiff.
|
|
137
164
|
*/
|
|
138
165
|
get partitiveRelations() {
|
|
166
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
139
167
|
return filterListDiffByType(this._relations, PartitiveHyperedge);
|
|
140
168
|
}
|
|
141
169
|
/** @deprecated use .relations */ get partitiveHyperedges() { return this.partitiveRelations; }
|
|
@@ -145,44 +173,73 @@ export class ConceptLevelDiff extends GlossaristModel {
|
|
|
145
173
|
* directly on a ConceptLevelDiff.
|
|
146
174
|
*/
|
|
147
175
|
get genericRelations() {
|
|
176
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
148
177
|
return filterListDiffByType(this._relations, GenericHyperedge);
|
|
149
178
|
}
|
|
179
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
150
180
|
get groups() { return this._groups; }
|
|
181
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
151
182
|
get sections() { return this._sections; }
|
|
183
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
152
184
|
get tags() { return this._tags; }
|
|
185
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
153
186
|
get metadata() { return this._metadata; }
|
|
154
187
|
|
|
155
188
|
get hasChanges() {
|
|
189
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
156
190
|
return this._sources.hasChanges
|
|
191
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
157
192
|
|| this._dates.hasChanges
|
|
193
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
158
194
|
|| this._relatedConcepts.hasChanges
|
|
195
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
159
196
|
|| this._relations.hasChanges
|
|
197
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
160
198
|
|| this._groups.hasChanges
|
|
199
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
161
200
|
|| this._sections.hasChanges
|
|
201
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
162
202
|
|| this._tags.hasChanges
|
|
203
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
163
204
|
|| this._metadata.hasChanges;
|
|
164
205
|
}
|
|
165
206
|
|
|
166
207
|
*walk() {
|
|
208
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
167
209
|
yield* walkList('concept.sources', this._sources);
|
|
210
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
168
211
|
yield* walkList('concept.dates', this._dates);
|
|
212
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
169
213
|
yield* walkList('concept.relatedConcepts', this._relatedConcepts);
|
|
214
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
170
215
|
yield* walkList('concept.relations', this._relations);
|
|
216
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
171
217
|
yield* walkList('concept.groups', this._groups);
|
|
218
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
172
219
|
yield* walkList('concept.sections', this._sections);
|
|
220
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
173
221
|
yield* walkList('concept.tags', this._tags);
|
|
222
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
174
223
|
yield* this._metadata.walk('concept.metadata');
|
|
175
224
|
}
|
|
176
225
|
|
|
177
226
|
toJSON() {
|
|
178
227
|
return {
|
|
228
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
179
229
|
sources: this._sources.toJSON(),
|
|
230
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
180
231
|
dates: this._dates.toJSON(),
|
|
232
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
181
233
|
related_concepts: this._relatedConcepts.toJSON(),
|
|
234
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
182
235
|
relations: this._relations.toJSON(),
|
|
236
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
183
237
|
groups: this._groups.toJSON(),
|
|
238
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
184
239
|
sections: this._sections.toJSON(),
|
|
240
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
185
241
|
tags: this._tags.toJSON(),
|
|
242
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
186
243
|
metadata: this._metadata.toJSON(),
|
|
187
244
|
};
|
|
188
245
|
}
|
|
@@ -195,80 +252,133 @@ export class ConceptLevelDiff extends GlossaristModel {
|
|
|
195
252
|
export class LocalizedConceptDiff extends GlossaristModel {
|
|
196
253
|
constructor(data: Record<string, unknown> = {}) {
|
|
197
254
|
super();
|
|
255
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
198
256
|
this.languageCode = data.languageCode ?? data.language_code ?? null;
|
|
257
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
199
258
|
this._designations = wrapListDiff(data.designations);
|
|
259
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
200
260
|
this._definitions = wrapListDiff(data.definitions);
|
|
261
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
201
262
|
this._notes = wrapListDiff(data.notes);
|
|
263
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
202
264
|
this._examples = wrapListDiff(data.examples);
|
|
265
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
203
266
|
this._sources = wrapListDiff(data.sources);
|
|
267
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
204
268
|
this._dates = wrapListDiff(data.dates);
|
|
269
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
205
270
|
this._related = wrapListDiff(data.related);
|
|
271
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
206
272
|
this._metadata = data.metadata instanceof MetadataDiff
|
|
207
273
|
? data.metadata
|
|
208
274
|
: MetadataDiff.fromJSON(data.metadata ?? {});
|
|
275
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
209
276
|
this._totalItems = data.totalItems ?? data.total_items ?? 0;
|
|
277
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
210
278
|
this._statsCache = undefined;
|
|
279
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
211
280
|
this._similarityCache = undefined;
|
|
212
281
|
}
|
|
213
282
|
|
|
283
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
214
284
|
get designations() { return this._designations; }
|
|
285
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
215
286
|
get definitions() { return this._definitions; }
|
|
287
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
216
288
|
get notes() { return this._notes; }
|
|
289
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
217
290
|
get examples() { return this._examples; }
|
|
291
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
218
292
|
get sources() { return this._sources; }
|
|
293
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
219
294
|
get dates() { return this._dates; }
|
|
295
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
220
296
|
get related() { return this._related; }
|
|
297
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
221
298
|
get metadata() { return this._metadata; }
|
|
299
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
222
300
|
get totalItems() { return this._totalItems; }
|
|
223
301
|
|
|
224
302
|
get hasChanges() {
|
|
303
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
225
304
|
return this._designations.hasChanges
|
|
305
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
226
306
|
|| this._definitions.hasChanges
|
|
307
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
227
308
|
|| this._notes.hasChanges
|
|
309
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
228
310
|
|| this._examples.hasChanges
|
|
311
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
229
312
|
|| this._sources.hasChanges
|
|
313
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
230
314
|
|| this._dates.hasChanges
|
|
315
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
231
316
|
|| this._related.hasChanges
|
|
317
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
232
318
|
|| this._metadata.hasChanges;
|
|
233
319
|
}
|
|
234
320
|
|
|
235
321
|
get stats() {
|
|
322
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
236
323
|
if (this._statsCache === undefined) {
|
|
324
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
237
325
|
this._statsCache = collectStats(this.walk());
|
|
238
326
|
}
|
|
327
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
239
328
|
return this._statsCache;
|
|
240
329
|
}
|
|
241
330
|
|
|
242
331
|
get similarity() {
|
|
332
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
243
333
|
if (this._similarityCache === undefined) {
|
|
334
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
244
335
|
this._similarityCache = computeSimilarity(this.stats.total, this._totalItems);
|
|
245
336
|
}
|
|
337
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
246
338
|
return this._similarityCache;
|
|
247
339
|
}
|
|
248
340
|
|
|
249
341
|
*walk(prefix) {
|
|
250
342
|
const base = prefix ?? '';
|
|
343
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
251
344
|
yield* walkList(`${base}.designations`, this._designations);
|
|
345
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
252
346
|
yield* walkList(`${base}.definitions`, this._definitions);
|
|
347
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
253
348
|
yield* walkList(`${base}.notes`, this._notes);
|
|
349
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
254
350
|
yield* walkList(`${base}.examples`, this._examples);
|
|
351
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
255
352
|
yield* walkList(`${base}.sources`, this._sources);
|
|
353
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
256
354
|
yield* walkList(`${base}.dates`, this._dates);
|
|
355
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
257
356
|
yield* walkList(`${base}.related`, this._related);
|
|
357
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
258
358
|
yield* this._metadata.walk(`${base}.metadata`);
|
|
259
359
|
}
|
|
260
360
|
|
|
261
361
|
toJSON() {
|
|
262
362
|
const obj = {};
|
|
363
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
263
364
|
if (this.languageCode != null) obj.language_code = this.languageCode;
|
|
365
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
264
366
|
obj.designations = this._designations.toJSON();
|
|
367
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
265
368
|
obj.definitions = this._definitions.toJSON();
|
|
369
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
266
370
|
obj.notes = this._notes.toJSON();
|
|
371
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
267
372
|
obj.examples = this._examples.toJSON();
|
|
373
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
268
374
|
obj.sources = this._sources.toJSON();
|
|
375
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
269
376
|
obj.dates = this._dates.toJSON();
|
|
377
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
270
378
|
obj.related = this._related.toJSON();
|
|
379
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
271
380
|
obj.metadata = this._metadata.toJSON();
|
|
381
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
272
382
|
obj.total_items = this._totalItems;
|
|
273
383
|
return obj;
|
|
274
384
|
}
|
|
@@ -281,63 +391,93 @@ export class LocalizedConceptDiff extends GlossaristModel {
|
|
|
281
391
|
export class ConceptDiff extends GlossaristModel {
|
|
282
392
|
constructor(data: Record<string, unknown> = {}) {
|
|
283
393
|
super();
|
|
394
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
284
395
|
this._oldId = data.oldId ?? data.old_id ?? null;
|
|
396
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
285
397
|
this._newId = data.newId ?? data.new_id ?? null;
|
|
398
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
286
399
|
this._concept = data.concept instanceof ConceptLevelDiff
|
|
287
400
|
? data.concept
|
|
288
401
|
: ConceptLevelDiff.fromJSON(data.concept ?? {});
|
|
402
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
289
403
|
this._languages = wrapListDiff(data.languages);
|
|
404
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
290
405
|
this._localizations = {};
|
|
291
406
|
const raw = data.localizations ?? {};
|
|
292
407
|
for (const [lang, lcDiff] of Object.entries(raw)) {
|
|
408
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
293
409
|
this._localizations[lang] = lcDiff instanceof LocalizedConceptDiff
|
|
294
410
|
? lcDiff
|
|
295
411
|
: LocalizedConceptDiff.fromJSON(lcDiff);
|
|
296
412
|
}
|
|
413
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
297
414
|
this._totalItems = data.totalItems ?? data.total_items ?? 0;
|
|
415
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
298
416
|
this._statsCache = undefined;
|
|
417
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
299
418
|
this._similarityCache = undefined;
|
|
300
419
|
}
|
|
301
420
|
|
|
421
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
302
422
|
get oldId() { return this._oldId; }
|
|
423
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
303
424
|
get newId() { return this._newId; }
|
|
425
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
304
426
|
get concept() { return this._concept; }
|
|
427
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
305
428
|
get languages() { return this._languages; }
|
|
429
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
306
430
|
get localizations() { return this._localizations; }
|
|
431
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
307
432
|
get totalItems() { return this._totalItems; }
|
|
308
433
|
|
|
309
434
|
get localizationLanguages() {
|
|
435
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
310
436
|
return Object.keys(this._localizations);
|
|
311
437
|
}
|
|
312
438
|
|
|
313
439
|
get hasChanges() {
|
|
440
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
314
441
|
return this._concept.hasChanges
|
|
442
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
315
443
|
|| this._languages.hasChanges
|
|
444
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
316
445
|
|| Object.values(this._localizations).some(lc => lc.hasChanges);
|
|
317
446
|
}
|
|
318
447
|
|
|
319
448
|
localization(lang) {
|
|
449
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
320
450
|
return this._localizations[lang] ?? null;
|
|
321
451
|
}
|
|
322
452
|
|
|
323
453
|
get stats() {
|
|
454
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
324
455
|
if (this._statsCache === undefined) {
|
|
456
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
325
457
|
this._statsCache = collectStats(this.walk());
|
|
326
458
|
}
|
|
459
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
327
460
|
return this._statsCache;
|
|
328
461
|
}
|
|
329
462
|
|
|
330
463
|
get similarity() {
|
|
464
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
331
465
|
if (this._similarityCache === undefined) {
|
|
466
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
332
467
|
this._similarityCache = computeSimilarity(this.stats.total, this._totalItems);
|
|
333
468
|
}
|
|
469
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
334
470
|
return this._similarityCache;
|
|
335
471
|
}
|
|
336
472
|
|
|
337
473
|
*walk() {
|
|
474
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
338
475
|
yield* this._concept.walk();
|
|
476
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
339
477
|
yield* walkList('languages', this._languages);
|
|
478
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
340
479
|
for (const [lang, lc] of Object.entries(this._localizations)) {
|
|
480
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
341
481
|
for (const { path, change } of lc.walk(`localizations.${lang}`)) {
|
|
342
482
|
yield { path, change, language: lang };
|
|
343
483
|
}
|
|
@@ -346,14 +486,22 @@ export class ConceptDiff extends GlossaristModel {
|
|
|
346
486
|
|
|
347
487
|
toJSON() {
|
|
348
488
|
const obj = {};
|
|
489
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
349
490
|
if (this._oldId != null) obj.old_id = this._oldId;
|
|
491
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
350
492
|
if (this._newId != null) obj.new_id = this._newId;
|
|
493
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
351
494
|
obj.concept = this._concept.toJSON();
|
|
495
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
352
496
|
obj.languages = this._languages.toJSON();
|
|
497
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
353
498
|
obj.localizations = {};
|
|
499
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
354
500
|
for (const [lang, lc] of Object.entries(this._localizations)) {
|
|
501
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
355
502
|
obj.localizations[lang] = lc.toJSON();
|
|
356
503
|
}
|
|
504
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
357
505
|
obj.total_items = this._totalItems;
|
|
358
506
|
return obj;
|
|
359
507
|
}
|
|
@@ -531,12 +679,14 @@ function fullMetadataDiff(obj, fields, direction) {
|
|
|
531
679
|
function diffDesignations(oldTerms, newTerms) {
|
|
532
680
|
return diffSet(oldTerms, newTerms, {
|
|
533
681
|
identityKey: identityOf,
|
|
682
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
534
683
|
textKey: d => d?.designation ?? '',
|
|
535
684
|
});
|
|
536
685
|
}
|
|
537
686
|
|
|
538
687
|
function diffTextList(oldItems, newItems) {
|
|
539
688
|
return diffList(oldItems, newItems, {
|
|
689
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
540
690
|
textKey: d => d?.content ?? '',
|
|
541
691
|
});
|
|
542
692
|
}
|
|
@@ -550,6 +700,7 @@ function diffSources(oldSources, newSources) {
|
|
|
550
700
|
function diffDates(oldDates, newDates) {
|
|
551
701
|
return diffSet(oldDates, newDates, {
|
|
552
702
|
identityKey: identityOf,
|
|
703
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
553
704
|
textKey: d => d?.date ?? '',
|
|
554
705
|
});
|
|
555
706
|
}
|
package/src/diff/diff-patch.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
2
1
|
import { Concept } from '../models/concept.js';
|
|
3
2
|
import { ConceptSource } from '../models/concept-source.js';
|
|
4
3
|
import { ConceptDate } from '../models/concept-date.js';
|
|
@@ -80,15 +79,25 @@ export function reverseDiff(diff) {
|
|
|
80
79
|
const localizations = {};
|
|
81
80
|
for (const [lang, lcDiff] of Object.entries(diff.localizations)) {
|
|
82
81
|
localizations[lang] = new LocalizedConceptDiff({
|
|
82
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
83
83
|
languageCode: lcDiff.languageCode,
|
|
84
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
84
85
|
designations: reverseListDiff(lcDiff.designations),
|
|
86
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
85
87
|
definitions: reverseListDiff(lcDiff.definitions),
|
|
88
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
86
89
|
notes: reverseListDiff(lcDiff.notes),
|
|
90
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
87
91
|
examples: reverseListDiff(lcDiff.examples),
|
|
92
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
88
93
|
sources: reverseListDiff(lcDiff.sources),
|
|
94
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
89
95
|
dates: reverseListDiff(lcDiff.dates),
|
|
96
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
90
97
|
related: reverseListDiff(lcDiff.related),
|
|
98
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
91
99
|
metadata: reverseMetadataDiff(lcDiff.metadata),
|
|
100
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
92
101
|
totalItems: lcDiff._totalItems,
|
|
93
102
|
});
|
|
94
103
|
}
|
|
@@ -122,12 +131,14 @@ function applyConceptLevelPatch(json, conceptDiff) {
|
|
|
122
131
|
const existing = v1ReadKeys
|
|
123
132
|
.map(k => json[k])
|
|
124
133
|
.find(arr => Array.isArray(arr)) ?? json[wireKey] ?? [];
|
|
134
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
125
135
|
json[wireKey] = applyListPatch(existing, partition, cls.identityOf);
|
|
126
136
|
for (const k of v1ReadKeys) {
|
|
127
137
|
if (json[k] != null && json[wireKey] != null) delete json[k];
|
|
128
138
|
}
|
|
129
139
|
}
|
|
130
140
|
|
|
141
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
131
142
|
json.tags = applyListPatch(json.tags ?? [], conceptDiff.tags);
|
|
132
143
|
|
|
133
144
|
applyMetadataPatch(json, conceptDiff.metadata, CONCEPT_METADATA_JSON_KEYS);
|
|
@@ -190,9 +201,11 @@ function applyMetadataPatch(target, metadataDiff, keyMap) {
|
|
|
190
201
|
for (const [field, change] of Object.entries(metadataDiff.changes)) {
|
|
191
202
|
const jsonKey = keyMap[field];
|
|
192
203
|
if (!jsonKey) continue;
|
|
204
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
193
205
|
if (change.newValue == null) {
|
|
194
206
|
delete target[jsonKey];
|
|
195
207
|
} else {
|
|
208
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
196
209
|
target[jsonKey] = change.newValue;
|
|
197
210
|
}
|
|
198
211
|
}
|
|
@@ -204,6 +217,7 @@ function reverseListDiff(listDiff) {
|
|
|
204
217
|
const changed = listDiff.changed.map(c => new Changed({
|
|
205
218
|
oldValue: c.newValue,
|
|
206
219
|
newValue: c.oldValue,
|
|
220
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
207
221
|
textDiff: c.textDiff ? reverseTextDiff(c.textDiff) : null,
|
|
208
222
|
path: c.path,
|
|
209
223
|
}));
|
|
@@ -214,7 +228,9 @@ function reverseMetadataDiff(metadataDiff) {
|
|
|
214
228
|
const changes = {};
|
|
215
229
|
for (const [field, change] of Object.entries(metadataDiff.changes)) {
|
|
216
230
|
changes[field] = new Changed({
|
|
231
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
217
232
|
oldValue: change.newValue,
|
|
233
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
218
234
|
newValue: change.oldValue,
|
|
219
235
|
});
|
|
220
236
|
}
|