Skip to content

Commit 07562eb

Browse files
Merge branch 'master' into clear_image_list_cache
2 parents 33160c3 + 461b54c commit 07562eb

File tree

146 files changed

+12336
-1244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+12336
-1244
lines changed

core/src/base-config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ export const basicIndexConfiguration = {
2222
'id:match': { path: 'resource.id', pathArray: ['resource', 'id'], type: 'match' },
2323
'isRecordedIn:contain': { path: 'resource.relations.isRecordedIn', pathArray: ['resource', 'relations', 'isRecordedIn'], type: 'contain' },
2424
'isChildOf:contain': { path: 'resource.relations.isChildOf', pathArray: ['resource', 'relations', 'isChildOf'], type: 'contain', recursivelySearchable: true },
25-
'isChildOf:exist': { path: 'resource.relations.isChildOf', pathArray: ['resource', 'relations', 'isChildOf'], type: 'exist' }
25+
'isChildOf:exist': { path: 'resource.relations.isChildOf', pathArray: ['resource', 'relations', 'isChildOf'], type: 'exist' },
26+
'missingRelationTargetIds:contain': { path: 'warnings.missingRelationTargets.targetIds', pathArray: ['warnings', 'missingRelationTargets', 'targetIds'], type: 'contain' }
2627
};

core/src/datastore/changes/changes-stream.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import { IndexFacade } from '../../index/index-facade';
33
import { Action } from '../../model/action';
44
import { Document } from '../../model/document';
55
import { ObserverUtil } from '../../tools/observer-util';
6-
import { CategoryConverter } from '../category-converter';
6+
import { DocumentConverter } from '../document-converter';
77
import { DocumentCache } from '../document-cache';
88
import { isProjectDocument } from '../helpers';
99
import { PouchdbDatastore } from '../pouchdb/pouchdb-datastore';
10+
import { WarningsUpdater } from '../warnings-updater';
11+
import { Datastore } from '../datastore';
12+
import { ProjectConfiguration } from '../../services/project-configuration';
13+
import { CategoryForm } from '../../model/configuration/category-form';
1014

1115

