@codingame/monaco-vscode-user-data-profile-service-override 5.3.0

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.
Files changed (33) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +1 -0
  3. package/package.json +31 -0
  4. package/userDataProfile.js +118 -0
  5. package/vscode/src/vs/platform/userDataProfile/browser/userDataProfile.js +95 -0
  6. package/vscode/src/vs/platform/userDataProfile/common/userDataProfileStorageService.js +84 -0
  7. package/vscode/src/vs/platform/userDataSync/common/extensionsMerge.js +331 -0
  8. package/vscode/src/vs/platform/userDataSync/common/extensionsSync.js +545 -0
  9. package/vscode/src/vs/platform/userDataSync/common/globalStateMerge.js +102 -0
  10. package/vscode/src/vs/platform/userDataSync/common/globalStateSync.js +431 -0
  11. package/vscode/src/vs/platform/userDataSync/common/keybindingsMerge.js +277 -0
  12. package/vscode/src/vs/platform/userDataSync/common/keybindingsSync.js +328 -0
  13. package/vscode/src/vs/platform/userDataSync/common/settingsSync.js +322 -0
  14. package/vscode/src/vs/platform/userDataSync/common/snippetsMerge.js +126 -0
  15. package/vscode/src/vs/platform/userDataSync/common/snippetsSync.js +478 -0
  16. package/vscode/src/vs/platform/userDataSync/common/tasksSync.js +245 -0
  17. package/vscode/src/vs/workbench/contrib/userDataProfile/browser/userDataProfile.contribution.js +9 -0
  18. package/vscode/src/vs/workbench/contrib/userDataProfile/browser/userDataProfile.js +495 -0
  19. package/vscode/src/vs/workbench/contrib/userDataProfile/browser/userDataProfileActions.js +159 -0
  20. package/vscode/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilePreview.js +24 -0
  21. package/vscode/src/vs/workbench/services/userData/browser/userDataInit.js +62 -0
  22. package/vscode/src/vs/workbench/services/userDataProfile/browser/extensionsResource.js +328 -0
  23. package/vscode/src/vs/workbench/services/userDataProfile/browser/globalStateResource.js +144 -0
  24. package/vscode/src/vs/workbench/services/userDataProfile/browser/keybindingsResource.js +119 -0
  25. package/vscode/src/vs/workbench/services/userDataProfile/browser/media/userDataProfileView.css.js +6 -0
  26. package/vscode/src/vs/workbench/services/userDataProfile/browser/settingsResource.js +140 -0
  27. package/vscode/src/vs/workbench/services/userDataProfile/browser/snippetsResource.js +155 -0
  28. package/vscode/src/vs/workbench/services/userDataProfile/browser/tasksResource.js +118 -0
  29. package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileImportExportService.js +1453 -0
  30. package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileInit.js +151 -0
  31. package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileManagement.js +180 -0
  32. package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileStorageService.js +39 -0
  33. package/vscode/src/vs/workbench/services/userDataSync/browser/userDataSyncInit.js +448 -0
