@codingame/monaco-vscode-api 1.81.2 → 1.81.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ import { getErrorMessage } from 'monaco-editor/esm/vs/base/common/errors.js';
2
+ import { Emitter } from 'monaco-editor/esm/vs/base/common/event.js';
3
+ import { Disposable, toDisposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
4
+ class BroadcastDataChannel extends Disposable {
5
+ constructor(channelName) {
6
+ super();
7
+ this.channelName = channelName;
8
+ this._onDidReceiveData = this._register(( new Emitter()));
9
+ this.onDidReceiveData = this._onDidReceiveData.event;
10
+ if ('BroadcastChannel' in window) {
11
+ try {
12
+ this.broadcastChannel = ( new BroadcastChannel(channelName));
13
+ const listener = (event) => {
14
+ this._onDidReceiveData.fire(event.data);
15
+ };
16
+ this.broadcastChannel.addEventListener('message', listener);
17
+ this._register(toDisposable(() => {
18
+ if (this.broadcastChannel) {
19
+ this.broadcastChannel.removeEventListener('message', listener);
20
+ this.broadcastChannel.close();
21
+ }
22
+ }));
23
+ }
24
+ catch (error) {
25
+ console.warn('Error while creating broadcast channel. Falling back to localStorage.', getErrorMessage(error));
26
+ }
27
+ }
28
+ if (!this.broadcastChannel) {
29
+ this.channelName = `BroadcastDataChannel.${channelName}`;
30
+ this.createBroadcastChannel();
31
+ }
32
+ }
33
+ createBroadcastChannel() {
34
+ const listener = (event) => {
35
+ if (event.key === this.channelName && event.newValue) {
36
+ this._onDidReceiveData.fire(JSON.parse(event.newValue));
37
+ }
38
+ };
39
+ window.addEventListener('storage', listener);
40
+ this._register(toDisposable(() => window.removeEventListener('storage', listener)));
41
+ }
42
+ postData(data) {
43
+ if (this.broadcastChannel) {
44
+ this.broadcastChannel.postMessage(data);
45
+ }
46
+ else {
47
+ window.localStorage.removeItem(this.channelName);
48
+ window.localStorage.setItem(this.channelName, JSON.stringify(data));
49
+ }
50
+ }
51
+ }
52
+ export { BroadcastDataChannel };
@@ -1,7 +1,44 @@
1
+ import { Event } from '../../../common/event.js';
2
+ import { IDisposable } from '../../../common/lifecycle.js';
3
+
1
4
  interface IStorageItemsChangeEvent {
2
5
  readonly changed?: Map<string, string>;
3
6
  readonly deleted?: Set<string>;
4
7
  }
8
+ interface IStorageChangeEvent {
9
+ /**
10
+ * The `key` of the storage entry that was changed
11
+ * or was removed.
12
+ */
13
+ readonly key: string;
14
+ /**
15
+ * A hint how the storage change event was triggered. If
16
+ * `true`, the storage change was triggered by an external
17
+ * source, such as:
18
+ * - another process (for example another window)
19
+ * - operations such as settings sync or profiles change
20
+ */
21
+ readonly external?: boolean;
22
+ }
5
23
  type StorageValue = string | boolean | number | undefined | null | object;
24
+ interface IStorage extends IDisposable {
25
+ readonly onDidChangeStorage: Event<IStorageChangeEvent>;
26
+ readonly items: Map<string, string>;
27
+ readonly size: number;
28
+ init(): Promise<void>;
29
+ get(key: string, fallbackValue: string): string;
30
+ get(key: string, fallbackValue?: string): string | undefined;
31
+ getBoolean(key: string, fallbackValue: boolean): boolean;
32
+ getBoolean(key: string, fallbackValue?: boolean): boolean | undefined;
33
+ getNumber(key: string, fallbackValue: number): number;
34
+ getNumber(key: string, fallbackValue?: number): number | undefined;
35
+ getObject<T extends object>(key: string, fallbackValue: T): T;
36
+ getObject<T extends object>(key: string, fallbackValue?: T): T | undefined;
37
+ set(key: string, value: StorageValue, external?: boolean): Promise<void>;
38
+ delete(key: string, external?: boolean): Promise<void>;
39
+ flush(delay?: number): Promise<void>;
40
+ whenFlushed(): Promise<void>;
41
+ close(): Promise<void>;
42
+ }
6
43
 
7
- export { IStorageItemsChangeEvent, StorageValue };
44
+ export { IStorage, IStorageChangeEvent, IStorageItemsChangeEvent, StorageValue };
@@ -1,6 +1,7 @@
1
1
  import { ServiceIdentifier } from '../../instantiation/common/instantiation.js';
2
2
  import { Event } from '../../../base/common/event.js';
3
- import { StorageValue } from '../../../base/parts/storage/common/storage.js';
3
+ import { Disposable } from '../../../base/common/lifecycle.js';
4
+ import { StorageValue, IStorageChangeEvent, IStorage } from '../../../base/parts/storage/common/storage.js';
4
5
  import { IUserDataProfile } from '../../userDataProfile/common/userDataProfile.js';
5
6
  import { IAnyWorkspaceIdentifier } from '../../workspace/common/workspace.js';
6
7
 
@@ -216,5 +217,63 @@ interface IStorageTargetChangeEvent {
216
217
  */
217
218
  readonly scope: StorageScope;
218
219
  }
220
+ interface IStorageServiceOptions {
221
+ readonly flushInterval: number;
222
+ }
223
+ declare abstract class AbstractStorageService extends Disposable implements IStorageService {
224
+ private readonly options;
225
+ readonly _serviceBrand: undefined;
226
+ private static DEFAULT_FLUSH_INTERVAL;
227
+ private readonly _onDidChangeValue;
228
+ readonly onDidChangeValue: Event<IStorageValueChangeEvent>;
229
+ private readonly _onDidChangeTarget;
230
+ readonly onDidChangeTarget: Event<IStorageTargetChangeEvent>;
231
+ private readonly _onWillSaveState;
232
+ readonly onWillSaveState: Event<IWillSaveStateEvent>;
233
+ private initializationPromise;
234
+ private readonly flushWhenIdleScheduler;
235
+ private readonly runFlushWhenIdle;
236
+ constructor(options?: IStorageServiceOptions);
237
+ private doFlushWhenIdle;
238
+ protected shouldFlushWhenIdle(): boolean;
239
+ protected stopFlushWhenIdle(): void;
240
+ initialize(): Promise<void>;
241
+ protected emitDidChangeValue(scope: StorageScope, event: IStorageChangeEvent): void;
242
+ protected emitWillSaveState(reason: WillSaveStateReason): void;
243
+ get(key: string, scope: StorageScope, fallbackValue: string): string;
244
+ get(key: string, scope: StorageScope): string | undefined;
245
+ getBoolean(key: string, scope: StorageScope, fallbackValue: boolean): boolean;
246
+ getBoolean(key: string, scope: StorageScope): boolean | undefined;
247
+ getNumber(key: string, scope: StorageScope, fallbackValue: number): number;
248
+ getNumber(key: string, scope: StorageScope): number | undefined;
249
+ getObject(key: string, scope: StorageScope, fallbackValue: object): object;
250
+ getObject(key: string, scope: StorageScope): object | undefined;
251
+ storeAll(entries: Array<IStorageEntry>, external: boolean): void;
252
+ store(key: string, value: StorageValue, scope: StorageScope, target: StorageTarget, external?: boolean): void;
253
+ remove(key: string, scope: StorageScope, external?: boolean): void;
254
+ private withPausedEmitters;
255
+ keys(scope: StorageScope, target: StorageTarget): string[];
256
+ private updateKeyTarget;
257
+ private _workspaceKeyTargets;
258
+ private get workspaceKeyTargets();
259
+ private _profileKeyTargets;
260
+ private get profileKeyTargets();
261
+ private _applicationKeyTargets;
262
+ private get applicationKeyTargets();
263
+ private getKeyTargets;
264
+ private loadKeyTargets;
265
+ isNew(scope: StorageScope): boolean;
266
+ flush(reason?: WillSaveStateReason): Promise<void>;
267
+ log(): Promise<void>;
268
+ switch(to: IAnyWorkspaceIdentifier | IUserDataProfile, preserveData: boolean): Promise<void>;
269
+ protected canSwitchProfile(from: IUserDataProfile, to: IUserDataProfile): boolean;
270
+ protected switchData(oldStorage: Map<string, string>, newStorage: IStorage, scope: StorageScope): void;
271
+ abstract hasScope(scope: IAnyWorkspaceIdentifier | IUserDataProfile): boolean;
272
+ protected abstract doInitialize(): Promise<void>;
273
+ protected abstract getStorage(scope: StorageScope): IStorage | undefined;
274
+ protected abstract getLogDetails(scope: StorageScope): string | undefined;
275
+ protected abstract switchToProfile(toProfile: IUserDataProfile, preserveData: boolean): Promise<void>;
276
+ protected abstract switchToWorkspace(toWorkspace: IAnyWorkspaceIdentifier | IUserDataProfile, preserveData: boolean): Promise<void>;
277
+ }
219
278
 
220
- export { IStorageEntry, IStorageService, IStorageTargetChangeEvent, IStorageValueChangeEvent, IWillSaveStateEvent, StorageScope, StorageTarget, WillSaveStateReason };
279
+ export { AbstractStorageService, IStorageEntry, IStorageService, IStorageServiceOptions, IStorageTargetChangeEvent, IStorageValueChangeEvent, IWillSaveStateEvent, StorageScope, StorageTarget, WillSaveStateReason };
@@ -1,6 +1,17 @@
1
1
  import { refineServiceDecorator } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
2
2
  import { ILayoutService } from 'monaco-editor/esm/vs/platform/layout/browser/layoutService.js';
3
3
  const IWorkbenchLayoutService = refineServiceDecorator(ILayoutService);
4
+ var Parts;
5
+ ( (function(Parts) {
6
+ Parts["TITLEBAR_PART"] = "workbench.parts.titlebar";
7
+ Parts["BANNER_PART"] = "workbench.parts.banner";
8
+ Parts["ACTIVITYBAR_PART"] = "workbench.parts.activitybar";
9
+ Parts["SIDEBAR_PART"] = "workbench.parts.sidebar";
10
+ Parts["PANEL_PART"] = "workbench.parts.panel";
11
+ Parts["AUXILIARYBAR_PART"] = "workbench.parts.auxiliarybar";
12
+ Parts["EDITOR_PART"] = "workbench.parts.editor";
13
+ Parts["STATUSBAR_PART"] = "workbench.parts.statusbar";
14
+ })(Parts || (Parts = {})));
4
15
  function positionToString(position) {
5
16
  switch (position) {
6
17
  case 0 : return 'left';
@@ -9,4 +20,4 @@ function positionToString(position) {
9
20
  default: return 'bottom';
10
21
  }
11
22
  }
12
- export { IWorkbenchLayoutService, positionToString };
23
+ export { IWorkbenchLayoutService, Parts, positionToString };
@@ -0,0 +1,40 @@
1
+ import { IStorage } from '../../../../base/parts/storage/common/storage.js';
2
+ import { ILogService } from '../../../../platform/log/common/log.js';
3
+ import { AbstractStorageService, StorageScope } from '../../../../platform/storage/common/storage.js';
4
+ import { IUserDataProfile } from '../../../../platform/userDataProfile/common/userDataProfile.js';
5
+ import { IAnyWorkspaceIdentifier } from '../../../../platform/workspace/common/workspace.js';
6
+ import { IUserDataProfileService } from '../../userDataProfile/common/userDataProfile.js';
7
+
8
+ declare class BrowserStorageService extends AbstractStorageService {
9
+ private readonly workspace;
10
+ private readonly userDataProfileService;
11
+ private readonly logService;
12
+ private static BROWSER_DEFAULT_FLUSH_INTERVAL;
13
+ private applicationStorage;
14
+ private applicationStorageDatabase;
15
+ private readonly applicationStoragePromise;
16
+ private profileStorage;
17
+ private profileStorageDatabase;
18
+ private profileStorageProfile;
19
+ private readonly profileStorageDisposables;
20
+ private workspaceStorage;
21
+ private workspaceStorageDatabase;
22
+ get hasPendingUpdate(): boolean;
23
+ constructor(workspace: IAnyWorkspaceIdentifier, userDataProfileService: IUserDataProfileService, logService: ILogService);
24
+ private registerListeners;
25
+ protected doInitialize(): Promise<void>;
26
+ private createApplicationStorage;
27
+ private createProfileStorage;
28
+ private createWorkspaceStorage;
29
+ private updateIsNew;
30
+ protected getStorage(scope: StorageScope): IStorage | undefined;
31
+ protected getLogDetails(scope: StorageScope): string | undefined;
32
+ protected switchToProfile(toProfile: IUserDataProfile): Promise<void>;
33
+ protected switchToWorkspace(toWorkspace: IAnyWorkspaceIdentifier, preserveData: boolean): Promise<void>;
34
+ protected shouldFlushWhenIdle(): boolean;
35
+ close(): void;
36
+ clear(): Promise<void>;
37
+ hasScope(scope: IAnyWorkspaceIdentifier | IUserDataProfile): boolean;
38
+ }
39
+
40
+ export { BrowserStorageService };
@@ -0,0 +1,278 @@
1
+ import { __decorate, __param } from '../../../../../../node_modules/tslib/tslib.es6.js';
2
+ import { BroadcastDataChannel } from '../../../../base/browser/broadcast.js';
3
+ import { isSafari } from 'monaco-editor/esm/vs/base/browser/browser.js';
4
+ import { IndexedDB } from 'monaco-editor/esm/vs/base/browser/indexedDB.js';
5
+ import { DeferredPromise, Promises } from 'monaco-editor/esm/vs/base/common/async.js';
6
+ import { toErrorMessage } from 'monaco-editor/esm/vs/base/common/errorMessage.js';
7
+ import { Emitter } from 'monaco-editor/esm/vs/base/common/event.js';
8
+ import { DisposableStore, Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
9
+ import { assertIsDefined } from 'monaco-editor/esm/vs/base/common/types.js';
10
+ import { Storage, isStorageItemsChangeEvent, InMemoryStorageDatabase } from 'monaco-editor/esm/vs/base/parts/storage/common/storage.js';
11
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
12
+ import { AbstractStorageService, isProfileUsingDefaultStorage, IS_NEW_KEY } from 'monaco-editor/esm/vs/platform/storage/common/storage.js';
13
+ import { isUserDataProfile } from 'monaco-editor/esm/vs/platform/userDataProfile/common/userDataProfile.js';
14
+ let BrowserStorageService = class BrowserStorageService extends AbstractStorageService {
15
+ static { this.BROWSER_DEFAULT_FLUSH_INTERVAL = 5 * 1000; }
16
+ get hasPendingUpdate() {
17
+ return Boolean(this.applicationStorageDatabase?.hasPendingUpdate ||
18
+ this.profileStorageDatabase?.hasPendingUpdate ||
19
+ this.workspaceStorageDatabase?.hasPendingUpdate);
20
+ }
21
+ constructor(workspace, userDataProfileService, logService) {
22
+ super({ flushInterval: BrowserStorageService.BROWSER_DEFAULT_FLUSH_INTERVAL });
23
+ this.workspace = workspace;
24
+ this.userDataProfileService = userDataProfileService;
25
+ this.logService = logService;
26
+ this.applicationStoragePromise = ( new DeferredPromise());
27
+ this.profileStorageProfile = this.userDataProfileService.currentProfile;
28
+ this.profileStorageDisposables = this._register(( new DisposableStore()));
29
+ this.registerListeners();
30
+ }
31
+ registerListeners() {
32
+ this._register(this.userDataProfileService.onDidChangeCurrentProfile(e => e.join(this.switchToProfile(e.profile))));
33
+ }
34
+ async doInitialize() {
35
+ await Promises.settled([
36
+ this.createApplicationStorage(),
37
+ this.createProfileStorage(this.profileStorageProfile),
38
+ this.createWorkspaceStorage()
39
+ ]);
40
+ }
41
+ async createApplicationStorage() {
42
+ const applicationStorageIndexedDB = await IndexedDBStorageDatabase.createApplicationStorage(this.logService);
43
+ this.applicationStorageDatabase = this._register(applicationStorageIndexedDB);
44
+ this.applicationStorage = this._register(( new Storage(this.applicationStorageDatabase)));
45
+ this._register(this.applicationStorage.onDidChangeStorage(e => this.emitDidChangeValue(-1 , e)));
46
+ await this.applicationStorage.init();
47
+ this.updateIsNew(this.applicationStorage);
48
+ this.applicationStoragePromise.complete({ indexedDb: applicationStorageIndexedDB, storage: this.applicationStorage });
49
+ }
50
+ async createProfileStorage(profile) {
51
+ this.profileStorageDisposables.clear();
52
+ this.profileStorageProfile = profile;
53
+ if (isProfileUsingDefaultStorage(this.profileStorageProfile)) {
54
+ const { indexedDb: applicationStorageIndexedDB, storage: applicationStorage } = await this.applicationStoragePromise.p;
55
+ this.profileStorageDatabase = applicationStorageIndexedDB;
56
+ this.profileStorage = applicationStorage;
57
+ this.profileStorageDisposables.add(this.profileStorage.onDidChangeStorage(e => this.emitDidChangeValue(0 , e)));
58
+ }
59
+ else {
60
+ const profileStorageIndexedDB = await IndexedDBStorageDatabase.createProfileStorage(this.profileStorageProfile, this.logService);
61
+ this.profileStorageDatabase = this.profileStorageDisposables.add(profileStorageIndexedDB);
62
+ this.profileStorage = this.profileStorageDisposables.add(( new Storage(this.profileStorageDatabase)));
63
+ this.profileStorageDisposables.add(this.profileStorage.onDidChangeStorage(e => this.emitDidChangeValue(0 , e)));
64
+ await this.profileStorage.init();
65
+ this.updateIsNew(this.profileStorage);
66
+ }
67
+ }
68
+ async createWorkspaceStorage() {
69
+ const workspaceStorageIndexedDB = await IndexedDBStorageDatabase.createWorkspaceStorage(this.workspace.id, this.logService);
70
+ this.workspaceStorageDatabase = this._register(workspaceStorageIndexedDB);
71
+ this.workspaceStorage = this._register(( new Storage(this.workspaceStorageDatabase)));
72
+ this._register(this.workspaceStorage.onDidChangeStorage(e => this.emitDidChangeValue(1 , e)));
73
+ await this.workspaceStorage.init();
74
+ this.updateIsNew(this.workspaceStorage);
75
+ }
76
+ updateIsNew(storage) {
77
+ const firstOpen = storage.getBoolean(IS_NEW_KEY);
78
+ if (firstOpen === undefined) {
79
+ storage.set(IS_NEW_KEY, true);
80
+ }
81
+ else if (firstOpen) {
82
+ storage.set(IS_NEW_KEY, false);
83
+ }
84
+ }
85
+ getStorage(scope) {
86
+ switch (scope) {
87
+ case -1 :
88
+ return this.applicationStorage;
89
+ case 0 :
90
+ return this.profileStorage;
91
+ default:
92
+ return this.workspaceStorage;
93
+ }
94
+ }
95
+ getLogDetails(scope) {
96
+ switch (scope) {
97
+ case -1 :
98
+ return this.applicationStorageDatabase?.name;
99
+ case 0 :
100
+ return this.profileStorageDatabase?.name;
101
+ default:
102
+ return this.workspaceStorageDatabase?.name;
103
+ }
104
+ }
105
+ async switchToProfile(toProfile) {
106
+ if (!this.canSwitchProfile(this.profileStorageProfile, toProfile)) {
107
+ return;
108
+ }
109
+ const oldProfileStorage = assertIsDefined(this.profileStorage);
110
+ const oldItems = oldProfileStorage.items;
111
+ if (oldProfileStorage !== this.applicationStorage) {
112
+ await oldProfileStorage.close();
113
+ }
114
+ await this.createProfileStorage(toProfile);
115
+ this.switchData(oldItems, assertIsDefined(this.profileStorage), 0 );
116
+ }
117
+ async switchToWorkspace(toWorkspace, preserveData) {
118
+ throw new Error('Migrating storage is currently unsupported in Web');
119
+ }
120
+ shouldFlushWhenIdle() {
121
+ return document.hasFocus() && !this.hasPendingUpdate;
122
+ }
123
+ close() {
124
+ if (isSafari) {
125
+ this.applicationStorage?.close();
126
+ this.profileStorageDatabase?.close();
127
+ this.workspaceStorageDatabase?.close();
128
+ }
129
+ this.dispose();
130
+ }
131
+ async clear() {
132
+ for (const scope of [-1 , 0 , 1 ]) {
133
+ for (const target of [0 , 1 ]) {
134
+ for (const key of ( this.keys(scope, target))) {
135
+ this.remove(key, scope);
136
+ }
137
+ }
138
+ await this.getStorage(scope)?.whenFlushed();
139
+ }
140
+ await Promises.settled([
141
+ this.applicationStorageDatabase?.clear() ?? Promise.resolve(),
142
+ this.profileStorageDatabase?.clear() ?? Promise.resolve(),
143
+ this.workspaceStorageDatabase?.clear() ?? Promise.resolve()
144
+ ]);
145
+ }
146
+ hasScope(scope) {
147
+ if (isUserDataProfile(scope)) {
148
+ return this.profileStorageProfile.id === scope.id;
149
+ }
150
+ return this.workspace.id === scope.id;
151
+ }
152
+ };
153
+ BrowserStorageService = ( __decorate([
154
+ ( __param(2, ILogService))
155
+ ], BrowserStorageService));
156
+ class InMemoryIndexedDBStorageDatabase extends InMemoryStorageDatabase {
157
+ constructor() {
158
+ super(...arguments);
159
+ this.hasPendingUpdate = false;
160
+ this.name = 'in-memory-indexedb-storage';
161
+ }
162
+ async clear() {
163
+ (await this.getItems()).clear();
164
+ }
165
+ dispose() {
166
+ }
167
+ }
168
+ class IndexedDBStorageDatabase extends Disposable {
169
+ static async createApplicationStorage(logService) {
170
+ return IndexedDBStorageDatabase.create({ id: 'global', broadcastChanges: true }, logService);
171
+ }
172
+ static async createProfileStorage(profile, logService) {
173
+ return IndexedDBStorageDatabase.create({ id: `global-${profile.id}`, broadcastChanges: true }, logService);
174
+ }
175
+ static async createWorkspaceStorage(workspaceId, logService) {
176
+ return IndexedDBStorageDatabase.create({ id: workspaceId }, logService);
177
+ }
178
+ static async create(options, logService) {
179
+ try {
180
+ const database = ( new IndexedDBStorageDatabase(options, logService));
181
+ await database.whenConnected;
182
+ return database;
183
+ }
184
+ catch (error) {
185
+ logService.error(`[IndexedDB Storage ${options.id}] create(): ${toErrorMessage(error, true)}`);
186
+ return ( new InMemoryIndexedDBStorageDatabase());
187
+ }
188
+ }
189
+ static { this.STORAGE_DATABASE_PREFIX = 'vscode-web-state-db-'; }
190
+ static { this.STORAGE_OBJECT_STORE = 'ItemTable'; }
191
+ get hasPendingUpdate() { return !!this.pendingUpdate; }
192
+ constructor(options, logService) {
193
+ super();
194
+ this.logService = logService;
195
+ this._onDidChangeItemsExternal = this._register(( new Emitter()));
196
+ this.onDidChangeItemsExternal = this._onDidChangeItemsExternal.event;
197
+ this.pendingUpdate = undefined;
198
+ this.name = `${IndexedDBStorageDatabase.STORAGE_DATABASE_PREFIX}${options.id}`;
199
+ this.broadcastChannel = options.broadcastChanges ? this._register(( new BroadcastDataChannel(this.name))) : undefined;
200
+ this.whenConnected = this.connect();
201
+ this.registerListeners();
202
+ }
203
+ registerListeners() {
204
+ if (this.broadcastChannel) {
205
+ this._register(this.broadcastChannel.onDidReceiveData(data => {
206
+ if (isStorageItemsChangeEvent(data)) {
207
+ this._onDidChangeItemsExternal.fire(data);
208
+ }
209
+ }));
210
+ }
211
+ }
212
+ async connect() {
213
+ try {
214
+ return await IndexedDB.create(this.name, undefined, [IndexedDBStorageDatabase.STORAGE_OBJECT_STORE]);
215
+ }
216
+ catch (error) {
217
+ this.logService.error(`[IndexedDB Storage ${this.name}] connect() error: ${toErrorMessage(error)}`);
218
+ throw error;
219
+ }
220
+ }
221
+ async getItems() {
222
+ const db = await this.whenConnected;
223
+ function isValid(value) {
224
+ return typeof value === 'string';
225
+ }
226
+ return db.getKeyValues(IndexedDBStorageDatabase.STORAGE_OBJECT_STORE, isValid);
227
+ }
228
+ async updateItems(request) {
229
+ let didUpdate = false;
230
+ this.pendingUpdate = this.doUpdateItems(request);
231
+ try {
232
+ didUpdate = await this.pendingUpdate;
233
+ }
234
+ finally {
235
+ this.pendingUpdate = undefined;
236
+ }
237
+ if (this.broadcastChannel && didUpdate) {
238
+ const event = {
239
+ changed: request.insert,
240
+ deleted: request.delete
241
+ };
242
+ this.broadcastChannel.postData(event);
243
+ }
244
+ }
245
+ async doUpdateItems(request) {
246
+ const toInsert = request.insert;
247
+ const toDelete = request.delete;
248
+ if ((!toInsert && !toDelete) || (toInsert?.size === 0 && toDelete?.size === 0)) {
249
+ return false;
250
+ }
251
+ const db = await this.whenConnected;
252
+ await db.runInTransaction(IndexedDBStorageDatabase.STORAGE_OBJECT_STORE, 'readwrite', objectStore => {
253
+ const requests = [];
254
+ if (toInsert) {
255
+ for (const [key, value] of toInsert) {
256
+ requests.push(objectStore.put(value, key));
257
+ }
258
+ }
259
+ if (toDelete) {
260
+ for (const key of toDelete) {
261
+ requests.push(objectStore.delete(key));
262
+ }
263
+ }
264
+ return requests;
265
+ });
266
+ return true;
267
+ }
268
+ async close() {
269
+ const db = await this.whenConnected;
270
+ await this.pendingUpdate;
271
+ return db.close();
272
+ }
273
+ async clear() {
274
+ const db = await this.whenConnected;
275
+ await db.runInTransaction(IndexedDBStorageDatabase.STORAGE_OBJECT_STORE, 'readwrite', objectStore => objectStore.clear());
276
+ }
277
+ }
278
+ export { BrowserStorageService, IndexedDBStorageDatabase };
@@ -0,0 +1,19 @@
1
+ import { ServiceIdentifier } from '../../../../platform/instantiation/common/instantiation.js';
2
+ import { Event } from '../../../../base/common/event.js';
3
+ import { IUserDataProfile } from '../../../../platform/userDataProfile/common/userDataProfile.js';
4
+
5
+ interface DidChangeUserDataProfileEvent {
6
+ readonly previous: IUserDataProfile;
7
+ readonly profile: IUserDataProfile;
8
+ join(promise: Promise<void>): void;
9
+ }
10
+ declare const IUserDataProfileService: ServiceIdentifier<IUserDataProfileService>;
11
+ interface IUserDataProfileService {
12
+ readonly _serviceBrand: undefined;
13
+ readonly currentProfile: IUserDataProfile;
14
+ readonly onDidChangeCurrentProfile: Event<DidChangeUserDataProfileEvent>;
15
+ updateCurrentProfile(currentProfile: IUserDataProfile): Promise<void>;
16
+ getShortName(profile: IUserDataProfile): string;
17
+ }
18
+
19
+ export { DidChangeUserDataProfileEvent, IUserDataProfileService };