From eb6a13d0bd1aa15d9c5782c2b3623e613513e9d9 Mon Sep 17 00:00:00 2001 From: liwei Date: Wed, 18 Oct 2023 10:59:42 +0800 Subject: [PATCH] feat: add extension storage api --- package.json | 2 +- packages/create-gopeed-ext/package.json | 2 +- .../templates/webpack/package.json | 4 +-- packages/gopeed-rest/package.json | 2 +- packages/gopeed-types/package.json | 2 +- packages/gopeed/package.json | 2 +- packages/gopeed/src/extension/index.ts | 30 +++++++++++++++++-- 7 files changed, 35 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 2478eb7..493ddf8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "1.0.9", + "version": "1.1.0", "packageManager": "pnpm@8.6.1", "type": "module", "scripts": { diff --git a/packages/create-gopeed-ext/package.json b/packages/create-gopeed-ext/package.json index 588382c..8c21513 100644 --- a/packages/create-gopeed-ext/package.json +++ b/packages/create-gopeed-ext/package.json @@ -1,6 +1,6 @@ { "name": "create-gopeed-ext", - "version": "1.0.9", + "version": "1.1.0", "keywords": [ "gopeed" ], diff --git a/packages/create-gopeed-ext/templates/webpack/package.json b/packages/create-gopeed-ext/templates/webpack/package.json index 7b49879..05fec51 100644 --- a/packages/create-gopeed-ext/templates/webpack/package.json +++ b/packages/create-gopeed-ext/templates/webpack/package.json @@ -20,8 +20,8 @@ "eslint": "^8.51.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0", - "gopeed": "^1.0.9", - "@gopeed/types": "^1.0.9", + "gopeed": "^1.1.0", + "@gopeed/types": "^1.1.0", "prettier": "^3.0.3", "webpack": "^5.75.0", "webpack-cli": "^5.0.1" diff --git a/packages/gopeed-rest/package.json b/packages/gopeed-rest/package.json index 323f089..4e03215 100644 --- a/packages/gopeed-rest/package.json +++ b/packages/gopeed-rest/package.json @@ -1,6 +1,6 @@ { "name": "@gopeed/rest", - "version": "1.0.9", + "version": "1.1.0", "description": "", "main": "dist/index.js", "exports": { diff --git a/packages/gopeed-types/package.json b/packages/gopeed-types/package.json index debdab2..96f89a1 100644 --- a/packages/gopeed-types/package.json +++ b/packages/gopeed-types/package.json @@ -1,6 +1,6 @@ { "name": "@gopeed/types", - "version": "1.0.9", + "version": "1.1.0", "description": "", "main": "dist/index.js", "exports": { diff --git a/packages/gopeed/package.json b/packages/gopeed/package.json index 7ebac9b..856e6dc 100644 --- a/packages/gopeed/package.json +++ b/packages/gopeed/package.json @@ -1,6 +1,6 @@ { "name": "gopeed", - "version": "1.0.9", + "version": "1.1.0", "description": "", "main": "dist/index.js", "exports": { diff --git a/packages/gopeed/src/extension/index.ts b/packages/gopeed/src/extension/index.ts index 9ce4f06..601eec1 100644 --- a/packages/gopeed/src/extension/index.ts +++ b/packages/gopeed/src/extension/index.ts @@ -4,18 +4,44 @@ import { Request, Resource } from '@gopeed/types'; type Settings = { [key: string]: unknown }; +interface Storage { + /** + * Returns the current value associated with the given key, or null if the given key does not exist. + * @param key + */ + get(key: string): string; + /** + * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously. + * @param key + * @param value + */ + set(key: string, value: string): void; + /** + * Removes the key/value pair with the given key, if a key/value pair with the given key exists. + * @param key + */ + remove(key: string): void; + /** + * Removes all key/value pairs, if any, that match the given key. + */ + clear(): void; + /** + * Returns all keys currently stored in the storage. + */ + keys(): string[]; +} + interface OnResovleContext { req: Request; res: Resource; settings: Settings; + storage: Storage; } interface Events { onResolve(handler: (ctx: OnResovleContext) => void): void; } -console.log(); - interface Logger { debug(message?: any, ...optionalParams: any[]): void; info(message?: any, ...optionalParams: any[]): void;