import { RelationMatrix , TagRelation } from '@icarus/shared' ; import { TagRelationStore } from '@icarus/storage' ; import NullPersistence from './NullPersistence' ; export default class TestTagRelationStore extends TagRelationStore { saved : TagRelation [ ] = [ ] ; constructor ( ) { super ( new NullPersistence ( ) ) ; } async attachTagToBook ( bookName , tagName ) { this . saved . push ( { bookName , tagName } ) ; } async detachTagFromBook ( bookName , tagName ) { const index = this . saved . findIndex ( v => v . bookName === bookName && v . tagName === tagName ) ; this . saved . splice ( index , 1 ) ; } async listAllTags ( ) { return [ 'tag1' , 'tag2' , 'tag3' ] ; } async listTagsByBook ( bookName ) { return this . saved . filter ( v => v . bookName === bookName ) . map ( v => v . tagName ) ; } async listBooksByTags ( tagNames ) { const bookNames = this . saved . filter ( v => tagNames . includes ( v . tagName ) ) . map ( v => v . bookName ) ; return [ ... new Set ( bookNames ) ] ; } async buildMatrix ( ) { return { tagNames : [ 'tag1' , 'tag2' , 'tag3' ] , bookNames : [ 'book1' , 'book2' , 'book3' ] , matrix : [ [ 1 , 1 , 1 ] , [ 1 , 0 , 1 ] , [ 1 , 0 , 1 ] , [ 0 , 0 , 0 ] , ] , } ; } }