@opentermsarchive/engine 0.26.1 → 0.27.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.
- package/bin/ota-track.js +3 -3
- package/bin/ota-validate.js +2 -2
- package/bin/ota.js +1 -1
- package/config/default.json +1 -1
- package/package.json +3 -4
- package/scripts/dataset/export/index.js +4 -4
- package/scripts/dataset/export/index.test.js +11 -17
- package/scripts/declarations/lint/index.mocha.js +1 -1
- package/scripts/declarations/utils/index.js +12 -12
- package/scripts/declarations/validate/definitions.js +1 -1
- package/scripts/declarations/validate/index.mocha.js +30 -34
- package/scripts/declarations/validate/service.history.schema.js +11 -11
- package/scripts/declarations/validate/service.schema.js +13 -13
- package/scripts/history/migrate-services.js +4 -4
- package/scripts/history/update-to-full-hash.js +2 -2
- package/scripts/import/index.js +14 -14
- package/scripts/rewrite/rewrite-snapshots.js +3 -3
- package/scripts/rewrite/rewrite-versions.js +14 -14
- package/scripts/utils/renamer/README.md +3 -3
- package/scripts/utils/renamer/index.js +13 -13
- package/src/archivist/errors.js +1 -1
- package/src/archivist/extract/exports.js +3 -0
- package/src/archivist/{filter → extract}/index.js +23 -27
- package/src/archivist/extract/index.test.js +516 -0
- package/src/archivist/index.js +101 -140
- package/src/archivist/index.test.js +178 -166
- package/src/archivist/recorder/index.js +11 -55
- package/src/archivist/recorder/index.test.js +310 -356
- package/src/archivist/recorder/record.js +18 -7
- package/src/archivist/recorder/repositories/git/dataMapper.js +41 -31
- package/src/archivist/recorder/repositories/git/index.js +11 -15
- package/src/archivist/recorder/repositories/git/index.test.js +1058 -463
- package/src/archivist/recorder/repositories/interface.js +8 -6
- package/src/archivist/recorder/repositories/mongo/dataMapper.js +21 -14
- package/src/archivist/recorder/repositories/mongo/index.js +8 -8
- package/src/archivist/recorder/repositories/mongo/index.test.js +898 -479
- package/src/archivist/recorder/snapshot.js +5 -0
- package/src/archivist/recorder/snapshot.test.js +65 -0
- package/src/archivist/recorder/version.js +14 -0
- package/src/archivist/recorder/version.test.js +65 -0
- package/src/archivist/services/index.js +60 -51
- package/src/archivist/services/index.test.js +63 -83
- package/src/archivist/services/service.js +26 -22
- package/src/archivist/services/service.test.js +46 -68
- package/src/archivist/services/{pageDeclaration.js → sourceDocument.js} +11 -9
- package/src/archivist/services/{pageDeclaration.test.js → sourceDocument.test.js} +21 -21
- package/src/archivist/services/terms.js +26 -0
- package/src/archivist/services/{documentDeclaration.test.js → terms.test.js} +15 -15
- package/src/exports.js +2 -2
- package/src/index.js +16 -13
- package/src/logger/index.js +35 -36
- package/src/notifier/index.js +8 -8
- package/src/tracker/index.js +6 -6
- package/src/archivist/filter/exports.js +0 -3
- package/src/archivist/filter/index.test.js +0 -564
- package/src/archivist/recorder/record.test.js +0 -91
- package/src/archivist/services/documentDeclaration.js +0 -26
- /package/scripts/utils/renamer/rules/{documentTypes.json → termsTypes.json} +0 -0
- /package/scripts/utils/renamer/rules/{documentTypesByService.json → termsTypesByService.json} +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @see {@link https://martinfowler.com/eaaCatalog/repository.html|Repository}
|
|
4
4
|
* @interface
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
class RepositoryInterface {
|
|
7
7
|
/**
|
|
8
8
|
* [Optional] Initialize repository
|
|
9
9
|
* Override this method if the repository needs some asynchronous initialization code (open database connection and create collections, initialize Git…)
|
|
@@ -35,15 +35,15 @@ export default class RepositoryInterface {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* Find the most recent record that matches the given service ID and terms type and optionally the
|
|
39
|
-
* In case of snapshots, if the record is related to
|
|
38
|
+
* Find the most recent record that matches the given service ID and terms type and optionally the document ID
|
|
39
|
+
* In case of snapshots, if the record is related to terms extracted from multiple source documents, the document ID is required to find the source snapshot
|
|
40
40
|
*
|
|
41
41
|
* @param {string} serviceId - Service ID of record to find
|
|
42
|
-
* @param {string}
|
|
43
|
-
* @param {string} [
|
|
42
|
+
* @param {string} termsType - Terms type of record to find
|
|
43
|
+
* @param {string} [documentId] - Document ID of record to find. Used to identify the source in terms extracted from multiple source documents. Not necessary for terms with a single source document
|
|
44
44
|
* @returns {Promise<Record>} Promise that will be resolved with the found record or an empty object if none match the given criteria
|
|
45
45
|
*/
|
|
46
|
-
async findLatest(serviceId,
|
|
46
|
+
async findLatest(serviceId, termsType, documentId) {
|
|
47
47
|
throw new Error(`#findLatest method is not implemented in ${this.constructor.name}`);
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -106,3 +106,5 @@ export default class RepositoryInterface {
|
|
|
106
106
|
throw new Error(`#loadRecordContent method is not implemented in ${this.constructor.name}`);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
+
|
|
110
|
+
export default RepositoryInterface;
|
|
@@ -1,32 +1,39 @@
|
|
|
1
1
|
import { ObjectId } from 'mongodb';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import Snapshot from '../../snapshot.js';
|
|
4
|
+
import Version from '../../version.js';
|
|
4
5
|
|
|
5
6
|
export function toPersistence(record) {
|
|
6
|
-
const
|
|
7
|
+
const recordFields = Object.fromEntries(Object.entries(record));
|
|
7
8
|
|
|
8
|
-
if (
|
|
9
|
-
|
|
9
|
+
if (recordFields.snapshotIds) {
|
|
10
|
+
recordFields.snapshotIds = record.snapshotIds.map(snapshotId => new ObjectId(snapshotId));
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
recordFields.content = record.content;
|
|
14
|
+
recordFields.created_at = new Date();
|
|
14
15
|
|
|
15
|
-
return
|
|
16
|
+
return recordFields;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export function toDomain(
|
|
19
|
-
const { _id, serviceId,
|
|
19
|
+
export function toDomain(mongoDocument) {
|
|
20
|
+
const { _id, serviceId, termsType, documentId, fetchDate, mimeType, isExtractOnly, isRefilter, isFirstRecord, snapshotIds } = mongoDocument;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
const attributes = {
|
|
22
23
|
id: _id.toString(),
|
|
23
24
|
serviceId,
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
termsType,
|
|
26
|
+
documentId,
|
|
26
27
|
mimeType,
|
|
27
28
|
fetchDate: new Date(fetchDate),
|
|
28
29
|
isFirstRecord: Boolean(isFirstRecord),
|
|
29
|
-
|
|
30
|
+
isExtractOnly: Boolean(isExtractOnly) || Boolean(isRefilter),
|
|
30
31
|
snapshotIds: snapshotIds?.map(snapshotId => snapshotId.toString()) || [],
|
|
31
|
-
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (snapshotIds) {
|
|
35
|
+
return new Version(attributes);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return new Snapshot(attributes);
|
|
32
39
|
}
|
|
@@ -32,14 +32,14 @@ export default class MongoRepository extends RepositoryInterface {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
async save(record) {
|
|
35
|
-
const { serviceId,
|
|
35
|
+
const { serviceId, termsType } = record;
|
|
36
36
|
|
|
37
37
|
if (record.isFirstRecord === undefined || record.isFirstRecord === null) {
|
|
38
|
-
record.isFirstRecord = !await this.collection.findOne({ serviceId,
|
|
38
|
+
record.isFirstRecord = !await this.collection.findOne({ serviceId, termsType });
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const documentFields = await this.#toPersistence(record);
|
|
42
|
-
const previousRecord = await this.findLatest(serviceId,
|
|
42
|
+
const previousRecord = await this.findLatest(serviceId, termsType);
|
|
43
43
|
|
|
44
44
|
if (previousRecord?.content == documentFields.content) {
|
|
45
45
|
return Object(null);
|
|
@@ -52,8 +52,8 @@ export default class MongoRepository extends RepositoryInterface {
|
|
|
52
52
|
return record;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
async findLatest(serviceId,
|
|
56
|
-
const [mongoDocument] = await this.collection.find({ serviceId,
|
|
55
|
+
async findLatest(serviceId, termsType) {
|
|
56
|
+
const [mongoDocument] = await this.collection.find({ serviceId, termsType }).limit(1).sort({ fetchDate: -1 }).toArray(); // `findOne` doesn't support the `sort` method, so even for only one mongo document use `find`
|
|
57
57
|
|
|
58
58
|
return this.#toDomain(mongoDocument);
|
|
59
59
|
}
|
|
@@ -95,12 +95,12 @@ export default class MongoRepository extends RepositoryInterface {
|
|
|
95
95
|
record.content = content instanceof Binary ? content.buffer : content;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
async #toDomain(
|
|
99
|
-
if (!
|
|
98
|
+
async #toDomain(mongoDocument, { deferContentLoading } = {}) {
|
|
99
|
+
if (!mongoDocument) {
|
|
100
100
|
return null;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
const record = DataMapper.toDomain(
|
|
103
|
+
const record = DataMapper.toDomain(mongoDocument);
|
|
104
104
|
|
|
105
105
|
if (deferContentLoading) {
|
|
106
106
|
return record;
|