@@ -0,0 +1,431 @@
1
+ import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
2
+ import { VSBuffer } from 'vscode/vscode/vs/base/common/buffer';
3
+ import { getErrorMessage } from 'vscode/vscode/vs/base/common/errors';
4
+ import { Event } from 'vscode/vscode/vs/base/common/event';
5
+ import { parse } from 'vscode/vscode/vs/base/common/json';
6
+ import { toFormattedString } from 'vscode/vscode/vs/base/common/jsonFormatter';
7
+ import { isWeb } from 'vscode/vscode/vs/base/common/platform';
8
+ import { generateUuid } from 'vscode/vscode/vs/base/common/uuid';
9
+ import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration.service';
10
+ import { IEnvironmentService } from 'vscode/vscode/vs/platform/environment/common/environment.service';
11
+ import { IFileService } from 'vscode/vscode/vs/platform/files/common/files.service';
12
+ import { ILogService } from 'vscode/vscode/vs/platform/log/common/log.service';
13
+ import { getServiceMachineId } from 'vscode/vscode/vs/platform/externalServices/common/serviceMachineId';
14
+ import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage.service';
15
+ import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry.service';
16
+ import { IUriIdentityService } from 'vscode/vscode/vs/platform/uriIdentity/common/uriIdentity.service';
17
+ import { AbstractSynchroniser, getSyncResourceLogLabel, AbstractInitializer, isSyncData } from 'vscode/vscode/vs/platform/userDataSync/common/abstractSynchronizer';
18
+ import { edit } from 'vscode/vscode/vs/platform/userDataSync/common/content';
19
+ import { merge } from './globalStateMerge.js';
20
+ import { USER_DATA_SYNC_SCHEME, ALL_SYNC_RESOURCES, getEnablementKey, SYNC_SERVICE_URL_TYPE, createSyncHeaders, UserDataSyncError } from 'vscode/vscode/vs/platform/userDataSync/common/userDataSync';
21
+ import { IUserDataSyncStoreService, IUserDataSyncLocalStoreService, IUserDataSyncLogService, IUserDataSyncEnablementService } from 'vscode/vscode/vs/platform/userDataSync/common/userDataSync.service';
22
+ import { IUserDataProfilesService } from 'vscode/vscode/vs/platform/userDataProfile/common/userDataProfile.service';
23
+ import { IUserDataProfileStorageService } from 'vscode/vscode/vs/platform/userDataProfile/common/userDataProfileStorageService.service';
24
+ import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
25
+
26
+ const argvStoragePrefx = 'globalState.argv.';
27
+ const argvProperties = ['locale'];
28
+ function stringify(globalState, format) {
29
+ const storageKeys = globalState.storage ? ( Object.keys(globalState.storage)).sort() : [];
30
+ const storage = {};
31
+ storageKeys.forEach(key => storage[key] = globalState.storage[key]);
32
+ globalState.storage = storage;
33
+ return format ? toFormattedString(globalState, {}) : JSON.stringify(globalState);
34
+ }
35
+ const GLOBAL_STATE_DATA_VERSION = 1;
36
+ let GlobalStateSynchroniser = class GlobalStateSynchroniser extends AbstractSynchroniser {
37
+ constructor(profile, collection, userDataProfileStorageService, fileService, userDataSyncStoreService, userDataSyncLocalStoreService, logService, environmentService, userDataSyncEnablementService, telemetryService, configurationService, storageService, uriIdentityService, instantiationService) {
38
+ super({ syncResource: "globalState" , profile }, collection, fileService, environmentService, storageService, userDataSyncStoreService, userDataSyncLocalStoreService, userDataSyncEnablementService, telemetryService, logService, configurationService, uriIdentityService);
39
+ this.userDataProfileStorageService = userDataProfileStorageService;
40
+ this.version = GLOBAL_STATE_DATA_VERSION;
41
+ this.previewResource = this.extUri.joinPath(this.syncPreviewFolder, 'globalState.json');
42
+ this.baseResource = this.previewResource.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' });
43
+ this.localResource = this.previewResource.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' });
44
+ this.remoteResource = this.previewResource.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' });
45
+ this.acceptedResource = this.previewResource.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' });
46
+ this.localGlobalStateProvider = instantiationService.createInstance(LocalGlobalStateProvider);
47
+ this._register(fileService.watch(this.extUri.dirname(this.environmentService.argvResource)));
48
+ this._register(Event.any(
49
+ Event.filter(fileService.onDidFilesChange, e => e.contains(this.environmentService.argvResource)), Event.filter(userDataProfileStorageService.onDidChange, e => {
50
+ if (( e.targetChanges.some(profile => this.syncResource.profile.id === profile.id))) {
51
+ return true;
52
+ }
53
+ if (( e.valueChanges.some(
54
+ ({ profile, changes }) => this.syncResource.profile.id === profile.id && ( changes.some(change => change.target === 0 ))
55
+ ))) {
56
+ return true;
57
+ }
58
+ return false;
59
+ }))((() => this.triggerLocalChange())));
60
+ }
61
+ async generateSyncPreview(remoteUserData, lastSyncUserData, isRemoteDataFromCurrentMachine) {
62
+ const remoteGlobalState = remoteUserData.syncData ? JSON.parse(remoteUserData.syncData.content) : null;
63
+ lastSyncUserData = lastSyncUserData === null && isRemoteDataFromCurrentMachine ? remoteUserData : lastSyncUserData;
64
+ const lastSyncGlobalState = lastSyncUserData && lastSyncUserData.syncData ? JSON.parse(lastSyncUserData.syncData.content) : null;
65
+ const localGlobalState = await this.localGlobalStateProvider.getLocalGlobalState(this.syncResource.profile);
66
+ if (remoteGlobalState) {
67
+ this.logService.trace(`${this.syncResourceLogLabel}: Merging remote ui state with local ui state...`);
68
+ }
69
+ else {
70
+ this.logService.trace(`${this.syncResourceLogLabel}: Remote ui state does not exist. Synchronizing ui state for the first time.`);
71
+ }
72
+ const storageKeys = await this.getStorageKeys(lastSyncGlobalState);
73
+ const { local, remote } = merge(localGlobalState.storage, remoteGlobalState ? remoteGlobalState.storage : null, lastSyncGlobalState ? lastSyncGlobalState.storage : null, storageKeys, this.logService);
74
+ const previewResult = {
75
+ content: null,
76
+ local,
77
+ remote,
78
+ localChange: ( Object.keys(local.added)).length > 0 || ( Object.keys(local.updated)).length > 0 || local.removed.length > 0 ? 2 : 0 ,
79
+ remoteChange: remote.all !== null ? 2 : 0 ,
80
+ };
81
+ const localContent = stringify(localGlobalState, false);
82
+ return [{
83
+ baseResource: this.baseResource,
84
+ baseContent: lastSyncGlobalState ? stringify(lastSyncGlobalState, false) : localContent,
85
+ localResource: this.localResource,
86
+ localContent,
87
+ localUserData: localGlobalState,
88
+ remoteResource: this.remoteResource,
89
+ remoteContent: remoteGlobalState ? stringify(remoteGlobalState, false) : null,
90
+ previewResource: this.previewResource,
91
+ previewResult,
92
+ localChange: previewResult.localChange,
93
+ remoteChange: previewResult.remoteChange,
94
+ acceptedResource: this.acceptedResource,
95
+ storageKeys
96
+ }];
97
+ }
98
+ async hasRemoteChanged(lastSyncUserData) {
99
+ const lastSyncGlobalState = lastSyncUserData.syncData ? JSON.parse(lastSyncUserData.syncData.content) : null;
100
+ if (lastSyncGlobalState === null) {
101
+ return true;
102
+ }
103
+ const localGlobalState = await this.localGlobalStateProvider.getLocalGlobalState(this.syncResource.profile);
104
+ const storageKeys = await this.getStorageKeys(lastSyncGlobalState);
105
+ const { remote } = merge(localGlobalState.storage, lastSyncGlobalState.storage, lastSyncGlobalState.storage, storageKeys, this.logService);
106
+ return remote.all !== null;
107
+ }
108
+ async getMergeResult(resourcePreview, token) {
109
+ return { ...resourcePreview.previewResult, hasConflicts: false };
110
+ }
111
+ async getAcceptResult(resourcePreview, resource, content, token) {
112
+ if (this.extUri.isEqual(resource, this.localResource)) {
113
+ return this.acceptLocal(resourcePreview);
114
+ }
115
+ if (this.extUri.isEqual(resource, this.remoteResource)) {
116
+ return this.acceptRemote(resourcePreview);
117
+ }
118
+ if (this.extUri.isEqual(resource, this.previewResource)) {
119
+ return resourcePreview.previewResult;
120
+ }
121
+ throw ( new Error(`Invalid Resource: ${( resource.toString())}`));
122
+ }
123
+ async acceptLocal(resourcePreview) {
124
+ return {
125
+ content: resourcePreview.localContent,
126
+ local: { added: {}, removed: [], updated: {} },
127
+ remote: { added: ( Object.keys(resourcePreview.localUserData.storage)), removed: [], updated: [], all: resourcePreview.localUserData.storage },
128
+ localChange: 0 ,
129
+ remoteChange: 2 ,
130
+ };
131
+ }
132
+ async acceptRemote(resourcePreview) {
133
+ if (resourcePreview.remoteContent !== null) {
134
+ const remoteGlobalState = JSON.parse(resourcePreview.remoteContent);
135
+ const { local, remote } = merge(resourcePreview.localUserData.storage, remoteGlobalState.storage, null, resourcePreview.storageKeys, this.logService);
136
+ return {
137
+ content: resourcePreview.remoteContent,
138
+ local,
139
+ remote,
140
+ localChange: ( Object.keys(local.added)).length > 0 || ( Object.keys(local.updated)).length > 0 || local.removed.length > 0 ? 2 : 0 ,
141
+ remoteChange: remote !== null ? 2 : 0 ,
142
+ };
143
+ }
144
+ else {
145
+ return {
146
+ content: resourcePreview.remoteContent,
147
+ local: { added: {}, removed: [], updated: {} },
148
+ remote: { added: [], removed: [], updated: [], all: null },
149
+ localChange: 0 ,
150
+ remoteChange: 0 ,
151
+ };
152
+ }
153
+ }
154
+ async applyResult(remoteUserData, lastSyncUserData, resourcePreviews, force) {
155
+ const { localUserData } = resourcePreviews[0][0];
156
+ const { local, remote, localChange, remoteChange } = resourcePreviews[0][1];
157
+ if (localChange === 0 && remoteChange === 0 ) {
158
+ this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing ui state.`);
159
+ }
160
+ if (localChange !== 0 ) {
161
+ this.logService.trace(`${this.syncResourceLogLabel}: Updating local ui state...`);
162
+ await this.backupLocal(JSON.stringify(localUserData));
163
+ await this.localGlobalStateProvider.writeLocalGlobalState(local, this.syncResource.profile);
164
+ this.logService.info(`${this.syncResourceLogLabel}: Updated local ui state`);
165
+ }
166
+ if (remoteChange !== 0 ) {
167
+ this.logService.trace(`${this.syncResourceLogLabel}: Updating remote ui state...`);
168
+ const content = JSON.stringify({ storage: remote.all });
169
+ remoteUserData = await this.updateRemoteUserData(content, force ? null : remoteUserData.ref);
170
+ this.logService.info(`${this.syncResourceLogLabel}: Updated remote ui state.${remote.added.length ? ` Added: ${remote.added}.` : ''}${remote.updated.length ? ` Updated: ${remote.updated}.` : ''}${remote.removed.length ? ` Removed: ${remote.removed}.` : ''}`);
171
+ }
172
+ if (lastSyncUserData?.ref !== remoteUserData.ref) {
173
+ this.logService.trace(`${this.syncResourceLogLabel}: Updating last synchronized ui state...`);
174
+ await this.updateLastSyncUserData(remoteUserData);
175
+ this.logService.info(`${this.syncResourceLogLabel}: Updated last synchronized ui state`);
176
+ }
177
+ }
178
+ async resolveContent(uri) {
179
+ if (this.extUri.isEqual(this.remoteResource, uri)
180
+ || this.extUri.isEqual(this.baseResource, uri)
181
+ || this.extUri.isEqual(this.localResource, uri)
182
+ || this.extUri.isEqual(this.acceptedResource, uri)) {
183
+ const content = await this.resolvePreviewContent(uri);
184
+ return content ? stringify(JSON.parse(content), true) : content;
185
+ }
186
+ return null;
187
+ }
188
+ async hasLocalData() {
189
+ try {
190
+ const { storage } = await this.localGlobalStateProvider.getLocalGlobalState(this.syncResource.profile);
191
+ if (( Object.keys(storage)).length > 1 || storage[`${argvStoragePrefx}.locale`]?.value !== 'en') {
192
+ return true;
193
+ }
194
+ }
195
+ catch (error) {
196
+ }
197
+ return false;
198
+ }
199
+ async getStorageKeys(lastSyncGlobalState) {
200
+ const storageData = await this.userDataProfileStorageService.readStorageData(this.syncResource.profile);
201
+ const user = [], machine = [];
202
+ for (const [key, value] of storageData) {
203
+ if (value.target === 0 ) {
204
+ user.push(key);
205
+ }
206
+ else if (value.target === 1 ) {
207
+ machine.push(key);
208
+ }
209
+ }
210
+ const registered = [...user, ...machine];
211
+ const unregistered = lastSyncGlobalState?.storage ? ( Object.keys(lastSyncGlobalState.storage)).filter(key => !key.startsWith(argvStoragePrefx) && !registered.includes(key) && storageData.get(key) !== undefined) : [];
212
+ if (!isWeb) {
213
+ const keysSyncedOnlyInWeb = [...( ALL_SYNC_RESOURCES.map(resource => getEnablementKey(resource))), SYNC_SERVICE_URL_TYPE];
214
+ unregistered.push(...keysSyncedOnlyInWeb);
215
+ machine.push(...keysSyncedOnlyInWeb);
216
+ }
217
+ return { user, machine, unregistered };
218
+ }
219
+ };
220
+ GlobalStateSynchroniser = ( __decorate([
221
+ ( __param(2, IUserDataProfileStorageService)),
222
+ ( __param(3, IFileService)),
223
+ ( __param(4, IUserDataSyncStoreService)),
224
+ ( __param(5, IUserDataSyncLocalStoreService)),
225
+ ( __param(6, IUserDataSyncLogService)),
226
+ ( __param(7, IEnvironmentService)),
227
+ ( __param(8, IUserDataSyncEnablementService)),
228
+ ( __param(9, ITelemetryService)),
229
+ ( __param(10, IConfigurationService)),
230
+ ( __param(11, IStorageService)),
231
+ ( __param(12, IUriIdentityService)),
232
+ ( __param(13, IInstantiationService))
233
+ ], GlobalStateSynchroniser));
234
+ let LocalGlobalStateProvider = class LocalGlobalStateProvider {
235
+ constructor(fileService, environmentService, userDataProfileStorageService, logService) {
236
+ this.fileService = fileService;
237
+ this.environmentService = environmentService;
238
+ this.userDataProfileStorageService = userDataProfileStorageService;
239
+ this.logService = logService;
240
+ }
241
+ async getLocalGlobalState(profile) {
242
+ const storage = {};
243
+ if (profile.isDefault) {
244
+ const argvContent = await this.getLocalArgvContent();
245
+ const argvValue = parse(argvContent);
246
+ for (const argvProperty of argvProperties) {
247
+ if (argvValue[argvProperty] !== undefined) {
248
+ storage[`${argvStoragePrefx}${argvProperty}`] = { version: 1, value: argvValue[argvProperty] };
249
+ }
250
+ }
251
+ }
252
+ const storageData = await this.userDataProfileStorageService.readStorageData(profile);
253
+ for (const [key, value] of storageData) {
254
+ if (value.value && value.target === 0 ) {
255
+ storage[key] = { version: 1, value: value.value };
256
+ }
257
+ }
258
+ return { storage };
259
+ }
260
+ async getLocalArgvContent() {
261
+ try {
262
+ this.logService.debug('GlobalStateSync#getLocalArgvContent', this.environmentService.argvResource);
263
+ const content = await this.fileService.readFile(this.environmentService.argvResource);
264
+ this.logService.debug('GlobalStateSync#getLocalArgvContent - Resolved', this.environmentService.argvResource);
265
+ return ( content.value.toString());
266
+ }
267
+ catch (error) {
268
+ this.logService.debug(getErrorMessage(error));
269
+ }
270
+ return '{}';
271
+ }
272
+ async writeLocalGlobalState({ added, removed, updated }, profile) {
273
+ const syncResourceLogLabel = getSyncResourceLogLabel("globalState" , profile);
274
+ const argv = {};
275
+ const updatedStorage = ( new Map());
276
+ const storageData = await this.userDataProfileStorageService.readStorageData(profile);
277
+ const handleUpdatedStorage = (keys, storage) => {
278
+ for (const key of keys) {
279
+ if (key.startsWith(argvStoragePrefx)) {
280
+ argv[key.substring(argvStoragePrefx.length)] = storage ? storage[key].value : undefined;
281
+ continue;
282
+ }
283
+ if (storage) {
284
+ const storageValue = storage[key];
285
+ if (storageValue.value !== storageData.get(key)?.value) {
286
+ updatedStorage.set(key, storageValue.value);
287
+ }
288
+ }
289
+ else {
290
+ if (storageData.get(key) !== undefined) {
291
+ updatedStorage.set(key, undefined);
292
+ }
293
+ }
294
+ }
295
+ };
296
+ handleUpdatedStorage(( Object.keys(added)), added);
297
+ handleUpdatedStorage(( Object.keys(updated)), updated);
298
+ handleUpdatedStorage(removed);
299
+ if (( Object.keys(argv)).length) {
300
+ this.logService.trace(`${syncResourceLogLabel}: Updating locale...`);
301
+ const argvContent = await this.getLocalArgvContent();
302
+ let content = argvContent;
303
+ for (const argvProperty of ( Object.keys(argv))) {
304
+ content = edit(content, [argvProperty], argv[argvProperty], {});
305
+ }
306
+ if (argvContent !== content) {
307
+ this.logService.trace(`${syncResourceLogLabel}: Updating locale...`);
308
+ await this.fileService.writeFile(this.environmentService.argvResource, VSBuffer.fromString(content));
309
+ this.logService.info(`${syncResourceLogLabel}: Updated locale.`);
310
+ }
311
+ this.logService.info(`${syncResourceLogLabel}: Updated locale`);
312
+ }
313
+ if (updatedStorage.size) {
314
+ this.logService.trace(`${syncResourceLogLabel}: Updating global state...`);
315
+ await this.userDataProfileStorageService.updateStorageData(profile, updatedStorage, 0 );
316
+ this.logService.info(`${syncResourceLogLabel}: Updated global state`, [...( updatedStorage.keys())]);
317
+ }
318
+ }
319
+ };
320
+ LocalGlobalStateProvider = ( __decorate([
321
+ ( __param(0, IFileService)),
322
+ ( __param(1, IEnvironmentService)),
323
+ ( __param(2, IUserDataProfileStorageService)),
324
+ ( __param(3, IUserDataSyncLogService))
325
+ ], LocalGlobalStateProvider));
326
+ let GlobalStateInitializer = class GlobalStateInitializer extends AbstractInitializer {
327
+ constructor(storageService, fileService, userDataProfilesService, environmentService, logService, uriIdentityService) {
328
+ super("globalState" , userDataProfilesService, environmentService, logService, fileService, storageService, uriIdentityService);
329
+ }
330
+ async doInitialize(remoteUserData) {
331
+ const remoteGlobalState = remoteUserData.syncData ? JSON.parse(remoteUserData.syncData.content) : null;
332
+ if (!remoteGlobalState) {
333
+ this.logService.info('Skipping initializing global state because remote global state does not exist.');
334
+ return;
335
+ }
336
+ const argv = {};
337
+ const storage = {};
338
+ for (const key of ( Object.keys(remoteGlobalState.storage))) {
339
+ if (key.startsWith(argvStoragePrefx)) {
340
+ argv[key.substring(argvStoragePrefx.length)] = remoteGlobalState.storage[key].value;
341
+ }
342
+ else {
343
+ if (this.storageService.get(key, 0 ) === undefined) {
344
+ storage[key] = remoteGlobalState.storage[key].value;
345
+ }
346
+ }
347
+ }
348
+ if (( Object.keys(argv)).length) {
349
+ let content = '{}';
350
+ try {
351
+ const fileContent = await this.fileService.readFile(this.environmentService.argvResource);
352
+ content = ( fileContent.value.toString());
353
+ }
354
+ catch (error) { }
355
+ for (const argvProperty of ( Object.keys(argv))) {
356
+ content = edit(content, [argvProperty], argv[argvProperty], {});
357
+ }
358
+ await this.fileService.writeFile(this.environmentService.argvResource, VSBuffer.fromString(content));
359
+ }
360
+ if (( Object.keys(storage)).length) {
361
+ const storageEntries = [];
362
+ for (const key of ( Object.keys(storage))) {
363
+ storageEntries.push({ key, value: storage[key], scope: 0 , target: 0 });
364
+ }
365
+ this.storageService.storeAll(storageEntries, true);
366
+ }
367
+ }
368
+ };
369
+ GlobalStateInitializer = ( __decorate([
370
+ ( __param(0, IStorageService)),
371
+ ( __param(1, IFileService)),
372
+ ( __param(2, IUserDataProfilesService)),
373
+ ( __param(3, IEnvironmentService)),
374
+ ( __param(4, IUserDataSyncLogService)),
375
+ ( __param(5, IUriIdentityService))
376
+ ], GlobalStateInitializer));
377
+ let UserDataSyncStoreTypeSynchronizer = class UserDataSyncStoreTypeSynchronizer {
378
+ constructor(userDataSyncStoreClient, storageService, environmentService, fileService, logService) {
379
+ this.userDataSyncStoreClient = userDataSyncStoreClient;
380
+ this.storageService = storageService;
381
+ this.environmentService = environmentService;
382
+ this.fileService = fileService;
383
+ this.logService = logService;
384
+ }
385
+ getSyncStoreType(userData) {
386
+ const remoteGlobalState = this.parseGlobalState(userData);
387
+ return remoteGlobalState?.storage[SYNC_SERVICE_URL_TYPE]?.value;
388
+ }
389
+ async sync(userDataSyncStoreType) {
390
+ const syncHeaders = createSyncHeaders(generateUuid());
391
+ try {
392
+ return await this.doSync(userDataSyncStoreType, syncHeaders);
393
+ }
394
+ catch (e) {
395
+ if (e instanceof UserDataSyncError) {
396
+ switch (e.code) {
397
+ case "PreconditionFailed" :
398
+ this.logService.info(`Failed to synchronize UserDataSyncStoreType as there is a new remote version available. Synchronizing again...`);
399
+ return this.doSync(userDataSyncStoreType, syncHeaders);
400
+ }
401
+ }
402
+ throw e;
403
+ }
404
+ }
405
+ async doSync(userDataSyncStoreType, syncHeaders) {
406
+ const globalStateUserData = await this.userDataSyncStoreClient.readResource("globalState" , null, undefined, syncHeaders);
407
+ const remoteGlobalState = this.parseGlobalState(globalStateUserData) || { storage: {} };
408
+ remoteGlobalState.storage[SYNC_SERVICE_URL_TYPE] = { value: userDataSyncStoreType, version: GLOBAL_STATE_DATA_VERSION };
409
+ const machineId = await getServiceMachineId(this.environmentService, this.fileService, this.storageService);
410
+ const syncDataToUpdate = { version: GLOBAL_STATE_DATA_VERSION, machineId, content: stringify(remoteGlobalState, false) };
411
+ await this.userDataSyncStoreClient.writeResource("globalState" , JSON.stringify(syncDataToUpdate), globalStateUserData.ref, undefined, syncHeaders);
412
+ }
413
+ parseGlobalState({ content }) {
414
+ if (!content) {
415
+ return null;
416
+ }
417
+ const syncData = JSON.parse(content);
418
+ if (isSyncData(syncData)) {
419
+ return syncData ? JSON.parse(syncData.content) : null;
420
+ }
421
+ throw ( new Error('Invalid remote data'));
422
+ }
423
+ };
424
+ UserDataSyncStoreTypeSynchronizer = ( __decorate([
425
+ ( __param(1, IStorageService)),
426
+ ( __param(2, IEnvironmentService)),
427
+ ( __param(3, IFileService)),
428
+ ( __param(4, ILogService))
429
+ ], UserDataSyncStoreTypeSynchronizer));
430
+
431
+ export { GlobalStateInitializer, GlobalStateSynchroniser, LocalGlobalStateProvider, UserDataSyncStoreTypeSynchronizer, stringify };