1216
/**
@@ -20,25 +24,27 @@ export class ChangesStream {
2024
private projectDocumentObservers: Array<Observer<Document>> = [];
2125

2226

23-
constructor(datastore: PouchdbDatastore,
27+
constructor(pouchDbDatastore: PouchdbDatastore,
28+
private datastore: Datastore,
2429
private indexFacade: IndexFacade,
2530
private documentCache: DocumentCache,
26-
private categoryConverter: CategoryConverter,
31+
private documentConverter: DocumentConverter,
32+
private projectConfiguration: ProjectConfiguration,
2733
private getUsername: () => string) {
2834

29-
datastore.deletedNotifications().subscribe(document => {
35+
pouchDbDatastore.deletedNotifications().subscribe(document => {
3036

3137
this.documentCache.remove(document.resource.id);
3238
this.indexFacade.remove(document);
3339
});
3440

35-
datastore.changesNotifications().subscribe(async document => {
41+
pouchDbDatastore.changesNotifications().subscribe(async document => {
3642

3743
if (isProjectDocument(document)) {
38-
ObserverUtil.notify(this.projectDocumentObservers, this.categoryConverter.convert(document));
44+
ObserverUtil.notify(this.projectDocumentObservers, this.documentConverter.convert(document));
3945
}
4046

41-
const isRemoteChange: boolean = await ChangesStream.isRemoteChange(document,this.getUsername());
47+
const isRemoteChange: boolean = await ChangesStream.isRemoteChange(document, this.getUsername());
4248

4349
if (isRemoteChange || !this.documentCache.get(document.resource.id)
4450
|| document._conflicts !== undefined) {
@@ -64,14 +70,22 @@ export class ChangesStream {
6470

6571
private async welcomeDocument(document: Document) {
6672

67-
const convertedDocument = this.categoryConverter.convert(document);
73+
const convertedDocument: Document = this.documentConverter.convert(document);
6874
this.indexFacade.put(convertedDocument);
6975

70-
// explicitly assign by value in order for changes to be detected by angular
71-
if (this.documentCache.get(convertedDocument.resource.id)) {
76+
const previousVersion: Document|undefined = this.documentCache.get(convertedDocument.resource.id);
77+
const previousIdentifier: string|undefined = previousVersion?.resource.identifier;
78+
if (previousVersion) {
79+
// Explicitly assign by value in order for changes to be detected by Angular
7280
this.documentCache.reassign(convertedDocument);
7381
}
7482

83+
const category: CategoryForm = this.projectConfiguration.getCategory(convertedDocument.resource.category);
84+
85+
await WarningsUpdater.updateIndexDependentWarnings(
86+
document, this.indexFacade, this.documentCache, category, this.datastore, previousIdentifier, true
87+
);
88+
7589
ObserverUtil.notify(this.remoteChangesObservers, convertedDocument);
7690
}
7791

core/src/datastore/datastore.ts

+47-16
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import { Document } from '../model/document';
33
import { NewDocument } from '../model/document';
44
import { Query } from '../model/query';
55
import { Name } from '../tools/named';
6-
import { CategoryConverter } from './category-converter';
6+
import { DocumentConverter } from './document-converter';
77
import { DatastoreErrors } from './datastore-errors';
88
import { DocumentCache } from './document-cache';
99
import { PouchdbDatastore } from './pouchdb/pouchdb-datastore';
10+
import { WarningsUpdater } from './warnings-updater';
11+
import { ProjectConfiguration } from '../services/project-configuration';
12+
import { CategoryForm } from '../model/configuration/category-form';
1013

1114

1215
/**
@@ -38,7 +41,8 @@ export class Datastore {
3841
constructor(private datastore: PouchdbDatastore,
3942
private indexFacade: IndexFacade,
4043
private documentCache: DocumentCache,
41-
private categoryConverter: CategoryConverter,
44+
private documentConverter: DocumentConverter,
45+
private projectConfiguration: ProjectConfiguration,
4246
private getUser: () => Name) {
4347
}
4448

@@ -68,9 +72,12 @@ export class Datastore {
6872

6973
public async bulkCreate(documents: Array<NewDocument>): Promise<Array<Document>> {
7074

71-
return (await this.datastore.bulkCreate(documents, this.getUser())).map(document => {
72-
return this.updateIndex(document);
73-
});
75+
const resultDocuments: Array<Document> = [];
76+
for (let document of await this.datastore.bulkCreate(documents, this.getUser())) {
77+
resultDocuments.push(await this.updateIndex(document));
78+
}
79+
80+
return resultDocuments;
7481
}
7582

7683

@@ -90,26 +97,45 @@ export class Datastore {
9097
*/
9198
public update: Datastore.Update = async (document: Document, squashRevisionsIds?: string[]): Promise<Document> => {
9299

100+
delete document.warnings;
101+
93102
return this.updateIndex(await this.datastore.update(document, this.getUser(), squashRevisionsIds));
94103
}
95104

96105

97106
public async bulkUpdate(documents: Array<Document>): Promise<Array<Document>> {
98107

99-
return (await this.datastore.bulkUpdate(documents, this.getUser())).map(document => {
100-
return this.updateIndex(document);
101-
});
108+
documents.forEach(document => delete document.warnings);
109+
110+
const resultDocuments: Array<Document> = [];
111+
for (let document of await this.datastore.bulkUpdate(documents, this.getUser())) {
112+
resultDocuments.push(await this.updateIndex(document));
113+
}
114+
115+
return resultDocuments;
102116
}
103117

104118

