-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ps 1291/apply to from json pattern to state (#3425)
* Clean up dangling behaviorSubject * Handle null in utils * fix null check * Await promises, even in async functions * Add to/fromJSON methods to State and Accounts This is needed since all storage in manifest v3 is key-value-pair-based and session storage of most data is actually serialized into an encrypted string. * Simplify AccountKeys json parsing * Fix account key (de)serialization * Remove unused DecodedToken state * Correct filename typo * Simplify keys `toJSON` tests * Explain AccountKeys `toJSON` return type * Remove unnecessary `any`s * Remove unique ArrayBuffer serialization * Initialize items in MemoryStorageService * Revert "Fix account key (de)serialization" This reverts commit b1dffb5, which was breaking serializations * Move fromJSON to owning object * Add DeepJsonify type * Use Records for storage * Add new Account Settings to serialized data * Fix failing serialization tests * Extract complex type conversion to helper methods * Remove unnecessary decorator * Return null from json deserializers * Remove unnecessary decorators * Remove obsolete test * Use type-fest `Jsonify` formatting rules for external library * Update jsonify comment Co-authored-by: @eliykat * Remove erroneous comment * Fix unintended deep-jsonify changes * Fix prettierignore * Fix formatting of deep-jsonify.ts Co-authored-by: Thomas Rittson <trittson@bitwarden.com> Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>
- Loading branch information
1 parent
0c815bf
commit b6cd011
Showing
37 changed files
with
635 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,6 @@ libs/.github | |
|
||
# Github Workflows | ||
.github/workflows | ||
|
||
# Forked library files | ||
libs/common/src/types/deep-jsonify.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 18 additions & 38 deletions
56
apps/browser/src/decorators/session-sync-observable/synced-item-metadata.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,39 @@ | ||
import { SyncedItemMetadata } from "./sync-item-metadata"; | ||
|
||
describe("build from key value pair", () => { | ||
describe("builder", () => { | ||
const propertyKey = "propertyKey"; | ||
const key = "key"; | ||
const initializer = (s: any) => "used initializer"; | ||
class TestClass {} | ||
const ctor = TestClass; | ||
|
||
it("should call initializer if provided", () => { | ||
const actual = SyncedItemMetadata.buildFromKeyValuePair( | ||
{}, | ||
{ | ||
propertyKey, | ||
sessionKey: "key", | ||
initializer: initializer, | ||
} | ||
); | ||
|
||
expect(actual).toEqual("used initializer"); | ||
it("should use initializer if provided", () => { | ||
const metadata = { propertyKey, sessionKey: key, initializer }; | ||
const builder = SyncedItemMetadata.builder(metadata); | ||
expect(builder({})).toBe("used initializer"); | ||
}); | ||
|
||
it("should call ctor if provided", () => { | ||
const expected = { provided: "value" }; | ||
const actual = SyncedItemMetadata.buildFromKeyValuePair(expected, { | ||
propertyKey, | ||
sessionKey: key, | ||
ctor: ctor, | ||
}); | ||
|
||
expect(actual).toBeInstanceOf(ctor); | ||
expect(actual).toEqual(expect.objectContaining(expected)); | ||
it("should use ctor if initializer is not provided", () => { | ||
const metadata = { propertyKey, sessionKey: key, ctor }; | ||
const builder = SyncedItemMetadata.builder(metadata); | ||
expect(builder({})).toBeInstanceOf(TestClass); | ||
}); | ||
|
||
it("should prefer using initializer if both are provided", () => { | ||
const actual = SyncedItemMetadata.buildFromKeyValuePair( | ||
{}, | ||
{ | ||
propertyKey, | ||
sessionKey: key, | ||
initializer: initializer, | ||
ctor: ctor, | ||
} | ||
); | ||
|
||
expect(actual).toEqual("used initializer"); | ||
it("should prefer initializer over ctor", () => { | ||
const metadata = { propertyKey, sessionKey: key, ctor, initializer }; | ||
const builder = SyncedItemMetadata.builder(metadata); | ||
expect(builder({})).toBe("used initializer"); | ||
}); | ||
|
||
it("should honor initialize as array", () => { | ||
const actual = SyncedItemMetadata.buildFromKeyValuePair([1, 2], { | ||
const metadata = { | ||
propertyKey, | ||
sessionKey: key, | ||
initializer: initializer, | ||
initializeAsArray: true, | ||
}); | ||
|
||
expect(actual).toEqual(["used initializer", "used initializer"]); | ||
}; | ||
const builder = SyncedItemMetadata.builder(metadata); | ||
expect(builder([{}])).toBeInstanceOf(Array); | ||
expect(builder([{}])[0]).toBe("used initializer"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.