Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ That is simple
## Usage

```js
const mongoOptions: MongoClientOptions = {
autoReconnect: true,
useNewUrlParser: true
};

let gridFS = new GridFSPromise("test", "mongodb://localhost:27017/test", mongoOptions, __dirname, "attachments");
const mongoOptions: MongoClientOptions = {};

let gridFS = new GridFSPromise(
"test",
"mongodb://localhost:27017/test",
mongoOptions,
__dirname,
"attachments",
);
gridFS.getObject("59e085f272882d728e2fa4c2").then((item) => {
console.log(item);
}).catch((err) => {
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"typescript": "^4.9.5"
},
"dependencies": {
"mongodb": "^5.4.0"
"mongodb": "^6.0.0"
}
}
188 changes: 83 additions & 105 deletions src/GridFSPromise.d.ts
Original file line number Diff line number Diff line change
@@ -1,109 +1,87 @@
import { ObjectID } from 'bson';
import {
GridFSBucketReadStream,
MongoClient,
MongoClientOptions,
} from 'mongodb';
import { ObjectId } from 'mongodb';
import { Document, GridFSBucketReadStream, MongoClient, MongoClientOptions } from 'mongodb';
export interface IGridFSObject {
_id: ObjectID;
length: number;
chunkSize: number;
uploadDate: Date;
md5: string;
filename: string;
contentType: string;
metadata: object;
_id: ObjectId;
length: number;
chunkSize: number;
uploadDate: Date;
md5?: string;
filename: string;
contentType?: string | undefined;
metadata?: Document | undefined;
}
export declare class GridFSPromise {
set CONNECTION(value: MongoClient);
get connection(): MongoClient | null;
private databaseName;
private readonly connectionUrl;
private readonly mongoClientOptions;
private basePath;
private bucketName;
private closeConnectionAutomatically;
private _CONNECTION;
maxTimeMS: number;
/**
* Constructor
* @param {string} mongoUrl
* @param {string} databaseName
* @param {MongoClientOptions} mongoOptions
* @param {string} bucketName
* @param {string} basePath
* @param {boolean} closeConnectionAutomatically
*/
constructor(
databaseName: string,
mongoUrl?: string | null,
mongoOptions?: MongoClientOptions | null,
bucketName?: string,
basePath?: string,
closeConnectionAutomatically?: boolean,
);
/**
* Returns a stream of a file from the GridFS.
* @param {string} id
* @return {Promise<GridFSBucketReadStream>}
*/
getFileStream(id: string): Promise<GridFSBucketReadStream>;
/**
* Save the File from the GridFs to the filesystem and get the Path back
* @param {string} id
* @param {string} fileName
* @param {string} filePath
* @return {Promise<string>}
*/
getFile(id: string, fileName?: string, filePath?: string): Promise<string>;
/**
* Get a single Object
* @param {string} id
* @return {Promise<IGridFSObject>}
*/
getObject(id: string): Promise<IGridFSObject>;
/**
* Upload a file directly from a fs Path
* @param {string} uploadFilePath
* @param {string} targetFileName
* @param {string} type
* @param {object} meta
* @param {boolean} deleteFile
* @return {Promise<IGridFSObject>}
*/
uploadFile(
uploadFilePath: string,
targetFileName: string,
type: string,
meta: object,
deleteFile?: boolean,
): Promise<IGridFSObject>;
/**
* Upload a file directly from a fs Path
* @param {string} uploadData
* @param {string} targetFileName
* @param {string} type
* @param {object} meta
* @return {Promise<IGridFSObject>}
*/
uploadFileString(
uploadData: string,
targetFileName: string,
type: string,
meta: object,
): Promise<IGridFSObject>;
/**
* Delete an File from the GridFS
* @param {string} id
* @return {Promise<boolean>}
*/
delete(id: string): Promise<boolean>;
/**
* Close the Connection, if the connection is not needed anymore
*/
closeConnection(): Promise<boolean>;
/**
* Connect to the Database and return a promise Object
*/
private connectDB;
set CONNECTION(value: MongoClient);
get connection(): MongoClient | null;
private databaseName;
private readonly connectionUrl;
private readonly mongoClientOptions;
private basePath;
private bucketName;
private closeConnectionAutomatically;
private _CONNECTION;
maxTimeMS: number;
/**
* Constructor
* @param {string} mongoUrl
* @param {string} databaseName
* @param {MongoClientOptions} mongoOptions
* @param {string} bucketName
* @param {string} basePath
* @param {boolean} closeConnectionAutomatically
*/
constructor(databaseName: string, mongoUrl?: string | null, mongoOptions?: MongoClientOptions | null, bucketName?: string, basePath?: string, closeConnectionAutomatically?: boolean);
/**
* Returns a stream of a file from the GridFS.
* @param {string} id
* @return {Promise<GridFSBucketReadStream>}
*/
getFileStream(id: string): Promise<GridFSBucketReadStream>;
/**
* Save the File from the GridFs to the filesystem and get the Path back
* @param {string} id
* @param {string} fileName
* @param {string} filePath
* @return {Promise<string>}
*/
getFile(id: string, fileName?: string, filePath?: string): Promise<string>;
/**
* Get a single Object
* @param {string} id
* @return {Promise<IGridFSObject>}
*/
getObject(id: string): Promise<IGridFSObject | void>;
/**
* Upload a file directly from a fs Path
* @param {string} uploadFilePath
* @param {string} targetFileName
* @param {string} type
* @param {object} meta
* @param {boolean} deleteFile
* @return {Promise<IGridFSObject>}
*/
uploadFile(uploadFilePath: string, targetFileName: string, type: string, meta: object, deleteFile?: boolean): Promise<IGridFSObject>;
/**
* Upload a file directly from a fs Path
* @param {string} uploadData
* @param {string} targetFileName
* @param {string} type
* @param {object} meta
* @return {Promise<IGridFSObject>}
*/
uploadFileString(uploadData: string, targetFileName: string, type: string, meta: object): Promise<IGridFSObject>;
/**
* Delete an File from the GridFS
* @param {string} id
* @return {Promise<boolean>}
*/
delete(id: string): Promise<boolean>;
/**
* Close the Connection, if the connection is not needed anymore
*/
closeConnection(): Promise<boolean>;
/**
* Connect to the Database and return a promise Object
*/
private connectDB;
}
Loading