refactor(web): dependency management (#2386)
This commit is contained in:
33
packages/services/src/Domain/UseCase/ChangeAndSaveItem.ts
Normal file
33
packages/services/src/Domain/UseCase/ChangeAndSaveItem.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { SyncOptions } from './../Sync/SyncOptions'
|
||||
import { MutatorClientInterface } from './../Mutator/MutatorClientInterface'
|
||||
import { SyncServiceInterface } from './../Sync/SyncServiceInterface'
|
||||
import { ItemManagerInterface } from '../Item/ItemManagerInterface'
|
||||
import { DecryptedItemInterface, DecryptedItemMutator, MutationType, PayloadEmitSource } from '@standardnotes/models'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
|
||||
export class ChangeAndSaveItem implements UseCaseInterface<DecryptedItemInterface | undefined> {
|
||||
constructor(
|
||||
private readonly items: ItemManagerInterface,
|
||||
private mutator: MutatorClientInterface,
|
||||
private sync: SyncServiceInterface,
|
||||
) {}
|
||||
|
||||
async execute<M extends DecryptedItemMutator = DecryptedItemMutator>(
|
||||
itemToLookupUuidFor: DecryptedItemInterface,
|
||||
mutate: (mutator: M) => void,
|
||||
updateTimestamps = true,
|
||||
emitSource?: PayloadEmitSource,
|
||||
syncOptions?: SyncOptions,
|
||||
): Promise<Result<DecryptedItemInterface | undefined>> {
|
||||
await this.mutator.changeItems(
|
||||
[itemToLookupUuidFor],
|
||||
mutate,
|
||||
updateTimestamps ? MutationType.UpdateUserTimestamps : MutationType.NoUpdateUserTimestamps,
|
||||
emitSource,
|
||||
)
|
||||
|
||||
await this.sync.sync(syncOptions)
|
||||
|
||||
return Result.ok(this.items.findItem(itemToLookupUuidFor.uuid))
|
||||
}
|
||||
}
|
||||
10
packages/services/src/Domain/UseCase/GetHost.ts
Normal file
10
packages/services/src/Domain/UseCase/GetHost.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { LegacyApiServiceInterface } from './../Api/LegacyApiServiceInterface'
|
||||
import { Result, SyncUseCaseInterface } from '@standardnotes/domain-core'
|
||||
|
||||
export class GetHost implements SyncUseCaseInterface<string> {
|
||||
constructor(private legacyApi: LegacyApiServiceInterface) {}
|
||||
|
||||
execute(): Result<string> {
|
||||
return Result.ok(this.legacyApi.getHost())
|
||||
}
|
||||
}
|
||||
18
packages/services/src/Domain/UseCase/SetHost.ts
Normal file
18
packages/services/src/Domain/UseCase/SetHost.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { HttpServiceInterface } from '@standardnotes/api'
|
||||
import { LegacyApiServiceInterface } from '../Api/LegacyApiServiceInterface'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
|
||||
export class SetHost implements UseCaseInterface<void> {
|
||||
constructor(
|
||||
private http: HttpServiceInterface,
|
||||
private legacyApi: LegacyApiServiceInterface,
|
||||
) {}
|
||||
|
||||
async execute(host: string): Promise<Result<string>> {
|
||||
this.http.setHost(host)
|
||||
|
||||
await this.legacyApi.setHost(host)
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user