2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { Disposable, DisposableMap, MutableDisposable, isDisposable, toDisposable } from '../../../base/common/lifecycle.js';
7
>
import { IStorage, IStorageDatabase, Storage } from '../../../base/parts/storage/common/storage.js';
8
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
9
>
import { AbstractStorageService, IStorageService, IStorageValueChangeEvent, StorageScope, StorageTarget, isProfileUsingDefaultStorage } from '../../storage/common/storage.js';
10
>
import { Emitter, Event } from '../../../base/common/event.js';
11
>
import { IRemoteService } from '../../ipc/common/services.js';
12
>
import { ILogService } from '../../log/common/log.js';
13
>
import { ApplicationStorageDatabaseClient, ProfileStorageDatabaseClient } from '../../storage/common/storageIpc.js';
14
>
import { IUserDataProfile, IUserDataProfilesService, reviveProfile } from './userDataProfile.js';
15
>
16
>
export interface IProfileStorageValueChanges {
17
>
readonly profile: IUserDataProfile;
18
>
readonly changes: IStorageValueChangeEvent[];
19
>
}
20
>
21
>
export interface IProfileStorageChanges {
22
>
readonly targetChanges: IUserDataProfile[];
23
>
readonly valueChanges: IProfileStorageValueChanges[];
24
>
}
25
>
26
>
export interface IStorageValue {
27
>
readonly value: string | undefined;
28
>
readonly target: StorageTarget;
29
>
readonly scope?: StorageScope;
30
>
}
31
>
32
>
export const IUserDataProfileStorageService = createDecorator<IUserDataProfileStorageService>('IUserDataProfileStorageService');
33
>
export interface IUserDataProfileStorageService {
34
>
readonly _serviceBrand: undefined;
35
>
36
>
/**
37
>
* Emitted whenever data is updated or deleted in a profile storage or target of a profile storage entry changes
38
>
*/
39
>
readonly onDidChange: Event<IProfileStorageChanges>;
40
>
41
>
/**
42
>
* Return the requested profile storage data
43
>
* @param profile The profile from which the data has to be read from
44
>
*/
45
>
readStorageData(profile: IUserDataProfile): Promise<Map<string, IStorageValue>>;
46
>
47
>
/**
48
>
* Update the given profile storage data in the profile storage
49
>
* @param profile The profile to which the data has to be written to
50
>
* @param data Data that has to be updated
51
>
* @param target Storage target of the data
52
>
* @param scope Storage scope of the data (defaults to PROFILE)
53
>
*/
54
>
updateStorageData(profile: IUserDataProfile, data: Map<string, string | undefined | null>, target: StorageTarget, scope?: StorageScope): Promise<void>;
55
>
56
>
/**
57
>
* Calls a function with a storage service scoped to given profile.
58
>
*/
59
>
withProfileScopedStorageService<T>(profile: IUserDataProfile, fn: (storageService: IStorageService) => Promise<T>): Promise<T>;
60
>
}
61
>
62
>
export abstract class AbstractUserDataProfileStorageService extends Disposable implements IUserDataProfileStorageService {
63
>
64
>
_serviceBrand: undefined;
65
>
66
>
readonly abstract onDidChange: Event<IProfileStorageChanges>;
67
>
68
>
private readonly storageServicesMap: DisposableMap<string, StorageService> | undefined;
69
>
70
>
constructor(
71
persistStorages: boolean,
72
@IStorageService protected readonly storageService: IStorageService