Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define an API to query records history #875

Merged
merged 74 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
6b321b6
Make committer date always equal to author date
Ndpnt May 16, 2022
bafc612
Define commit message prefixes as constants
Ndpnt May 4, 2022
85d26ce
Improve GitAdapter records iteration
Ndpnt May 4, 2022
4dd31d7
Allow passing a promise for `content` to `record` function
Ndpnt May 4, 2022
2a3e422
Handle asynchronous record content loading in recorder
Ndpnt May 4, 2022
a2f1f85
Update git adapter tests
Ndpnt May 18, 2022
342ae17
Remove magic strings
Ndpnt May 11, 2022
5e3fcf4
Add iterate function to MongoAdapter
Ndpnt May 10, 2022
7bb2fac
Improve record function to MongoAdapter
Ndpnt May 10, 2022
20ef5e0
Fix deprecation warning
Ndpnt May 11, 2022
cb8e026
Improve MongoAdapter tests
Ndpnt May 10, 2022
2426753
Fix Recorder tests as content is now lazy loaded
Ndpnt May 10, 2022
d10df95
Fix Export tests as content is now lazy loaded
Ndpnt May 10, 2022
1cdf524
Add getRecord function to GitAdapter
Ndpnt May 18, 2022
ff9373e
Add getRecords function to GitAdapter
Ndpnt May 10, 2022
f41f0d5
Add getRecord function to MongoAdapter
Ndpnt May 10, 2022
d08771a
Add getRecords function to MongoAdapter
Ndpnt May 10, 2022
78f9929
Add count function to MongoAdapter
Ndpnt May 10, 2022
9b784aa
Add count function to GitAdapter
Ndpnt May 10, 2022
a1ce9a0
Add history scripts logger module
Ndpnt May 11, 2022
15b0252
Improve naming
Ndpnt May 11, 2022
8098400
Better manage access to non-existent records
Ndpnt May 11, 2022
fcea33e
Simplify code
Ndpnt May 11, 2022
8ee7ff5
Add history utils to import README
Ndpnt May 25, 2022
2833919
Add script to update snapshots Ids references to full git hash
Ndpnt May 25, 2022
01f3b76
Add script to migrate services
Ndpnt May 25, 2022
7f0b9be
Significantly improvement of perf when getting commits
Ndpnt May 25, 2022
55a0025
Name parameters for commits functions
Ndpnt May 31, 2022
30ace5a
Remove obsolete code
Ndpnt May 31, 2022
8d6d91e
Simplify code
Ndpnt May 31, 2022
b163bdc
Minor code style improvement
Ndpnt May 31, 2022
785ed0f
Refactor storage adapters
Ndpnt Jun 6, 2022
6d225e8
Rename `adapter` to `repository`
Ndpnt Jun 7, 2022
270ede0
Update scripts
Ndpnt Jun 7, 2022
4a0a4ca
Improve naming
Ndpnt Jun 7, 2022
b47a084
Minor doc update
Ndpnt Jun 7, 2022
299e6c5
Ensure markdown extension is .md
Ndpnt Jun 7, 2022
a14715a
Create interface for repositories
Ndpnt Jun 7, 2022
7bac4cc
Validate required params when instantiating Record
Ndpnt Jun 7, 2022
7b56f29
Improve separation
Ndpnt Jun 8, 2022
db8eb0d
Improve repository API
Ndpnt Jun 8, 2022
e288af2
Make getCommit returns only one commit
Ndpnt Jun 8, 2022
d2f6c67
Improve function name
Ndpnt Jun 8, 2022
5d823da
Improve returning null object
Ndpnt Jun 8, 2022
e1ac331
Update scripts
Ndpnt Jun 8, 2022
f728c66
Move repositories in recorder module
Ndpnt Jun 8, 2022
8db2db2
Switch to a repository factory
Ndpnt Jun 13, 2022
2be75cc
Improve recorder file structure
Ndpnt Jun 13, 2022
b26e88f
Throw an error when trying to access not loaded Record content
Ndpnt Jun 13, 2022
43720a7
Add validation tests to Record
Ndpnt Jun 13, 2022
f0beb5f
Improve Record test readability
Ndpnt Jun 13, 2022
b182407
Add missing space
Ndpnt Jun 13, 2022
9fc509c
Improve English
Ndpnt Jun 13, 2022
c1d4fcf
Remove useless parens
Ndpnt Jun 13, 2022
1159c26
Follow subject convention in tests
Ndpnt Jun 13, 2022
3e148da
Switch to static property and method
Ndpnt Jun 13, 2022
3bf9f21
Improve variable name
Ndpnt Jun 13, 2022
33c1813
Move variable declaration for clarity
Ndpnt Jun 13, 2022
12aeaf2
Fix method name in script
Ndpnt Jun 15, 2022
4f1c887
Rename variables for clarity
Ndpnt Jun 15, 2022
1acc32e
Convert obsolete Classes to simple module
Ndpnt Jun 15, 2022
3bd7d52
Improve phrasings
Ndpnt Jun 15, 2022
7172c91
Remove obsolete parens
Ndpnt Jun 15, 2022
2ee7c2a
Ensure optional methods behavior in RepositoryInterface
Ndpnt Jun 15, 2022
c19c6cc
Remove obsolete code
Ndpnt Jun 15, 2022
bd6a444
Assign all given params to a new Record
Ndpnt Jun 15, 2022
a665294
Do not filter Record fields before saving it in Mongo
Ndpnt Jun 15, 2022
f70e547
Switch method and property to public
Ndpnt Jun 15, 2022
f7a6880
Remove obsolete file
Ndpnt Jun 15, 2022
4a1f2da
Remove redundant operations
Ndpnt Jun 15, 2022
f9c992e
Pass only required config
Ndpnt Jun 15, 2022
f95cf88
Fix main in package.json
Ndpnt Jun 15, 2022
3e9593f
Improve variable name to avoid confusion
Ndpnt Jun 15, 2022
69db45d
Improve naming
Ndpnt Jun 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends:
- airbnb-base
parserOptions:
ecmaVersion: 2020
ecmaVersion: 2022
env:
node: true
mocha: true
Expand Down Expand Up @@ -106,3 +106,10 @@ overrides:
rules:
func-names: 0
import/no-extraneous-dependencies: 0
- files:
- src/**/*[iI]nterface.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need both I and i ?

