internal: incomplete vault systems behind feature flag (#2340)
This commit is contained in:
@@ -1,31 +1,37 @@
|
||||
import { ItemManager } from '@Lib/Services'
|
||||
import { TagsToFoldersMigrationApplicator } from './TagsToFolders'
|
||||
import { MutatorClientInterface } from '@standardnotes/services'
|
||||
|
||||
describe('folders component to hierarchy', () => {
|
||||
let itemManager: ItemManager
|
||||
let mutator: MutatorClientInterface
|
||||
let changeItemMock: jest.Mock
|
||||
let findOrCreateTagParentChainMock: jest.Mock
|
||||
|
||||
const itemManagerMock = (tagTitles: string[]) => {
|
||||
const mockTag = (title: string) => ({
|
||||
title,
|
||||
uuid: title,
|
||||
parentId: undefined,
|
||||
})
|
||||
beforeEach(() => {
|
||||
itemManager = {} as unknown as jest.Mocked<ItemManager>
|
||||
|
||||
const mock = {
|
||||
getItems: jest.fn().mockReturnValue(tagTitles.map(mockTag)),
|
||||
findOrCreateTagParentChain: jest.fn(),
|
||||
changeItem: jest.fn(),
|
||||
}
|
||||
mutator = {} as unknown as jest.Mocked<MutatorClientInterface>
|
||||
|
||||
return mock
|
||||
}
|
||||
changeItemMock = mutator.changeItem = jest.fn()
|
||||
findOrCreateTagParentChainMock = mutator.findOrCreateTagParentChain = jest.fn()
|
||||
})
|
||||
|
||||
describe('folders component to hierarchy', () => {
|
||||
it('should produce a valid hierarchy in the simple case', async () => {
|
||||
const titles = ['a', 'a.b', 'a.b.c']
|
||||
itemManager.getItems
|
||||
|
||||
const itemManager = itemManagerMock(titles)
|
||||
await TagsToFoldersMigrationApplicator.run(itemManager as unknown as ItemManager)
|
||||
itemManager.getItems = jest.fn().mockReturnValue(titles.map(mockTag))
|
||||
|
||||
const findOrCreateTagParentChainCalls = itemManager.findOrCreateTagParentChain.mock.calls
|
||||
const changeItemCalls = itemManager.changeItem.mock.calls
|
||||
await TagsToFoldersMigrationApplicator.run(itemManager, mutator)
|
||||
|
||||
const findOrCreateTagParentChainCalls = findOrCreateTagParentChainMock.mock.calls
|
||||
const changeItemCalls = changeItemMock.mock.calls
|
||||
|
||||
expect(findOrCreateTagParentChainCalls.length).toEqual(2)
|
||||
expect(findOrCreateTagParentChainCalls[0][0]).toEqual(['a'])
|
||||
@@ -39,11 +45,11 @@ describe('folders component to hierarchy', () => {
|
||||
it('should not touch flat hierarchies', async () => {
|
||||
const titles = ['a', 'x', 'y', 'z']
|
||||
|
||||
const itemManager = itemManagerMock(titles)
|
||||
await TagsToFoldersMigrationApplicator.run(itemManager as unknown as ItemManager)
|
||||
itemManager.getItems = jest.fn().mockReturnValue(titles.map(mockTag))
|
||||
await TagsToFoldersMigrationApplicator.run(itemManager, mutator)
|
||||
|
||||
const findOrCreateTagParentChainCalls = itemManager.findOrCreateTagParentChain.mock.calls
|
||||
const changeItemCalls = itemManager.changeItem.mock.calls
|
||||
const findOrCreateTagParentChainCalls = findOrCreateTagParentChainMock.mock.calls
|
||||
const changeItemCalls = changeItemMock.mock.calls
|
||||
|
||||
expect(findOrCreateTagParentChainCalls.length).toEqual(0)
|
||||
|
||||
@@ -53,11 +59,11 @@ describe('folders component to hierarchy', () => {
|
||||
it('should work despite cloned tags', async () => {
|
||||
const titles = ['a.b', 'c', 'a.b']
|
||||
|
||||
const itemManager = itemManagerMock(titles)
|
||||
await TagsToFoldersMigrationApplicator.run(itemManager as unknown as ItemManager)
|
||||
itemManager.getItems = jest.fn().mockReturnValue(titles.map(mockTag))
|
||||
await TagsToFoldersMigrationApplicator.run(itemManager, mutator)
|
||||
|
||||
const findOrCreateTagParentChainCalls = itemManager.findOrCreateTagParentChain.mock.calls
|
||||
const changeItemCalls = itemManager.changeItem.mock.calls
|
||||
const findOrCreateTagParentChainCalls = findOrCreateTagParentChainMock.mock.calls
|
||||
const changeItemCalls = changeItemMock.mock.calls
|
||||
|
||||
expect(findOrCreateTagParentChainCalls.length).toEqual(2)
|
||||
expect(findOrCreateTagParentChainCalls[0][0]).toEqual(['a'])
|
||||
@@ -71,11 +77,11 @@ describe('folders component to hierarchy', () => {
|
||||
it('should produce a valid hierarchy cases with missing intermediate tags or unordered', async () => {
|
||||
const titles = ['y.2', 'w.3', 'y']
|
||||
|
||||
const itemManager = itemManagerMock(titles)
|
||||
await TagsToFoldersMigrationApplicator.run(itemManager as unknown as ItemManager)
|
||||
itemManager.getItems = jest.fn().mockReturnValue(titles.map(mockTag))
|
||||
await TagsToFoldersMigrationApplicator.run(itemManager, mutator)
|
||||
|
||||
const findOrCreateTagParentChainCalls = itemManager.findOrCreateTagParentChain.mock.calls
|
||||
const changeItemCalls = itemManager.changeItem.mock.calls
|
||||
const findOrCreateTagParentChainCalls = findOrCreateTagParentChainMock.mock.calls
|
||||
const changeItemCalls = changeItemMock.mock.calls
|
||||
|
||||
expect(findOrCreateTagParentChainCalls.length).toEqual(2)
|
||||
expect(findOrCreateTagParentChainCalls[0][0]).toEqual(['w'])
|
||||
@@ -89,11 +95,11 @@ describe('folders component to hierarchy', () => {
|
||||
it('skip prefixed names', async () => {
|
||||
const titles = ['.something', '.something...something']
|
||||
|
||||
const itemManager = itemManagerMock(titles)
|
||||
await TagsToFoldersMigrationApplicator.run(itemManager as unknown as ItemManager)
|
||||
itemManager.getItems = jest.fn().mockReturnValue(titles.map(mockTag))
|
||||
await TagsToFoldersMigrationApplicator.run(itemManager, mutator)
|
||||
|
||||
const findOrCreateTagParentChainCalls = itemManager.findOrCreateTagParentChain.mock.calls
|
||||
const changeItemCalls = itemManager.changeItem.mock.calls
|
||||
const findOrCreateTagParentChainCalls = findOrCreateTagParentChainMock.mock.calls
|
||||
const changeItemCalls = changeItemMock.mock.calls
|
||||
|
||||
expect(findOrCreateTagParentChainCalls.length).toEqual(0)
|
||||
expect(changeItemCalls.length).toEqual(0)
|
||||
@@ -109,11 +115,11 @@ describe('folders component to hierarchy', () => {
|
||||
'something..another.thing..anyway',
|
||||
]
|
||||
|
||||
const itemManager = itemManagerMock(titles)
|
||||
await TagsToFoldersMigrationApplicator.run(itemManager as unknown as ItemManager)
|
||||
itemManager.getItems = jest.fn().mockReturnValue(titles.map(mockTag))
|
||||
await TagsToFoldersMigrationApplicator.run(itemManager, mutator)
|
||||
|
||||
const findOrCreateTagParentChainCalls = itemManager.findOrCreateTagParentChain.mock.calls
|
||||
const changeItemCalls = itemManager.changeItem.mock.calls
|
||||
const findOrCreateTagParentChainCalls = findOrCreateTagParentChainMock.mock.calls
|
||||
const changeItemCalls = changeItemMock.mock.calls
|
||||
|
||||
expect(findOrCreateTagParentChainCalls.length).toEqual(1)
|
||||
expect(findOrCreateTagParentChainCalls[0][0]).toEqual(['a', 'b'])
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MutatorClientInterface } from '@standardnotes/services'
|
||||
import { SNTag, TagMutator, TagFolderDelimitter } from '@standardnotes/models'
|
||||
import { ItemManager } from '@Lib/Services'
|
||||
import { lastElement, sortByKey, withoutLastElement } from '@standardnotes/utils'
|
||||
@@ -15,7 +16,7 @@ export class TagsToFoldersMigrationApplicator {
|
||||
return false
|
||||
}
|
||||
|
||||
public static async run(itemManager: ItemManager): Promise<void> {
|
||||
public static async run(itemManager: ItemManager, mutator: MutatorClientInterface): Promise<void> {
|
||||
const tags = itemManager.getItems(ContentType.Tag) as SNTag[]
|
||||
const sortedTags = sortByKey(tags, 'title')
|
||||
|
||||
@@ -36,9 +37,9 @@ export class TagsToFoldersMigrationApplicator {
|
||||
return
|
||||
}
|
||||
|
||||
const parent = await itemManager.findOrCreateTagParentChain(parents)
|
||||
const parent = await mutator.findOrCreateTagParentChain(parents)
|
||||
|
||||
await itemManager.changeItem(tag, (mutator: TagMutator) => {
|
||||
await mutator.changeItem(tag, (mutator: TagMutator) => {
|
||||
mutator.title = newTitle
|
||||
|
||||
if (parent) {
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { AnyKeyParamsContent, KeyParamsContent004 } from '@standardnotes/common'
|
||||
import { EncryptedPayload, EncryptedTransferPayload, isErrorDecryptingPayload } from '@standardnotes/models'
|
||||
import {
|
||||
EncryptedPayload,
|
||||
EncryptedTransferPayload,
|
||||
isErrorDecryptingPayload,
|
||||
ContentTypeUsesRootKeyEncryption,
|
||||
} from '@standardnotes/models'
|
||||
import { PreviousSnjsVersion1_0_0, PreviousSnjsVersion2_0_0, SnjsVersion } from '../Version'
|
||||
import { Migration } from '@Lib/Migrations/Migration'
|
||||
import {
|
||||
@@ -16,7 +21,6 @@ import {
|
||||
import { assert } from '@standardnotes/utils'
|
||||
import { CreateReader } from './StorageReaders/Functions'
|
||||
import { StorageReader } from './StorageReaders/Reader'
|
||||
import { ContentTypeUsesRootKeyEncryption } from '@standardnotes/encryption'
|
||||
|
||||
/** A key that was briefly present in Snjs version 2.0.0 but removed in 2.0.1 */
|
||||
const LastMigrationTimeStampKey2_0_0 = 'last_migration_timestamp'
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { BackupServiceInterface } from '@standardnotes/files'
|
||||
import { Environment, Platform } from '@standardnotes/models'
|
||||
import { DeviceInterface, InternalEventBusInterface, EncryptionService } from '@standardnotes/services'
|
||||
import {
|
||||
DeviceInterface,
|
||||
InternalEventBusInterface,
|
||||
EncryptionService,
|
||||
MutatorClientInterface,
|
||||
} from '@standardnotes/services'
|
||||
import { SNSessionManager } from '../Services/Session/SessionManager'
|
||||
import { ApplicationIdentifier } from '@standardnotes/common'
|
||||
import { ItemManager } from '@Lib/Services/Items/ItemManager'
|
||||
@@ -15,6 +20,7 @@ export type MigrationServices = {
|
||||
sessionManager: SNSessionManager
|
||||
backups?: BackupServiceInterface
|
||||
itemManager: ItemManager
|
||||
mutator: MutatorClientInterface
|
||||
singletonManager: SNSingletonManager
|
||||
featuresService: SNFeaturesService
|
||||
environment: Environment
|
||||
|
||||
@@ -20,7 +20,7 @@ export class Migration2_20_0 extends Migration {
|
||||
|
||||
for (const item of items) {
|
||||
this.services.itemManager.removeItemLocally(item)
|
||||
await this.services.storageService.deletePayloadWithId(item.uuid)
|
||||
await this.services.storageService.deletePayloadWithUuid(item.uuid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ export class Migration2_36_0 extends Migration {
|
||||
|
||||
for (const item of items) {
|
||||
this.services.itemManager.removeItemLocally(item)
|
||||
await this.services.storageService.deletePayloadWithId(item.uuid)
|
||||
await this.services.storageService.deletePayloadWithUuid(item.uuid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export class Migration2_42_0 extends Migration {
|
||||
})
|
||||
|
||||
for (const theme of themes) {
|
||||
await this.services.itemManager.setItemToBeDeleted(theme)
|
||||
await this.services.mutator.setItemToBeDeleted(theme)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export class Migration2_7_0 extends Migration {
|
||||
const batchMgrSingleton = this.services.singletonManager.findSingleton(ContentType.Component, batchMgrPred)
|
||||
|
||||
if (batchMgrSingleton) {
|
||||
await this.services.itemManager.setItemToBeDeleted(batchMgrSingleton)
|
||||
await this.services.mutator.setItemToBeDeleted(batchMgrSingleton)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user