mirror of
https://github.com/bitwarden/browser
synced 2026-02-07 12:13:45 +00:00
Scaffold Platform storage lib
This commit is contained in:
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
@@ -87,6 +87,7 @@ libs/common/src/platform @bitwarden/team-platform-dev
|
||||
libs/common/spec @bitwarden/team-platform-dev
|
||||
libs/common/src/state-migrations @bitwarden/team-platform-dev
|
||||
libs/platform @bitwarden/team-platform-dev
|
||||
libs/storage @bitwarden/team-platform-dev
|
||||
# Web utils used across app and connectors
|
||||
apps/web/src/utils/ @bitwarden/team-platform-dev
|
||||
# Web core and shared files
|
||||
|
||||
@@ -1,26 +1,6 @@
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
import { StorageOptions } from "../models/domain/storage-options";
|
||||
|
||||
export type StorageUpdateType = "save" | "remove";
|
||||
export type StorageUpdate = {
|
||||
key: string;
|
||||
updateType: StorageUpdateType;
|
||||
};
|
||||
|
||||
export interface ObservableStorageService {
|
||||
/**
|
||||
* Provides an {@link Observable} that represents a stream of updates that
|
||||
* have happened in this storage service or in the storage this service provides
|
||||
* an interface to.
|
||||
*/
|
||||
get updates$(): Observable<StorageUpdate>;
|
||||
}
|
||||
|
||||
export abstract class AbstractStorageService {
|
||||
abstract get valuesRequireDeserialization(): boolean;
|
||||
abstract get<T>(key: string, options?: StorageOptions): Promise<T>;
|
||||
abstract has(key: string, options?: StorageOptions): Promise<boolean>;
|
||||
abstract save<T>(key: string, obj: T, options?: StorageOptions): Promise<void>;
|
||||
abstract remove(key: string, options?: StorageOptions): Promise<void>;
|
||||
}
|
||||
export {
|
||||
StorageUpdateType,
|
||||
StorageUpdate,
|
||||
ObservableStorageService,
|
||||
StorageService as AbstractStorageService,
|
||||
} from "@bitwarden/storage";
|
||||
|
||||
@@ -1,7 +1 @@
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum HtmlStorageLocation {
|
||||
Local = "local",
|
||||
Memory = "memory",
|
||||
Session = "session",
|
||||
}
|
||||
export { HtmlStorageLocation } from "@bitwarden/storage";
|
||||
|
||||
@@ -1,7 +1 @@
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum StorageLocation {
|
||||
Both = "both",
|
||||
Disk = "disk",
|
||||
Memory = "memory",
|
||||
}
|
||||
export { StorageLocation } from "@bitwarden/storage";
|
||||
|
||||
@@ -1,9 +1 @@
|
||||
import { HtmlStorageLocation, StorageLocation } from "../../enums";
|
||||
|
||||
export type StorageOptions = {
|
||||
storageLocation?: StorageLocation;
|
||||
useSecureStorage?: boolean;
|
||||
userId?: string;
|
||||
htmlStorageLocation?: HtmlStorageLocation;
|
||||
keySuffix?: string;
|
||||
};
|
||||
export { StorageOptions } from "@bitwarden/storage";
|
||||
|
||||
5
libs/storage/README.md
Normal file
5
libs/storage/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# storage
|
||||
|
||||
Owned by: platform
|
||||
|
||||
Basic primitives for storage.
|
||||
3
libs/storage/eslint.config.mjs
Normal file
3
libs/storage/eslint.config.mjs
Normal file
@@ -0,0 +1,3 @@
|
||||
import baseConfig from "../../eslint.config.mjs";
|
||||
|
||||
export default [...baseConfig];
|
||||
10
libs/storage/jest.config.js
Normal file
10
libs/storage/jest.config.js
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
displayName: "storage",
|
||||
preset: "../../jest.preset.js",
|
||||
testEnvironment: "node",
|
||||
transform: {
|
||||
"^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }],
|
||||
},
|
||||
moduleFileExtensions: ["ts", "js", "html"],
|
||||
coverageDirectory: "../../coverage/libs/storage",
|
||||
};
|
||||
10
libs/storage/package.json
Normal file
10
libs/storage/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@bitwarden/storage",
|
||||
"version": "0.0.0",
|
||||
"description": "Basic primitives for storage.",
|
||||
"type": "commonjs",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"license": "GPL-3.0",
|
||||
"author": "platform"
|
||||
}
|
||||
27
libs/storage/project.json
Normal file
27
libs/storage/project.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "storage",
|
||||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||
"sourceRoot": "libs/storage/src",
|
||||
"projectType": "library",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nx/js:tsc",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"options": {
|
||||
"outputPath": "dist/libs/storage",
|
||||
"main": "libs/storage/src/index.ts",
|
||||
"tsConfig": "libs/storage/tsconfig.lib.json",
|
||||
"assets": ["libs/storage/*.md"]
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nx/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"options": {
|
||||
"jestConfig": "libs/storage/jest.config.js",
|
||||
"passWithNoTests": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
libs/storage/src/index.ts
Normal file
3
libs/storage/src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./observable-storage.service";
|
||||
export * from "./storage.service";
|
||||
export * from "./storage-options";
|
||||
17
libs/storage/src/observable-storage.service.ts
Normal file
17
libs/storage/src/observable-storage.service.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
export type StorageUpdateType = "save" | "remove";
|
||||
|
||||
export type StorageUpdate = {
|
||||
key: string;
|
||||
updateType: StorageUpdateType;
|
||||
};
|
||||
|
||||
export interface ObservableStorageService {
|
||||
/**
|
||||
* Provides an {@link Observable} that represents a stream of updates that
|
||||
* have happened in this storage service or in the storage this service provides
|
||||
* an interface to.
|
||||
*/
|
||||
get updates$(): Observable<StorageUpdate>;
|
||||
}
|
||||
23
libs/storage/src/storage-options.ts
Normal file
23
libs/storage/src/storage-options.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export const StorageLocation = {
|
||||
Both: "both",
|
||||
Disk: "disk",
|
||||
Memory: "memory",
|
||||
} as const;
|
||||
|
||||
export type StorageLocation = (typeof StorageLocation)[keyof typeof StorageLocation];
|
||||
|
||||
export const HtmlStorageLocation = {
|
||||
Local: "local",
|
||||
Memory: "memory",
|
||||
Session: "session",
|
||||
} as const;
|
||||
|
||||
export type HtmlStorageLocation = (typeof HtmlStorageLocation)[keyof typeof HtmlStorageLocation];
|
||||
|
||||
export type StorageOptions = {
|
||||
storageLocation?: StorageLocation;
|
||||
useSecureStorageLocation?: boolean;
|
||||
userId?: string;
|
||||
htmlStorageLocation?: HtmlStorageLocation;
|
||||
keySuffix?: string;
|
||||
};
|
||||
9
libs/storage/src/storage.service.ts
Normal file
9
libs/storage/src/storage.service.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { StorageOptions } from "./storage-options";
|
||||
|
||||
export abstract class StorageService {
|
||||
abstract get valuesRequireDeserialization(): boolean;
|
||||
abstract get<T>(key: string, options?: StorageOptions): Promise<T>;
|
||||
abstract has(key: string, options?: StorageOptions): Promise<boolean>;
|
||||
abstract save<T>(key: string, obj: T, options?: StorageOptions): Promise<void>;
|
||||
abstract remove(key: string, options?: StorageOptions): Promise<void>;
|
||||
}
|
||||
13
libs/storage/tsconfig.json
Normal file
13
libs/storage/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.lib.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.spec.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
10
libs/storage/tsconfig.lib.json
Normal file
10
libs/storage/tsconfig.lib.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"declaration": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["jest.config.js", "src/**/*.spec.ts"]
|
||||
}
|
||||
10
libs/storage/tsconfig.spec.json
Normal file
10
libs/storage/tsconfig.spec.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../..//dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node10",
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
|
||||
}
|
||||
8
package-lock.json
generated
8
package-lock.json
generated
@@ -302,6 +302,10 @@
|
||||
"version": "0.0.0",
|
||||
"license": "GPL-3.0"
|
||||
},
|
||||
"libs/storage": {
|
||||
"version": "0.0.0",
|
||||
"license": "GPL-3.0"
|
||||
},
|
||||
"libs/tools/card": {
|
||||
"name": "@bitwarden/tools-card",
|
||||
"version": "0.0.0",
|
||||
@@ -5219,6 +5223,10 @@
|
||||
"resolved": "libs/tools/send/send-ui",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@bitwarden/storage": {
|
||||
"resolved": "libs/storage",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@bitwarden/tools-card": {
|
||||
"resolved": "libs/tools/card",
|
||||
"link": true
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
"@bitwarden/platform": ["./libs/platform/src"],
|
||||
"@bitwarden/platform/*": ["./libs/platform/src/*"],
|
||||
"@bitwarden/send-ui": ["./libs/tools/send/send-ui/src"],
|
||||
"@bitwarden/storage": ["libs/storage/src/index.ts"],
|
||||
"@bitwarden/tools-card": ["./libs/tools/card/src"],
|
||||
"@bitwarden/ui-common": ["./libs/ui/common/src"],
|
||||
"@bitwarden/ui-common/setup-jest": ["./libs/ui/common/src/setup-jest"],
|
||||
|
||||
Reference in New Issue
Block a user