@laffery/cos-db
Advanced tools
Comparing version 1.1.0 to 1.1.1
import COS from "cos-nodejs-sdk-v5"; | ||
declare module "@laffery/cos-db" { | ||
interface Secret { | ||
interface Secret { | ||
id: string; | ||
key: string; | ||
} | ||
export interface COSConfig { | ||
} | ||
interface COSConfig { | ||
bucket: string; | ||
region: string; | ||
secret: Secret; | ||
} | ||
export class COSClient { | ||
} | ||
/** | ||
* A useful client to access COS as a database | ||
*/ | ||
declare class COSClient implements COSClient { | ||
private client; | ||
private bucket; | ||
constructor(config: COSConfig); | ||
/** | ||
@@ -21,3 +23,2 @@ * @description list items in the target directory | ||
list(dir: string): Promise<COS.GetBucketResult>; | ||
/** | ||
@@ -29,3 +30,2 @@ * @description save file object to COS | ||
put(Key: string, Body: any): Promise<COS.PutObjectResult>; | ||
/** | ||
@@ -36,3 +36,3 @@ * @description delete an object | ||
del(Key: string): Promise<COS.DeleteObjectResult>; | ||
} | ||
} | ||
export default COSClient; |
87
index.js
@@ -1,33 +0,56 @@ | ||
const COS = require('cos-nodejs-sdk-v5'); | ||
class COSClient { | ||
constructor(config) { | ||
this.client = new COS({ | ||
SecretId: config.secret.id, | ||
SecretKey: config.secret.key | ||
}); | ||
this.bucket = { | ||
Bucket: config.bucket, | ||
Region: config.region | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
var cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5")); | ||
/** | ||
* A useful client to access COS as a database | ||
*/ | ||
var COSClient = /** @class */ (function () { | ||
function COSClient(config) { | ||
this.client = new cos_nodejs_sdk_v5_1["default"]({ | ||
SecretId: config.secret.id, | ||
SecretKey: config.secret.key | ||
}); | ||
this.bucket = { | ||
Bucket: config.bucket, | ||
Region: config.region | ||
}; | ||
} | ||
} | ||
list(dir) { | ||
return this.client.getBucket({ ...this.bucket, Prefix: dir }); | ||
} | ||
put(Key, Body) { | ||
return this.client.putObject({ | ||
...this.bucket, | ||
Key, | ||
Body, | ||
StorageClass: 'STANDARD' | ||
}); | ||
} | ||
del(Key) { | ||
return this.client.deleteObject({ ...this.bucket, Key }) | ||
} | ||
} | ||
module.exports = COSClient; | ||
/** | ||
* @description list items in the target directory | ||
* @param dir directory name | ||
*/ | ||
COSClient.prototype.list = function (dir) { | ||
return this.client.getBucket(__assign(__assign({}, this.bucket), { Prefix: dir })); | ||
}; | ||
/** | ||
* @description save file object to COS | ||
* @param Key key of your object, as well as its filepath | ||
* @param Body value of the object | ||
*/ | ||
COSClient.prototype.put = function (Key, Body) { | ||
return this.client.putObject(__assign(__assign({}, this.bucket), { Key: Key, Body: Body, StorageClass: "STANDARD" })); | ||
}; | ||
/** | ||
* @description delete an object | ||
* @param Key key of your object, as well as its filepath | ||
*/ | ||
COSClient.prototype.del = function (Key) { | ||
return this.client.deleteObject(__assign(__assign({}, this.bucket), { Key: Key })); | ||
}; | ||
return COSClient; | ||
}()); | ||
exports["default"] = COSClient; |
{ | ||
"name": "@laffery/cos-db", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A useful lib to access COS as a database", | ||
@@ -8,3 +8,5 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "node test.js" | ||
"test": "node test.js", | ||
"build": "tsc", | ||
"prepublish": "yarn build" | ||
}, | ||
@@ -28,7 +30,8 @@ "repository": { | ||
"dependencies": { | ||
"cos-nodejs-sdk-v5": "^2.11.5" | ||
"cos-nodejs-sdk-v5": "^2.11.6" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.5.4" | ||
"tsc": "^2.0.4", | ||
"typescript": "^4.6.2" | ||
} | ||
} |
6275
7
182
2
Updatedcos-nodejs-sdk-v5@^2.11.6