@opentermsarchive/engine 1.2.1 → 1.3.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.
@@ -30,7 +30,7 @@ export default class Git {
30
30
  .addConfig('core.quotePath', false); // disable Git's encoding of special characters in pathnames. For example, `service·A` will be encoded as `service\302\267A` without this setting, leading to issues. See https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath
31
31
  }
32
32
 
33
- async add(filePath) {
33
+ add(filePath) {
34
34
  return this.git.add(this.relativePath(filePath));
35
35
  }
36
36
 
@@ -55,11 +55,11 @@ export default class Git {
55
55
  return summary.commit;
56
56
  }
57
57
 
58
- async pushChanges() {
58
+ pushChanges() {
59
59
  return this.git.push();
60
60
  }
61
61
 
62
- async listCommits(options = []) {
62
+ listCommits(options = []) {
63
63
  return this.log([ '--reverse', '--no-merges', '--name-only', ...options ]);
64
64
  }
65
65
 
@@ -89,11 +89,11 @@ export default class Git {
89
89
  return Boolean(result);
90
90
  }
91
91
 
92
- async checkout(options) {
92
+ checkout(options) {
93
93
  return this.git.checkout(options);
94
94
  }
95
95
 
96
- async show(options) {
96
+ show(options) {
97
97
  return this.git.show(options);
98
98
  }
99
99
 
@@ -107,7 +107,7 @@ export default class Git {
107
107
  return (await this.git.show([ shortHash, '--pretty=%H', '-s' ])).trim();
108
108
  }
109
109
 
110
- async restore(path, commit) {
110
+ restore(path, commit) {
111
111
  return this.git.raw([ 'restore', '-s', commit, '--', path ]);
112
112
  }
113
113
 
@@ -100,7 +100,7 @@ export default class GitRepository extends RepositoryInterface {
100
100
  }
101
101
  }
102
102
 
103
- async removeAll() {
103
+ removeAll() {
104
104
  return this.git.destroyHistory();
105
105
  }
106
106
 
@@ -129,7 +129,9 @@ export default class GitRepository extends RepositoryInterface {
129
129
 
130
130
  async #getCommits() {
131
131
  return (await this.git.listCommits())
132
- .filter(({ message }) => message.match(DataMapper.COMMIT_MESSAGE_PREFIXES_REGEXP)) // Skip commits which are not a record (README, LICENSE…)
132
+ .filter(commit => // Skip non-record commits (e.g., README or LICENSE updates)
133
+ DataMapper.COMMIT_MESSAGE_PREFIXES_REGEXP.test(commit.message) // Commits generated by the engine have messages that match predefined prefixes
134
+ && path.dirname(commit.diff.files[0].file) !== '.') // Assumes one record per commit; records must be in a serviceId folder, not root
133
135
  .sort((commitA, commitB) => new Date(commitA.date) - new Date(commitB.date)); // Make sure that the commits are sorted in ascending chronological order
134
136
  }
135
137
 
@@ -91,7 +91,7 @@ describe('GitRepository', () => {
91
91
  ([commit] = await git.log());
92
92
  });
93
93
 
94
- after(async () => subject.removeAll());
94
+ after(() => subject.removeAll());
95
95
 
96
96
  it('saves the record', () => {
97
97
  expect(numberOfRecordsAfter).to.equal(numberOfRecordsBefore + 1);
@@ -158,7 +158,7 @@ describe('GitRepository', () => {
158
158
  ([commit] = await git.log());
159
159
  });
160
160
 
161
- after(async () => subject.removeAll());
161
+ after(() => subject.removeAll());
162
162
 
163
163
  it('saves the record', () => {
164
164
  expect(numberOfRecordsAfter).to.equal(numberOfRecordsBefore + 1);
@@ -194,7 +194,7 @@ describe('GitRepository', () => {
194
194
  numberOfRecordsAfter = (await git.log()).length;
195
195
  });
196
196
 
197
- after(async () => subject.removeAll());
197
+ after(() => subject.removeAll());
198
198
 
199
199
  it('does not save the record', () => {
200
200
  expect(numberOfRecordsAfter).to.equal(numberOfRecordsBefore);
@@ -232,7 +232,7 @@ describe('GitRepository', () => {
232
232
  ([commit] = await git.log());
233
233
  });
234
234
 
235
- after(async () => subject.removeAll());
235
+ after(() => subject.removeAll());
236
236
 
237
237
  it('saves the record', () => {
238
238
  expect(numberOfRecordsAfter).to.equal(numberOfRecordsBefore + 1);
@@ -263,7 +263,7 @@ describe('GitRepository', () => {
263
263
  ([commit] = await git.log());
264
264
  });
265
265
 
266
- after(async () => subject.removeAll());
266
+ after(() => subject.removeAll());
267
267
 
268
268
  it('stores snapshot ID', () => {
269
269
  expect(commit.body).to.include(config.get('recorder.versions.storage.git.snapshotIdentiferTemplate').replace(SNAPSHOT_ID_MARKER, SNAPSHOT_ID));
@@ -295,7 +295,7 @@ describe('GitRepository', () => {
295
295
  ([commit] = await git.log());
296
296
  });
297
297
 
298
- after(async () => subject.removeAll());
298
+ after(() => subject.removeAll());
299
299
 
300
300
  it('stores snapshots IDs', () => {
301
301
  expect(commit.body).to.include(config.get('recorder.versions.storage.git.snapshotIdentiferTemplate').replace(SNAPSHOT_ID_MARKER, SNAPSHOT_ID_1));
@@ -333,7 +333,7 @@ describe('GitRepository', () => {
333
333
  (record = await subject.findById(id));
334
334
  });
335
335
 
336
- after(async () => subject.removeAll());
336
+ after(() => subject.removeAll());
337
337
 
338
338
  it('returns a Version object', () => {
339
339
  expect(record).to.be.an.instanceof(Version);
@@ -355,7 +355,7 @@ describe('GitRepository', () => {
355
355
  expect(record.termsType).to.equal(TERMS_TYPE);
356
356
  });
357
357
 
358
- it('returns the content', async () => {
358
+ it('returns the content', () => {
359
359
  expect(record.content).to.equal(CONTENT);
360
360
  });
361
361
 
@@ -412,7 +412,7 @@ describe('GitRepository', () => {
412
412
  recordFound = await subject.findByDate(SERVICE_PROVIDER_ID, TERMS_TYPE, oneHourBeforeFetchDateLater);
413
413
  });
414
414
 
415
- after(async () => subject.removeAll());
415
+ after(() => subject.removeAll());
416
416
 
417
417
  it('returns a Version object', () => {
418
418
  expect(recordFound).to.be.an.instanceof(Version);
@@ -431,7 +431,7 @@ describe('GitRepository', () => {
431
431
  recordFound = await subject.findByDate(SERVICE_PROVIDER_ID, TERMS_TYPE);
432
432
  });
433
433
 
434
- it('returns null', async () => {
434
+ it('returns null', () => {
435
435
  expect(recordFound).to.equal(null);
436
436
  });
437
437
  });
@@ -478,7 +478,7 @@ describe('GitRepository', () => {
478
478
  (records = await subject.findAll());
479
479
  });
480
480
 
481
- after(async () => subject.removeAll());
481
+ after(() => subject.removeAll());
482
482
 
483
483
  it('returns all records', () => {
484
484
  expect(records.length).to.equal(3);
@@ -490,7 +490,7 @@ describe('GitRepository', () => {
490
490
  }
491
491
  });
492
492
 
493
- it('returns records in ascending order', async () => {
493
+ it('returns records in ascending order', () => {
494
494
  expect(records.map(record => record.fetchDate)).to.deep.equal([ FETCH_DATE_EARLIER, FETCH_DATE, FETCH_DATE_LATER ]);
495
495
  });
496
496
  });
@@ -527,9 +527,9 @@ describe('GitRepository', () => {
527
527
  (count = await subject.count());
528
528
  });
529
529
 
530
- after(async () => subject.removeAll());
530
+ after(() => subject.removeAll());
531
531
 
532
- it('returns the proper count', async () => {
532
+ it('returns the proper count', () => {
533
533
  expect(count).to.equal(3);
534
534
  });
535
535
  });
@@ -562,7 +562,7 @@ describe('GitRepository', () => {
562
562
  latestRecord = await subject.findLatest(SERVICE_PROVIDER_ID, TERMS_TYPE);
563
563
  });
564
564
 
565
- after(async () => subject.removeAll());
565
+ after(() => subject.removeAll());
566
566
 
567
567
  it('returns a Version object', () => {
568
568
  expect(latestRecord).to.be.an.instanceof(Version);
@@ -572,7 +572,7 @@ describe('GitRepository', () => {
572
572
  expect(latestRecord.id).to.include(lastSnapshotId);
573
573
  });
574
574
 
575
- it('returns the latest record content', async () => {
575
+ it('returns the latest record content', () => {
576
576
  expect(latestRecord.content.toString('utf8')).to.equal(UPDATED_FILE_CONTENT);
577
577
  });
578
578
  });
@@ -585,7 +585,7 @@ describe('GitRepository', () => {
585
585
  latestRecord = await subject.findLatest(SERVICE_PROVIDER_ID, TERMS_TYPE);
586
586
  });
587
587
 
588
- it('returns null', async () => {
588
+ it('returns null', () => {
589
589
  expect(latestRecord).to.equal(null);
590
590
  });
591
591
  });
@@ -637,15 +637,36 @@ describe('GitRepository', () => {
637
637
  }
638
638
  });
639
639
 
640
- after(async () => subject.removeAll());
640
+ after(() => subject.removeAll());
641
641
 
642
- it('iterates through all records', async () => {
642
+ it('iterates through all records', () => {
643
643
  expect(ids).to.have.members(expectedIds);
644
644
  });
645
645
 
646
- it('iterates in ascending order', async () => {
646
+ it('iterates in ascending order', () => {
647
647
  expect(fetchDates).to.deep.equal([ FETCH_DATE_EARLIER, FETCH_DATE, FETCH_DATE_LATER ]);
648
648
  });
649
+
650
+ context('when the repository contains non-record commits (e.g., README or LICENSE updates)', () => {
651
+ const iteratedIds = [];
652
+ let extraCommitId;
653
+
654
+ before(async () => {
655
+ await fs.writeFileSync(path.resolve(subject.path, 'README.md'), '# README');
656
+ await subject.git.add(path.resolve(subject.path, 'README.md'));
657
+ extraCommitId = await subject.git.commit({ message: 'Update README', filePath: path.resolve(subject.path, 'README.md') });
658
+
659
+ for await (const record of subject.iterate()) {
660
+ iteratedIds.push(record.id);
661
+ }
662
+ });
663
+
664
+ after(() => subject.removeAll());
665
+
666
+ it('iterates through records only', () => {
667
+ expect(iteratedIds).to.not.contains(extraCommitId);
668
+ });
669
+ });
649
670
  });
650
671
  });
651
672
 
@@ -695,7 +716,7 @@ describe('GitRepository', () => {
695
716
  ([commit] = await git.log());
696
717
  });
697
718
 
698
- after(async () => subject.removeAll());
719
+ after(() => subject.removeAll());
699
720
 
700
721
  it('saves the record', () => {
701
722
  expect(numberOfRecordsAfter).to.equal(numberOfRecordsBefore + 1);
@@ -765,7 +786,7 @@ describe('GitRepository', () => {
765
786
  ([commit] = await git.log());
766
787
  });
767
788
 
768
- after(async () => subject.removeAll());
789
+ after(() => subject.removeAll());
769
790
 
770
791
  it('saves the record', () => {
771
792
  expect(numberOfRecordsAfter).to.equal(numberOfRecordsBefore + 1);
@@ -803,7 +824,7 @@ describe('GitRepository', () => {
803
824
  numberOfRecordsAfter = (await git.log()).length;
804
825
  });
805
826
 
806
- after(async () => subject.removeAll());
827
+ after(() => subject.removeAll());
807
828
 
808
829
  it('does not save the record', () => {
809
830
  expect(numberOfRecordsAfter).to.equal(numberOfRecordsBefore);
@@ -831,7 +852,7 @@ describe('GitRepository', () => {
831
852
  ([commit] = await git.log());
832
853
  });
833
854
 
834
- after(async () => subject.removeAll());
855
+ after(() => subject.removeAll());
835
856
 
836
857
  it('saves the record', () => {
837
858
  expect(numberOfRecordsAfter).to.equal(numberOfRecordsBefore + 1);
@@ -863,7 +884,7 @@ describe('GitRepository', () => {
863
884
  ([commit] = await git.log());
864
885
  });
865
886
 
866
- after(async () => subject.removeAll());
887
+ after(() => subject.removeAll());
867
888
 
868
889
  it('saves the record', () => {
869
890
  expect(numberOfRecordsAfter).to.equal(numberOfRecordsBefore + 1);
@@ -899,7 +920,7 @@ describe('GitRepository', () => {
899
920
  (record = await subject.findById(id));
900
921
  });
901
922
 
902
- after(async () => subject.removeAll());
923
+ after(() => subject.removeAll());
903
924
 
904
925
  it('returns a Snapshot object', () => {
905
926
  expect(record).to.be.an.instanceof(Snapshot);
@@ -921,7 +942,7 @@ describe('GitRepository', () => {
921
942
  expect(record.termsType).to.equal(TERMS_TYPE);
922
943
  });
923
944
 
924
- it('returns the content', async () => {
945
+ it('returns the content', () => {
925
946
  expect(record.content).to.equal(CONTENT);
926
947
  });
927
948
 
@@ -986,7 +1007,7 @@ describe('GitRepository', () => {
986
1007
  (records = await subject.findAll());
987
1008
  });
988
1009
 
989
- after(async () => subject.removeAll());
1010
+ after(() => subject.removeAll());
990
1011
 
991
1012
  it('returns all records', () => {
992
1013
  expect(records.length).to.equal(3);
@@ -998,7 +1019,7 @@ describe('GitRepository', () => {
998
1019
  }
999
1020
  });
1000
1021
 
1001
- it('returns records in ascending order', async () => {
1022
+ it('returns records in ascending order', () => {
1002
1023
  expect(records.map(record => record.fetchDate)).to.deep.equal([ FETCH_DATE_EARLIER, FETCH_DATE, FETCH_DATE_LATER ]);
1003
1024
  });
1004
1025
  });
@@ -1035,9 +1056,9 @@ describe('GitRepository', () => {
1035
1056
  (count = await subject.count());
1036
1057
  });
1037
1058
 
1038
- after(async () => subject.removeAll());
1059
+ after(() => subject.removeAll());
1039
1060
 
1040
- it('returns the proper count', async () => {
1061
+ it('returns the proper count', () => {
1041
1062
  expect(count).to.equal(3);
1042
1063
  });
1043
1064
  });
@@ -1070,7 +1091,7 @@ describe('GitRepository', () => {
1070
1091
  latestRecord = await subject.findLatest(SERVICE_PROVIDER_ID, TERMS_TYPE);
1071
1092
  });
1072
1093
 
1073
- after(async () => subject.removeAll());
1094
+ after(() => subject.removeAll());
1074
1095
 
1075
1096
  it('returns a Snapshot object', () => {
1076
1097
  expect(latestRecord).to.be.an.instanceof(Snapshot);
@@ -1080,7 +1101,7 @@ describe('GitRepository', () => {
1080
1101
  expect(latestRecord.id).to.include(lastSnapshotId);
1081
1102
  });
1082
1103
 
1083
- it('returns the latest record content', async () => {
1104
+ it('returns the latest record content', () => {
1084
1105
  expect(latestRecord.content.toString('utf8')).to.equal(UPDATED_FILE_CONTENT);
1085
1106
  });
1086
1107
 
@@ -1102,13 +1123,13 @@ describe('GitRepository', () => {
1102
1123
  latestRecord = await subject.findLatest(SERVICE_PROVIDER_ID, TERMS_TYPE);
1103
1124
  });
1104
1125
 
1105
- after(async () => subject.removeAll());
1126
+ after(() => subject.removeAll());
1106
1127
 
1107
1128
  it('returns the latest record id', () => {
1108
1129
  expect(latestRecord.id).to.include(lastSnapshotId);
1109
1130
  });
1110
1131
 
1111
- it('returns the latest record content', async () => {
1132
+ it('returns the latest record content', () => {
1112
1133
  expect(latestRecord.content.toString('utf8')).to.equal(PDF_CONTENT);
1113
1134
  });
1114
1135
 
@@ -1125,7 +1146,7 @@ describe('GitRepository', () => {
1125
1146
  latestRecord = await subject.findLatest(SERVICE_PROVIDER_ID, TERMS_TYPE);
1126
1147
  });
1127
1148
 
1128
- it('returns null', async () => {
1149
+ it('returns null', () => {
1129
1150
  expect(latestRecord).to.equal(null);
1130
1151
  });
1131
1152
  });
@@ -1174,13 +1195,13 @@ describe('GitRepository', () => {
1174
1195
  }
1175
1196
  });
1176
1197
 
1177
- after(async () => subject.removeAll());
1198
+ after(() => subject.removeAll());
1178
1199
 
1179
- it('iterates through all records', async () => {
1200
+ it('iterates through all records', () => {
1180
1201
  expect(ids).to.have.members(expectedIds);
1181
1202
  });
1182
1203
 
1183
- it('iterates in ascending order', async () => {
1204
+ it('iterates in ascending order', () => {
1184
1205
  expect(fetchDates).to.deep.equal([ FETCH_DATE_EARLIER, FETCH_DATE, FETCH_DATE_LATER ]);
1185
1206
  });
1186
1207
  });
@@ -1266,7 +1287,7 @@ describe('GitRepository', () => {
1266
1287
  /* eslint-enable no-await-in-loop */
1267
1288
  });
1268
1289
 
1269
- after(async () => subject.removeAll());
1290
+ after(() => subject.removeAll());
1270
1291
 
1271
1292
  describe('Records attributes', () => {
1272
1293
  describe('#isExtractOnly', () => {
@@ -1333,7 +1354,7 @@ describe('GitRepository', () => {
1333
1354
  }
1334
1355
  });
1335
1356
 
1336
- it('returns records in ascending order', async () => {
1357
+ it('returns records in ascending order', () => {
1337
1358
  expect(records.map(record => record.fetchDate)).to.deep.equal(expectedDates);
1338
1359
  });
1339
1360
  });
@@ -1345,7 +1366,7 @@ describe('GitRepository', () => {
1345
1366
  (count = await subject.count());
1346
1367
  });
1347
1368
 
1348
- it('returns the proper count', async () => {
1369
+ it('returns the proper count', () => {
1349
1370
  expect(count).to.equal(expectedIds.length);
1350
1371
  });
1351
1372
  });
@@ -1361,11 +1382,11 @@ describe('GitRepository', () => {
1361
1382
  }
1362
1383
  });
1363
1384
 
1364
- it('iterates through all records', async () => {
1385
+ it('iterates through all records', () => {
1365
1386
  expect(ids).to.have.members(expectedIds);
1366
1387
  });
1367
1388
 
1368
- it('iterates in ascending order', async () => {
1389
+ it('iterates in ascending order', () => {
1369
1390
  expect(fetchDates).to.deep.equal(expectedDates);
1370
1391
  });
1371
1392
  });
@@ -3,6 +3,8 @@
3
3
  * @see {@link https://martinfowler.com/eaaCatalog/repository.html|Repository}
4
4
  * @interface
5
5
  */
6
+
7
+ /* eslint-disable require-await */
6
8
  class RepositoryInterface {
7
9
  /**
8
10
  * [Optional] Initialize repository
@@ -122,3 +124,4 @@ class RepositoryInterface {
122
124
  }
123
125
 
124
126
  export default RepositoryInterface;
127
+ /* eslint-enable require-await */
@@ -29,7 +29,7 @@ export default class MongoRepository extends RepositoryInterface {
29
29
  return this;
30
30
  }
31
31
 
32
- async finalize() {
32
+ finalize() {
33
33
  return this.client.close();
34
34
  }
35
35
 
@@ -77,7 +77,7 @@ export default class MongoRepository extends RepositoryInterface {
77
77
  .map(mongoDocument => this.#toDomain(mongoDocument, { deferContentLoading: true })));
78
78
  }
79
79
 
80
- async count() {
80
+ count() {
81
81
  return this.collection.find().count();
82
82
  }
83
83
 
@@ -93,7 +93,7 @@ export default class MongoRepository extends RepositoryInterface {
93
93
  /* eslint-enable no-await-in-loop */
94
94
  }
95
95
 
96
- async removeAll() {
96
+ removeAll() {
97
97
  return this.collection.deleteMany();
98
98
  }
99
99