105-
private updateIndex(document: Document) {
119+
private async updateIndex(document: Document): Promise<Document> {
106120

107-
const convertedDocument = this.categoryConverter.convert(document);
121+
const convertedDocument = this.documentConverter.convert(document);
108122
this.indexFacade.put(convertedDocument);
109123

110-
return !this.documentCache.get(document.resource.id as any)
124+
const previousVersion: Document|undefined = this.documentCache.get(convertedDocument.resource.id);
125+
const previousIdentifier: string|undefined = previousVersion?.resource.identifier;
126+
127+
document = !previousVersion
111128
? this.documentCache.set(convertedDocument)
112129
: this.documentCache.reassign(convertedDocument);
130+
const category: CategoryForm = this.projectConfiguration.getCategory(document.resource.category);
131+
132+
await WarningsUpdater.updateNonUniqueIdentifierWarning(
133+
document, this.indexFacade, this, previousIdentifier, true
134+
);
135+
await WarningsUpdater.updateResourceLimitWarning(document, category, this.indexFacade, this, true);
136+
await WarningsUpdater.updateRelationTargetWarning(document, this.indexFacade, this.documentCache, this, true);
137+
138+
return document;
113139
}
114140

115141

@@ -134,6 +160,12 @@ export class Datastore {
134160

135161
await this.datastore.remove(document);
136162
this.documentCache.remove(document.resource.id);
163+
164+
await WarningsUpdater.updateResourceLimitWarnings(
165+
this,
166+
this.indexFacade,
167+
this.projectConfiguration.getCategory(document.resource.category)
168+
);
137169
}
138170

139171

@@ -157,7 +189,7 @@ export class Datastore {
157189
return cachedDocument;
158190
}
159191

160-
let document = this.categoryConverter.convert(await this.datastore.fetch(id, options?.conflicts));
192+
let document = this.documentConverter.convert(await this.datastore.fetch(id, options?.conflicts));
161193

162194
return cachedDocument
163195
? this.documentCache.reassign(document)
@@ -200,7 +232,7 @@ export class Datastore {
200232

201233
public convert: Datastore.Convert = (document: Document) => {
202234

203-
this.categoryConverter.convert(document);
235+
this.documentConverter.convert(document);
204236
}
205237

206238

@@ -229,7 +261,7 @@ export class Datastore {
229261
*/
230262
public async getRevision(docId: string, revisionId: string): Promise<Document> {
231263

232-
return this.categoryConverter.convert(
264+
return this.documentConverter.convert(
233265
await this.datastore.fetchRevision(docId, revisionId));
234266
}
235267

@@ -312,11 +344,10 @@ export class Datastore {
312344
private async getDocumentsFromDatastore(ids: string[]): Promise<Array<Document>> {
313345

314346
const documents: Array<Document> = [];
315-
316347
(await this.datastore.bulkFetch(ids)).forEach(document => {
317348

318349
try {
319-
const convertedDocument = this.categoryConverter.convert(document);
350+
const convertedDocument = this.documentConverter.convert(document);
320351
documents.push(this.documentCache.set(convertedDocument));
321352
} catch (errWithParams) {
322353
if (errWithParams[0] === DatastoreErrors.UNKNOWN_CATEGORY) {

core/src/datastore/document-cache.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export class DocumentCache {
3535

3636
public reassign(document: Document) {
3737

38-
if (!document._conflicts) {
39-
delete (this.get(document.resource.id) as any)._conflicts;
40-
}
38+
if (!document._conflicts) delete (this.get(document.resource.id))._conflicts;
39+
if (!document.warnings) delete (this.get(document.resource.id)).warnings;
40+
4141
Object.assign(this.get(document.resource.id), document);
4242

4343
return document;

core/src/datastore/category-converter.ts core/src/datastore/document-converter.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { to } from 'tsfun';
21
import { Relation } from '../model/configuration/relation';
32
import { Document } from '../model/document';
43
import { Resource } from '../model/resource';
@@ -8,9 +7,11 @@ import { InPlace } from '../tools/in-place';
87
import { Named } from '../tools/named';
98
import { DatastoreErrors } from './datastore-errors';
109
import { Migrator } from './migrator';
10+
import { CategoryForm } from '../model/configuration/category-form';
11+
import { WarningsUpdater } from './warnings-updater';
1112

1213

13-
export class CategoryConverter {
14+
export class DocumentConverter {
1415

1516
constructor(private projectConfiguration: ProjectConfiguration) { }
1617

@@ -19,10 +20,10 @@ export class CategoryConverter {
1920

2021
const convertedDocument = Migrator.migrate(document);
2122

22-
if (document.resource.category !== 'Configuration'
23-
&& !Tree.flatten(this.projectConfiguration.getCategories()).map(to(Named.NAME))
24-
.includes(document.resource.category)) {
25-
throw [DatastoreErrors.UNKNOWN_CATEGORY, document.resource.category];
23+
if (document.resource.category !== 'Configuration') {
24+
const category: CategoryForm = this.projectConfiguration.getCategory(document.resource.category);
25+
if (!category) throw [DatastoreErrors.UNKNOWN_CATEGORY, document.resource.category];
26+
WarningsUpdater.updateIndexIndependentWarnings(document, category);
2627
}
2728

2829
InPlace.takeOrMake(convertedDocument, [Document.RESOURCE, Resource.IDENTIFIER], '');

core/src/datastore/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './category-converter';
1+
export * from './document-converter';
22
export * from './changes';
33
export * from './datastore';
44
export { Datastore } from './datastore';

0 commit comments

Comments
 (0)