@opentermsarchive/engine 0.26.1 → 0.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +1 -3
  2. package/bin/ota-track.js +3 -3
  3. package/bin/ota-validate.js +2 -2
  4. package/bin/ota.js +1 -1
  5. package/config/default.json +1 -1
  6. package/package.json +3 -4
  7. package/scripts/dataset/export/index.js +4 -4
  8. package/scripts/dataset/export/index.test.js +11 -17
  9. package/scripts/declarations/lint/index.mocha.js +1 -1
  10. package/scripts/declarations/utils/index.js +12 -12
  11. package/scripts/declarations/validate/definitions.js +1 -1
  12. package/scripts/declarations/validate/index.mocha.js +30 -34
  13. package/scripts/declarations/validate/service.history.schema.js +11 -11
  14. package/scripts/declarations/validate/service.schema.js +13 -13
  15. package/scripts/history/migrate-services.js +4 -4
  16. package/scripts/history/update-to-full-hash.js +2 -2
  17. package/scripts/import/index.js +14 -14
  18. package/scripts/rewrite/rewrite-snapshots.js +3 -3
  19. package/scripts/rewrite/rewrite-versions.js +14 -14
  20. package/scripts/utils/renamer/README.md +3 -3
  21. package/scripts/utils/renamer/index.js +13 -13
  22. package/src/archivist/errors.js +1 -1
  23. package/src/archivist/extract/exports.js +3 -0
  24. package/src/archivist/{filter → extract}/index.js +23 -27
  25. package/src/archivist/extract/index.test.js +516 -0
  26. package/src/archivist/index.js +101 -140
  27. package/src/archivist/index.test.js +178 -166
  28. package/src/archivist/recorder/index.js +11 -55
  29. package/src/archivist/recorder/index.test.js +310 -356
  30. package/src/archivist/recorder/record.js +18 -7
  31. package/src/archivist/recorder/repositories/git/dataMapper.js +41 -31
  32. package/src/archivist/recorder/repositories/git/index.js +11 -15
  33. package/src/archivist/recorder/repositories/git/index.test.js +1058 -463
  34. package/src/archivist/recorder/repositories/interface.js +8 -6
  35. package/src/archivist/recorder/repositories/mongo/dataMapper.js +21 -14
  36. package/src/archivist/recorder/repositories/mongo/index.js +8 -8
  37. package/src/archivist/recorder/repositories/mongo/index.test.js +898 -479
  38. package/src/archivist/recorder/snapshot.js +5 -0
  39. package/src/archivist/recorder/snapshot.test.js +65 -0
  40. package/src/archivist/recorder/version.js +14 -0
  41. package/src/archivist/recorder/version.test.js +65 -0
  42. package/src/archivist/services/index.js +60 -51
  43. package/src/archivist/services/index.test.js +63 -83
  44. package/src/archivist/services/service.js +26 -22
  45. package/src/archivist/services/service.test.js +46 -68
  46. package/src/archivist/services/{pageDeclaration.js → sourceDocument.js} +11 -9
  47. package/src/archivist/services/{pageDeclaration.test.js → sourceDocument.test.js} +21 -21
  48. package/src/archivist/services/terms.js +26 -0
  49. package/src/archivist/services/{documentDeclaration.test.js → terms.test.js} +15 -15
  50. package/src/exports.js +2 -2
  51. package/src/index.js +16 -13
  52. package/src/logger/index.js +35 -36
  53. package/src/notifier/index.js +8 -8
  54. package/src/tracker/index.js +6 -6
  55. package/src/archivist/filter/exports.js +0 -3
  56. package/src/archivist/filter/index.test.js +0 -564
  57. package/src/archivist/recorder/record.test.js +0 -91
  58. package/src/archivist/services/documentDeclaration.js +0 -26
  59. /package/scripts/utils/renamer/rules/{documentTypes.json → termsTypes.json} +0 -0
  60. /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
- export default class RepositoryInterface {
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 page ID
39
- * In case of snapshots, if the record is related to a multipage document, the page ID is required to find the corresponding snapshot
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} documentType - Terms type of record to find
43
- * @param {string} [pageId] - Page ID of record to find. Used to differentiate pages of multipage document. Not necessary for single page document
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, documentType, pageId) {
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 Record from '../../record.js';
3
+ import Snapshot from '../../snapshot.js';
4
+ import Version from '../../version.js';
4
5
 
5
6
  export function toPersistence(record) {
6
- const documentFields = Object.fromEntries(Object.entries(record));
7
+ const recordFields = Object.fromEntries(Object.entries(record));
7
8
 
8
- if (documentFields.snapshotIds) {
9
- documentFields.snapshotIds = record.snapshotIds.map(snapshotId => new ObjectId(snapshotId));
9
+ if (recordFields.snapshotIds) {
10
+ recordFields.snapshotIds = record.snapshotIds.map(snapshotId => new ObjectId(snapshotId));
10
11
  }
11
12
 
12
- documentFields.content = record.content;
13
- documentFields.created_at = new Date();
13
+ recordFields.content = record.content;
14
+ recordFields.created_at = new Date();
14
15
 
15
- return documentFields;
16
+ return recordFields;
16
17
  }
17
18
 
18
- export function toDomain(document) {
19
- const { _id, serviceId, documentType, pageId, fetchDate, mimeType, isRefilter, isFirstRecord, snapshotIds } = document;
19
+ export function toDomain(mongoDocument) {
20
+ const { _id, serviceId, termsType, documentId, fetchDate, mimeType, isExtractOnly, isRefilter, isFirstRecord, snapshotIds } = mongoDocument;
20
21
 
21
- return new Record({
22
+ const attributes = {
22
23
  id: _id.toString(),
23
24
  serviceId,
24
- documentType,
25
- pageId,
25
+ termsType,
26
+ documentId,
26
27
  mimeType,
27
28
  fetchDate: new Date(fetchDate),
28
29
  isFirstRecord: Boolean(isFirstRecord),
29
- isRefilter: Boolean(isRefilter),
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, documentType } = record;
35
+ const { serviceId, termsType } = record;
36
36
 
37
37
  if (record.isFirstRecord === undefined || record.isFirstRecord === null) {
38
- record.isFirstRecord = !await this.collection.findOne({ serviceId, documentType });
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, documentType);
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, documentType) {
56
- const [mongoDocument] = await this.collection.find({ serviceId, documentType }).limit(1).sort({ fetchDate: -1 }).toArray(); // `findOne` doesn't support the `sort` method, so even for only one document use `find`
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(document, { deferContentLoading } = {}) {
99
- if (!document) {
98
+ async #toDomain(mongoDocument, { deferContentLoading } = {}) {
99
+ if (!mongoDocument) {
100
100
  return null;
101
101
  }
102
102
 
103
- const record = DataMapper.toDomain(document);
103
+ const record = DataMapper.toDomain(mongoDocument);
104
104
 
105
105
  if (deferContentLoading) {
106
106
  return record;