I see only one interface.js file in lower case

Copy link
Member Author

@Ndpnt Ndpnt Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the beginning my file was named repositoryInterface.js and I renamed it after.
The rules I defined will be true for all interfaces so I support all naming.

rules:
no-unused-vars: 0
require-yield: 0
class-methods-use-this: 0
no-empty-function: 0
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
- [Core](#core)
- [Configuring](#configuring)
- [Configuration file](#configuration-file)
- [Storage adapters](#storage-adapters)
- [Storage repositories](#storage-repositories)
- [Environment variables](#environment-variables)
- [Running](#running)
- [Deploying](#deploying)
- [Publishing](#publishing)
- [Publishing](#publishing)
- [Contributing](#contributing)
- [Adding or updating a service](#adding-a-new-service-or-updating-an-existing-service)
- [Core engine](#core-engine)
Expand Down Expand Up @@ -144,7 +144,7 @@ When refering to the base folder, it means the folder where you will be `git pul
5. If you are using a special repo instance (e.g., `dating-declarations`), create a new [config file](#configuring), `config/development.json`, and add:
```json
{

"services": {
"declarationsPath": "../<name of the repo>/declarations"
}
Expand Down Expand Up @@ -185,12 +185,12 @@ The default configuration can be found in `config/default.json`. The full refere
"recorder": {
"versions": {
"storage": {
"<storage-adapter>": "Storage adapter configuration object; see below"
"<storage-repository>": "Storage repository configuration object; see below"
}
},
"snapshots": {
"storage": {
"<storage-adapter>": "Storage adapter configuration object; see below"
"<storage-repository>": "Storage repository configuration object; see below"
}
}
},
Expand Down Expand Up @@ -235,9 +235,9 @@ The default configuration is merged with (and overridden by) environment-specifi

If you want to change your local configuration, we suggest you create a `config/development.json` file with overridden values. An example of a production configuration file can be found in `config/production.json`.

##### Storage adapters
##### Storage repositories

Two storage adapters are currently supported: Git and MongoDB. Each one can be used independently for versions and snapshots.
Two storage repositories are currently supported: Git and MongoDB. Each one can be used independently for versions and snapshots.

###### Git

Expand Down
2 changes: 1 addition & 1 deletion ops/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ In order to automatically set up a virtual machine:
2. Install [VirtualBox](https://www.virtualbox.org/wiki/Downloads) to manage virtual machines. If you prefer Docker, or have an Apple Silicon machine, install [Docker](https://docs.docker.com/get-docker/) instead.
3. Create a dedicated SSH key with no password: `ssh-keygen -f ~/.ssh/ota-vagrant -q -N ""`. This key will be automatically used by Vagrant.

> VirtualBox is not compatible with Apple Silicon (M1…) processors. If you have such a machine, you will need to use the Docker provider. Since MongoDB cannot be installed on ARM, it is skipped in the infrastructure installation process. This means you cannot test the MongoDB storage adapter with Vagrant with an Apple Silicon processor.
> VirtualBox is not compatible with Apple Silicon (M1…) processors. If you have such a machine, you will need to use the Docker provider. Since MongoDB cannot be installed on ARM, it is skipped in the infrastructure installation process. This means you cannot test the MongoDB storage repository with Vagrant with an Apple Silicon processor.

### Launch

Expand Down
98 changes: 51 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"license": "EUPL-1.2",
"author": "ambanum",
"type": "module",
"main": "index.js",
"main": "src/main.js",
"bin": {
"ota-lint-declarations": "./bin/lint-declarations.js",
"ota-validate-declarations": "./bin/validate-declarations.js"
Expand All @@ -37,6 +37,7 @@
"dependencies": {
"@accordproject/markdown-cicero": "^0.15.2",
"@accordproject/markdown-pdf": "^0.15.2",
"@opentermsarchive/simple-git": "^3.7.2",
"abort-controller": "^3.0.0",
"ajv": "^6.12.6",
"archiver": "^5.3.0",
Expand Down Expand Up @@ -72,7 +73,6 @@
"puppeteer-extra": "^3.2.3",
"puppeteer-extra-plugin-stealth": "^2.9.0",
"sib-api-v3-sdk": "^8.2.1",
"simple-git": "^2.47.0",
"turndown": "^7.0.0",
"winston": "^3.3.3",
"winston-mail": "^2.0.0"
Expand Down
9 changes: 5 additions & 4 deletions scripts/dataset/export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import path from 'path';
import { fileURLToPath } from 'url';

import archiver from 'archiver';
import config from 'config';

import { instantiateVersionsStorageAdapter } from '../../../src/index.js';
import RepositoryFactory from '../../../src/archivist/recorder/repositories/factory.js';
import * as renamer from '../../utils/renamer/index.js';
import readme from '../assets/README.template.js';
import logger from '../logger/index.js';
Expand All @@ -16,7 +17,7 @@ const fs = fsApi.promises;
const ARCHIVE_FORMAT = 'zip'; // for supported formats, see https://www.archiverjs.com/docs/archive-formats

export default async function generate({ archivePath, releaseDate }) {
const versionsStorageAdapter = await (instantiateVersionsStorageAdapter()).initialize();
const versionsRepository = await RepositoryFactory.create(config.get('recorder.versions.storage')).initialize();

const archive = await initializeArchive(archivePath);

Expand All @@ -28,7 +29,7 @@ export default async function generate({ archivePath, releaseDate }) {

let index = 1;

for await (const version of versionsStorageAdapter.iterate()) {
for await (const version of versionsRepository.iterate()) {
const { content, fetchDate } = version;
const { serviceId, documentType } = renamer.applyRules(version.serviceId, version.documentType);

Expand Down Expand Up @@ -70,7 +71,7 @@ export default async function generate({ archivePath, releaseDate }) {
archive.stream.finalize();

await archive.done;
await versionsStorageAdapter.finalize();
await versionsRepository.finalize();

return {
servicesCount: services.size,
Expand Down
33 changes: 20 additions & 13 deletions scripts/dataset/export/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import dircompare from 'dir-compare';
import mime from 'mime';
import StreamZip from 'node-stream-zip';

import GitAdapter from '../../../src/storage-adapters/git/index.js';
import Record from '../../../src/archivist/recorder/record.js';
import GitRepository from '../../../src/archivist/recorder/repositories/git/index.js';

import generateArchive from './index.js';

Expand All @@ -30,6 +31,8 @@ const FOURTH_FETCH_DATE = '2022-01-01T12:12:24.000Z';
const FIRST_CONTENT = 'First Content';
const SECOND_CONTENT = 'Second Content';

const MIME_TYPE = 'text/markdown';

const SNAPSHOT_ID = '721ce4a63ad399ecbdb548a66d6d327e7bc97876';

const RELEASE_DATE = '2022-01-01T18:21:00.000Z';
Expand All @@ -41,49 +44,53 @@ describe('Export', () => {
const TMP_PATH = path.resolve(__dirname, './tmp');
const EXPECTED_DATASET_PATH = path.resolve(__dirname, './test/fixtures/dataset');

let storageAdapter;
let repository;
let zip;

before(async function () {
this.timeout(10000);
storageAdapter = new GitAdapter({
repository = new GitRepository({
...config.get('recorder.versions.storage.git'),
path: path.resolve(__dirname, '../../../', config.get('recorder.versions.storage.git.path')),
});

await storageAdapter.initialize();
await repository.initialize();

await storageAdapter.record({
await repository.save(new Record({
serviceId: FIRST_SERVICE_PROVIDER_ID,
documentType: FIRST_DOCUMENT_TYPE,
content: FIRST_CONTENT,
mimeType: MIME_TYPE,
fetchDate: FIRST_FETCH_DATE,
snapshotId: SNAPSHOT_ID,
});
}));

await storageAdapter.record({
await repository.save(new Record({
serviceId: FIRST_SERVICE_PROVIDER_ID,
documentType: FIRST_DOCUMENT_TYPE,
content: SECOND_CONTENT,
mimeType: MIME_TYPE,
fetchDate: SECOND_FETCH_DATE,
snapshotId: SNAPSHOT_ID,
});
}));

await storageAdapter.record({
await repository.save(new Record({
serviceId: SECOND_SERVICE_PROVIDER_ID,
documentType: FIRST_DOCUMENT_TYPE,
content: FIRST_CONTENT,
mimeType: MIME_TYPE,
fetchDate: THIRD_FETCH_DATE,
snapshotId: SNAPSHOT_ID,
});
}));

await storageAdapter.record({
await repository.save(new Record({
serviceId: SECOND_SERVICE_PROVIDER_ID,
documentType: SECOND_DOCUMENT_TYPE,
content: FIRST_CONTENT,
mimeType: MIME_TYPE,
fetchDate: FOURTH_FETCH_DATE,
snapshotId: SNAPSHOT_ID,
});
}));

await generateArchive({
archivePath: ARCHIVE_PATH,
Expand All @@ -97,7 +104,7 @@ describe('Export', () => {

after(async () => {
await fs.rm(TMP_PATH, { recursive: true });
await storageAdapter._removeAllRecords();
await repository.removeAll();
});

it('is an archive', () => {
Expand Down
Loading