storage2.ts 4.1 KB
Newer Older
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { Event } from 'vs/base/common/event';

9
export const INextStorageService = createDecorator<INextStorageService>('nextStorageService');
10

11 12
export interface INextStorageService {
	_serviceBrand: any;
13

14 15 16 17
	/**
	 * Emitted whenever data is updated or deleted.
	 */
	readonly onDidChangeStorage: Event<Set<string>>;
18 19

	/**
20 21
	 * Retrieve an element stored with the given key from storage. Use
	 * the provided defaultValue if the element is null or undefined.
22
	 */
23
	get(key: string, fallbackValue?: string): string;
24 25

	/**
26 27 28
	 * Retrieve an element stored with the given key from storage. Use
	 * the provided defaultValue if the element is null or undefined. The element
	 * will be converted to a boolean.
29
	 */
30
	getBoolean(key: string, fallbackValue?: boolean): boolean;
31

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
	/**
	 * Retrieve an element stored with the given key from storage. Use
	 * the provided defaultValue if the element is null or undefined. The element
	 * will be converted to a number using parseInt with a base of 10.
	 */
	getInteger(key: string, fallbackValue?: number): number;

	/**
	 * Store a string value under the given key to storage. The value will
	 * be converted to a string.
	 */
	set(key: string, value: any): Promise<void>;

	/**
	 * Delete an element stored under the provided key from storage.
	 */
	delete(key: string): Promise<void>;
49 50
}

51 52
export const INextWorkspaceStorageService = createDecorator<INextWorkspaceStorageService>('nextWorkspaceStorageService');

53 54 55
export interface INextWorkspaceStorageService {
	_serviceBrand: any;

56 57 58
	/**
	 * Emitted whenever data is updated or deleted.
	 */
59 60 61 62 63 64
	readonly onDidChangeStorage: Event<IWorkspaceStorageChangeEvent>;

	/**
	 * Retrieve an element stored with the given key from storage. Use
	 * the provided defaultValue if the element is null or undefined.
	 *
B
Benjamin Pasero 已提交
65
	 * The scope argument allows to define the scope of the storage
66 67
	 * operation to either the current workspace only or all workspaces.
	 */
B
Benjamin Pasero 已提交
68
	get(key: string, scope: StorageScope, fallbackValue?: string): string;
69 70 71 72 73 74

	/**
	 * Retrieve an element stored with the given key from storage. Use
	 * the provided defaultValue if the element is null or undefined. The element
	 * will be converted to a boolean.
	 *
B
Benjamin Pasero 已提交
75
	 * The scope argument allows to define the scope of the storage
76 77
	 * operation to either the current workspace only or all workspaces.
	 */
B
Benjamin Pasero 已提交
78
	getBoolean(key: string, scope: StorageScope, fallbackValue?: boolean): boolean;
79 80 81 82 83 84

	/**
	 * Retrieve an element stored with the given key from storage. Use
	 * the provided defaultValue if the element is null or undefined. The element
	 * will be converted to a number using parseInt with a base of 10.
	 *
B
Benjamin Pasero 已提交
85
	 * The scope argument allows to define the scope of the storage
86 87
	 * operation to either the current workspace only or all workspaces.
	 */
B
Benjamin Pasero 已提交
88
	getInteger(key: string, scope: StorageScope, fallbackValue?: number): number;
89 90 91 92 93

	/**
	 * Store a string value under the given key to storage. The value will
	 * be converted to a string.
	 *
B
Benjamin Pasero 已提交
94
	 * The scope argument allows to define the scope of the storage
95 96
	 * operation to either the current workspace only or all workspaces.
	 */
B
Benjamin Pasero 已提交
97
	set(key: string, value: any, scope: StorageScope): Promise<void>;
98 99 100 101

	/**
	 * Delete an element stored under the provided key from storage.
	 *
B
Benjamin Pasero 已提交
102
	 * The scope argument allows to define the scope of the storage
103 104
	 * operation to either the current workspace only or all workspaces.
	 */
B
Benjamin Pasero 已提交
105
	delete(key: string, scope: StorageScope): Promise<void>;
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
}

export const enum StorageScope {

	/**
	 * The stored data will be scoped to all workspaces.
	 */
	GLOBAL,

	/**
	 * The stored data will be scoped to the current workspace.
	 */
	WORKSPACE
}

export interface IWorkspaceStorageChangeEvent {
	keys: Set<string>;
	scope: StorageScope;
124
}