mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 17:23:02 -05:00
Add more to strict nulls (#11871)
* add more to strict nulls * maintain error handling properly * fix lint
This commit is contained in:
@@ -16,7 +16,7 @@ export default class AccountStore implements IAccountStore {
|
||||
public static MEMENTO_KEY: string = 'Microsoft.SqlTools.Accounts';
|
||||
|
||||
// MEMBER VARIABLES ////////////////////////////////////////////////////
|
||||
private _activeOperation?: Thenable<any>;
|
||||
private _activeOperation?: Promise<any>;
|
||||
|
||||
constructor(
|
||||
private _memento: { [key: string]: any },
|
||||
@@ -24,7 +24,7 @@ export default class AccountStore implements IAccountStore {
|
||||
) { }
|
||||
|
||||
// PUBLIC METHODS //////////////////////////////////////////////////////
|
||||
public addOrUpdate(newAccount: azdata.Account): Thenable<AccountAdditionResult> {
|
||||
public addOrUpdate(newAccount: azdata.Account): Promise<AccountAdditionResult> {
|
||||
return this.doOperation(() => {
|
||||
return this.readFromMemento()
|
||||
.then(accounts => {
|
||||
@@ -35,18 +35,18 @@ export default class AccountStore implements IAccountStore {
|
||||
: this.updateAccountList(accounts, newAccount.key, matchAccount => AccountStore.mergeAccounts(newAccount, matchAccount));
|
||||
})
|
||||
.then(result => this.writeToMemento(result.updatedAccounts).then(() => result))
|
||||
.then(result => <AccountAdditionResult>result);
|
||||
.then(result => ({ accountAdded: result.accountAdded, accountModified: result.accountModified, changedAccount: result.changedAccount! }));
|
||||
});
|
||||
}
|
||||
|
||||
public getAccountsByProvider(providerId: string): Thenable<azdata.Account[]> {
|
||||
public getAccountsByProvider(providerId: string): Promise<azdata.Account[]> {
|
||||
return this.doOperation(() => {
|
||||
return this.readFromMemento()
|
||||
.then(accounts => accounts.filter(account => account.key.providerId === providerId));
|
||||
});
|
||||
}
|
||||
|
||||
public getAllAccounts(): Thenable<azdata.Account[]> {
|
||||
public getAllAccounts(): Promise<azdata.Account[]> {
|
||||
return this.doOperation(() => {
|
||||
return this.cleanupDeprecatedAccounts().then(() => {
|
||||
return this.readFromMemento();
|
||||
@@ -54,7 +54,7 @@ export default class AccountStore implements IAccountStore {
|
||||
});
|
||||
}
|
||||
|
||||
public cleanupDeprecatedAccounts(): Thenable<void> {
|
||||
public cleanupDeprecatedAccounts(): Promise<void> {
|
||||
return this.readFromMemento()
|
||||
.then(accounts => {
|
||||
// No need to waste cycles
|
||||
@@ -80,7 +80,7 @@ export default class AccountStore implements IAccountStore {
|
||||
});
|
||||
}
|
||||
|
||||
public remove(key: azdata.AccountKey): Thenable<boolean> {
|
||||
public remove(key: azdata.AccountKey): Promise<boolean> {
|
||||
return this.doOperation(() => {
|
||||
return this.readFromMemento()
|
||||
.then(accounts => this.removeFromAccountList(accounts, key))
|
||||
@@ -89,7 +89,7 @@ export default class AccountStore implements IAccountStore {
|
||||
});
|
||||
}
|
||||
|
||||
public update(key: azdata.AccountKey, updateOperation: (account: azdata.Account) => void): Thenable<boolean> {
|
||||
public update(key: azdata.AccountKey, updateOperation: (account: azdata.Account) => void): Promise<boolean> {
|
||||
return this.doOperation(() => {
|
||||
return this.readFromMemento()
|
||||
.then(accounts => this.updateAccountList(accounts, key, updateOperation))
|
||||
@@ -115,7 +115,7 @@ export default class AccountStore implements IAccountStore {
|
||||
target.isStale = source.isStale;
|
||||
}
|
||||
|
||||
private doOperation<T>(op: () => Thenable<T>) {
|
||||
private doOperation<T>(op: () => Promise<T>) {
|
||||
// Initialize the active operation to an empty promise if necessary
|
||||
let activeOperation = this._activeOperation || Promise.resolve<any>(null);
|
||||
|
||||
@@ -201,7 +201,7 @@ export default class AccountStore implements IAccountStore {
|
||||
}
|
||||
|
||||
// MEMENTO IO METHODS //////////////////////////////////////////////////
|
||||
private readFromMemento(): Thenable<azdata.Account[]> {
|
||||
private readFromMemento(): Promise<azdata.Account[]> {
|
||||
// Initialize the account list if it isn't already
|
||||
let accounts = this._memento[AccountStore.MEMENTO_KEY];
|
||||
if (!accounts) {
|
||||
@@ -214,14 +214,17 @@ export default class AccountStore implements IAccountStore {
|
||||
return Promise.resolve(accounts);
|
||||
}
|
||||
|
||||
private writeToMemento(accounts: azdata.Account[]): Thenable<void> {
|
||||
private writeToMemento(accounts: azdata.Account[]): Promise<void> {
|
||||
// Store a shallow copy of the account list to disconnect the memento list from the active list
|
||||
this._memento[AccountStore.MEMENTO_KEY] = deepClone(accounts);
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
interface AccountListOperationResult extends AccountAdditionResult {
|
||||
interface AccountListOperationResult {
|
||||
accountRemoved: boolean;
|
||||
updatedAccounts: azdata.Account[];
|
||||
changedAccount: azdata.Account | undefined;
|
||||
accountAdded: boolean;
|
||||
accountModified: boolean;
|
||||
}
|
||||
|
||||
@@ -41,27 +41,24 @@ export class AccountViewModel {
|
||||
* and fires an event after each provider/accounts has been loaded.
|
||||
*
|
||||
*/
|
||||
public initialize(): Thenable<AccountProviderAddedEventParams[]> {
|
||||
public initialize(): Promise<AccountProviderAddedEventParams[]> {
|
||||
// Load a baseline of the account provider metadata and accounts
|
||||
// 1) Get all the providers from the account management service
|
||||
// 2) For each provider, get the accounts
|
||||
// 3) Build parameters to add a provider and return it
|
||||
return this._accountManagementService.getAccountProviderMetadata()
|
||||
.then(
|
||||
(providers: azdata.AccountProviderMetadata[]) => {
|
||||
const promises = providers.map(provider => {
|
||||
return this._accountManagementService.getAccountsForProvider(provider.id)
|
||||
.then(
|
||||
accounts => <AccountProviderAddedEventParams>{
|
||||
addedProvider: provider,
|
||||
initialAccounts: accounts
|
||||
},
|
||||
() => { /* Swallow failures at getting accounts, we'll just hide that provider */ });
|
||||
});
|
||||
return Promise.all(promises).then(accounts => coalesce(accounts));
|
||||
}, () => {
|
||||
/* Swallow failures and just pretend we don't have any providers */
|
||||
return [];
|
||||
.then(providers => {
|
||||
const promises = providers.map(provider => {
|
||||
return this._accountManagementService.getAccountsForProvider(provider.id)
|
||||
.then(accounts => <AccountProviderAddedEventParams>{
|
||||
addedProvider: provider,
|
||||
initialAccounts: accounts
|
||||
}, () => undefined);
|
||||
});
|
||||
return Promise.all(promises).then(accounts => coalesce(accounts));
|
||||
}, () => {
|
||||
/* Swallow failures and just pretend we don't have any providers */
|
||||
return [];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export interface AccountAdditionResult {
|
||||
/**
|
||||
* The account that was added/updated (with any updates applied)
|
||||
*/
|
||||
changedAccount: azdata.Account | undefined;
|
||||
changedAccount: azdata.Account;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,23 +16,23 @@ export interface IAccountManagementService {
|
||||
_serviceBrand: undefined;
|
||||
|
||||
// ACCOUNT MANAGEMENT METHODS //////////////////////////////////////////
|
||||
accountUpdated(account: azdata.Account): Thenable<void>;
|
||||
addAccount(providerId: string): Thenable<void>;
|
||||
getAccountProviderMetadata(): Thenable<azdata.AccountProviderMetadata[]>;
|
||||
getAccountsForProvider(providerId: string): Thenable<azdata.Account[]>;
|
||||
getAccounts(): Thenable<azdata.Account[]>;
|
||||
accountUpdated(account: azdata.Account): Promise<void>;
|
||||
addAccount(providerId: string): Promise<void>;
|
||||
getAccountProviderMetadata(): Promise<azdata.AccountProviderMetadata[]>;
|
||||
getAccountsForProvider(providerId: string): Promise<azdata.Account[]>;
|
||||
getAccounts(): Promise<azdata.Account[]>;
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Thenable<{ [key: string]: { token: string } }>;
|
||||
getAccountSecurityToken(account: azdata.Account, tenant: string, resource: azdata.AzureResource): Thenable<{ token: string }>;
|
||||
removeAccount(accountKey: azdata.AccountKey): Thenable<boolean>;
|
||||
removeAccounts(): Thenable<boolean>;
|
||||
refreshAccount(account: azdata.Account): Thenable<azdata.Account>;
|
||||
getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Promise<{ [key: string]: { token: string } } | undefined>;
|
||||
getAccountSecurityToken(account: azdata.Account, tenant: string, resource: azdata.AzureResource): Promise<{ token: string } | undefined>;
|
||||
removeAccount(accountKey: azdata.AccountKey): Promise<boolean>;
|
||||
removeAccounts(): Promise<boolean>;
|
||||
refreshAccount(account: azdata.Account): Promise<azdata.Account>;
|
||||
|
||||
// UI METHODS //////////////////////////////////////////////////////////
|
||||
openAccountListDialog(): Thenable<void>;
|
||||
beginAutoOAuthDeviceCode(providerId: string, title: string, message: string, userCode: string, uri: string): Thenable<void>;
|
||||
openAccountListDialog(): Promise<void>;
|
||||
beginAutoOAuthDeviceCode(providerId: string, title: string, message: string, userCode: string, uri: string): Promise<void>;
|
||||
endAutoOAuthDeviceCode(): void;
|
||||
cancelAutoOAuthDeviceCode(providerId: string): void;
|
||||
copyUserCodeAndOpenBrowser(userCode: string, uri: string): void;
|
||||
@@ -61,20 +61,20 @@ export interface IAccountStore {
|
||||
* @param account Account to add/update
|
||||
* @return Results of the add/update operation
|
||||
*/
|
||||
addOrUpdate(account: azdata.Account): Thenable<AccountAdditionResult>;
|
||||
addOrUpdate(account: azdata.Account): Promise<AccountAdditionResult>;
|
||||
|
||||
/**
|
||||
* Retrieves all accounts, filtered by provider ID
|
||||
* @param providerId ID of the provider to filter by
|
||||
* @return Promise to return all accounts that belong to the provided provider
|
||||
*/
|
||||
getAccountsByProvider(providerId: string): Thenable<azdata.Account[]>;
|
||||
getAccountsByProvider(providerId: string): Promise<azdata.Account[]>;
|
||||
|
||||
/**
|
||||
* Retrieves all accounts in the store. Returns empty array if store is not initialized
|
||||
* @return Promise to return all accounts
|
||||
*/
|
||||
getAllAccounts(): Thenable<azdata.Account[]>;
|
||||
getAllAccounts(): Promise<azdata.Account[]>;
|
||||
|
||||
/**
|
||||
* Removes an account.
|
||||
@@ -83,7 +83,7 @@ export interface IAccountStore {
|
||||
* @param key - The key of an account.
|
||||
* @returns True if the account was removed, false if the account doesn't exist
|
||||
*/
|
||||
remove(key: azdata.AccountKey): Thenable<boolean>;
|
||||
remove(key: azdata.AccountKey): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Updates the custom properties stored with an account.
|
||||
@@ -93,5 +93,5 @@ export interface IAccountStore {
|
||||
* @param updateOperation - Operation to perform on the matching account
|
||||
* @returns True if the account was modified, false if the account doesn't exist
|
||||
*/
|
||||
update(key: azdata.AccountKey, updateOperation: (account: azdata.Account) => void): Thenable<boolean>;
|
||||
update(key: azdata.AccountKey, updateOperation: (account: azdata.Account) => void): Promise<boolean>;
|
||||
}
|
||||
|
||||
@@ -15,15 +15,15 @@ export class TestAccountManagementService implements IAccountManagementService {
|
||||
public get removeAccountProviderEvent(): Event<azdata.AccountProviderMetadata> { return Event.None; }
|
||||
public get updateAccountListEvent(): Event<UpdateAccountListEventParams> { return Event.None; }
|
||||
|
||||
accountUpdated(account: azdata.Account): Thenable<void> {
|
||||
accountUpdated(account: azdata.Account): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
addAccount(providerId: string): Thenable<void> {
|
||||
addAccount(providerId: string): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
beginAutoOAuthDeviceCode(title: string, message: string, userCode: string, uri: string): Thenable<void> {
|
||||
beginAutoOAuthDeviceCode(title: string, message: string, userCode: string, uri: string): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
@@ -39,35 +39,35 @@ export class TestAccountManagementService implements IAccountManagementService {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getAccountProviderMetadata(): Thenable<azdata.AccountProviderMetadata[]> {
|
||||
getAccountProviderMetadata(): Promise<azdata.AccountProviderMetadata[]> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
getAccounts(): Thenable<azdata.Account[]> {
|
||||
getAccounts(): Promise<azdata.Account[]> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
getAccountsForProvider(providerId: string): Thenable<azdata.Account[]> {
|
||||
getAccountsForProvider(providerId: string): Promise<azdata.Account[]> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Thenable<{}> {
|
||||
getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Promise<{}> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
getAccountSecurityToken(account: azdata.Account, tenant: string, resource: azdata.AzureResource): Thenable<{ token: string }> {
|
||||
getAccountSecurityToken(account: azdata.Account, tenant: string, resource: azdata.AzureResource): Promise<{ token: string }> {
|
||||
return Promise.resolve(undefined!);
|
||||
}
|
||||
|
||||
removeAccount(accountKey: azdata.AccountKey): Thenable<boolean> {
|
||||
removeAccount(accountKey: azdata.AccountKey): Promise<boolean> {
|
||||
throw new Error('Method not implemented');
|
||||
}
|
||||
|
||||
removeAccounts(): Thenable<boolean> {
|
||||
removeAccounts(): Promise<boolean> {
|
||||
throw new Error('Method not implemented');
|
||||
}
|
||||
|
||||
refreshAccount(account: azdata.Account): Thenable<azdata.Account> {
|
||||
refreshAccount(account: azdata.Account): Promise<azdata.Account> {
|
||||
throw new Error('Method not implemented');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user