Skip to content

Commit

Permalink
Add typing to localData object (#3368)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliykat authored Sep 1, 2022
1 parent e2cb0cf commit 063acfe
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
8 changes: 6 additions & 2 deletions libs/common/src/abstractions/state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CollectionData } from "../models/data/collectionData";
import { EncryptedOrganizationKeyData } from "../models/data/encryptedOrganizationKeyData";
import { EventData } from "../models/data/eventData";
import { FolderData } from "../models/data/folderData";
import { LocalData } from "../models/data/localData";
import { OrganizationData } from "../models/data/organizationData";
import { PolicyData } from "../models/data/policyData";
import { ProviderData } from "../models/data/providerData";
Expand Down Expand Up @@ -245,8 +246,11 @@ export abstract class StateService<T extends Account = Account> {
setLastActive: (value: number, options?: StorageOptions) => Promise<void>;
getLastSync: (options?: StorageOptions) => Promise<string>;
setLastSync: (value: string, options?: StorageOptions) => Promise<void>;
getLocalData: (options?: StorageOptions) => Promise<any>;
setLocalData: (value: string, options?: StorageOptions) => Promise<void>;
getLocalData: (options?: StorageOptions) => Promise<{ [cipherId: string]: LocalData }>;
setLocalData: (
value: { [cipherId: string]: LocalData },
options?: StorageOptions
) => Promise<void>;
getLocale: (options?: StorageOptions) => Promise<string>;
setLocale: (value: string, options?: StorageOptions) => Promise<void>;
getMainWindowSize: (options?: StorageOptions) => Promise<number>;
Expand Down
4 changes: 4 additions & 0 deletions libs/common/src/models/data/localData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type LocalData = {
lastUsedDate?: number;
lastLaunched?: number;
};
5 changes: 3 additions & 2 deletions libs/common/src/models/domain/cipher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CipherRepromptType } from "../../enums/cipherRepromptType";
import { CipherType } from "../../enums/cipherType";
import { CipherData } from "../data/cipherData";
import { LocalData } from "../data/localData";
import { CipherView } from "../view/cipherView";

import { Attachment } from "./attachment";
Expand All @@ -26,7 +27,7 @@ export class Cipher extends Domain {
edit: boolean;
viewPassword: boolean;
revisionDate: Date;
localData: any;
localData: LocalData;
login: Login;
identity: Identity;
card: Card;
Expand All @@ -38,7 +39,7 @@ export class Cipher extends Domain {
deletedDate: Date;
reprompt: CipherRepromptType;

constructor(obj?: CipherData, localData: any = null) {
constructor(obj?: CipherData, localData: LocalData = null) {
super();
if (obj == null) {
return;
Expand Down
3 changes: 2 additions & 1 deletion libs/common/src/models/view/cipherView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Jsonify } from "type-fest";
import { CipherRepromptType } from "../../enums/cipherRepromptType";
import { CipherType } from "../../enums/cipherType";
import { LinkedIdType } from "../../enums/linkedIdType";
import { LocalData } from "../data/localData";
import { Cipher } from "../domain/cipher";

import { AttachmentView } from "./attachmentView";
Expand All @@ -25,7 +26,7 @@ export class CipherView implements View {
organizationUseTotp = false;
edit = false;
viewPassword = true;
localData: any;
localData: LocalData;
login = new LoginView();
identity = new IdentityView();
card = new CardView();
Expand Down
9 changes: 7 additions & 2 deletions libs/common/src/services/state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { CollectionData } from "../models/data/collectionData";
import { EncryptedOrganizationKeyData } from "../models/data/encryptedOrganizationKeyData";
import { EventData } from "../models/data/eventData";
import { FolderData } from "../models/data/folderData";
import { LocalData } from "../models/data/localData";
import { OrganizationData } from "../models/data/organizationData";
import { PolicyData } from "../models/data/policyData";
import { ProviderData } from "../models/data/providerData";
Expand Down Expand Up @@ -1747,12 +1748,16 @@ export class StateService<
);
}

async getLocalData(options?: StorageOptions): Promise<any> {
async getLocalData(options?: StorageOptions): Promise<{ [cipherId: string]: LocalData }> {
return (
await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()))
)?.data?.localData;
}
async setLocalData(value: string, options?: StorageOptions): Promise<void> {

async setLocalData(
value: { [cipherId: string]: LocalData },
options?: StorageOptions
): Promise<void> {
const account = await this.getAccount(
this.reconcileOptions(options, await this.defaultOnDiskLocalOptions())
);
Expand Down

0 comments on commit 063acfe

Please sign in to comment.