@reactioncommerce/file-collections-sa-gridfs
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.1.1](https://github.com/reactioncommerce/reaction-file-collections/compare/@reactioncommerce/file-collections-sa-gridfs@0.1.0...@reactioncommerce/file-collections-sa-gridfs@0.1.1) (2019-12-17) | ||
**Note:** Version bump only for package @reactioncommerce/file-collections-sa-gridfs | ||
# [0.1.0](https://github.com/reactioncommerce/reaction-file-collections/compare/@reactioncommerce/file-collections-sa-gridfs@0.0.2...@reactioncommerce/file-collections-sa-gridfs@0.1.0) (2019-08-23) | ||
@@ -8,0 +16,0 @@ |
@@ -1,3 +0,3 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });var _debug = require("debug");var _debug2 = _interopRequireDefault(_debug);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}exports.default = | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");_Object$defineProperty(exports, "__esModule", { value: true });exports.default = void 0;var _debug = _interopRequireDefault(require("debug"));var _default = | ||
(0, _debug2.default)("reaction-file-collections"); | ||
(0, _debug.default)("reaction-file-collections");exports.default = _default; |
@@ -1,10 +0,24 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });var _promise = require("babel-runtime/core-js/promise");var _promise2 = _interopRequireDefault(_promise);var _extends2 = require("babel-runtime/helpers/extends");var _extends3 = _interopRequireDefault(_extends2);var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);var _createClass2 = require("babel-runtime/helpers/createClass");var _createClass3 = _interopRequireDefault(_createClass2);var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);var _inherits2 = require("babel-runtime/helpers/inherits");var _inherits3 = _interopRequireDefault(_inherits2);var _gridfsStream = require("gridfs-stream");var _gridfsStream2 = _interopRequireDefault(_gridfsStream); | ||
var _fileCollectionsSaBase = require("@reactioncommerce/file-collections-sa-base");var _fileCollectionsSaBase2 = _interopRequireDefault(_fileCollectionsSaBase); | ||
var _debug = require("./debug");var _debug2 = _interopRequireDefault(_debug);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _Object$defineProperty2 = require("@babel/runtime-corejs2/core-js/object/define-property");_Object$defineProperty2(exports, "__esModule", { value: true });exports.default = void 0;var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/define-property"));var _defineProperties = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/define-properties"));var _getOwnPropertyDescriptors = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors"));var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor"));var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols"));var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));var _defineProperty3 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));var _gridfsStream = _interopRequireDefault(require("gridfs-stream")); | ||
var _fileCollectionsSaBase = _interopRequireDefault(require("@reactioncommerce/file-collections-sa-base")); | ||
var _debug = _interopRequireDefault(require("./debug"));function ownKeys(object, enumerableOnly) {var keys = (0, _keys.default)(object);if (_getOwnPropertySymbols.default) {var symbols = (0, _getOwnPropertySymbols.default)(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {return (0, _getOwnPropertyDescriptor.default)(object, sym).enumerable;});keys.push.apply(keys, symbols);}return keys;}function _objectSpread(target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {ownKeys(Object(source), true).forEach(function (key) {(0, _defineProperty3.default)(target, key, source[key]);});} else if (_getOwnPropertyDescriptors.default) {(0, _defineProperties.default)(target, (0, _getOwnPropertyDescriptors.default)(source));} else {ownKeys(Object(source)).forEach(function (key) {(0, _defineProperty2.default)(target, key, (0, _getOwnPropertyDescriptor.default)(source, key));});}}return target;} | ||
// 256k is default GridFS chunk size, but performs terribly for largish files | ||
var DEFAULT_CHUNK_SIZE = 1024 * 1024 * 2;var | ||
const DEFAULT_CHUNK_SIZE = 1024 * 1024 * 2; | ||
GridFSStore = function (_StorageAdapter) {(0, _inherits3.default)(GridFSStore, _StorageAdapter); | ||
function GridFSStore() | ||
class GridFSStore extends _fileCollectionsSaBase.default { | ||
constructor({ | ||
chunkSize = DEFAULT_CHUNK_SIZE, | ||
collectionPrefix = "fc_sa_gridfs.", | ||
db, | ||
fileKeyMaker, | ||
mongodb, | ||
name, | ||
transformRead, | ||
transformWrite } = | ||
{}) { | ||
super({ | ||
fileKeyMaker, | ||
name, | ||
transformRead, | ||
transformWrite });(0, _defineProperty3.default)(this, "typeName", | ||
@@ -18,8 +32,2 @@ | ||
{var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},_ref$chunkSize = _ref.chunkSize,chunkSize = _ref$chunkSize === undefined ? DEFAULT_CHUNK_SIZE : _ref$chunkSize,_ref$collectionPrefix = _ref.collectionPrefix,collectionPrefix = _ref$collectionPrefix === undefined ? "fc_sa_gridfs." : _ref$collectionPrefix,db = _ref.db,fileKeyMaker = _ref.fileKeyMaker,mongodb = _ref.mongodb,name = _ref.name,transformRead = _ref.transformRead,transformWrite = _ref.transformWrite;(0, _classCallCheck3.default)(this, GridFSStore);var _this = (0, _possibleConstructorReturn3.default)(this, (GridFSStore.__proto__ || (0, _getPrototypeOf2.default)(GridFSStore)).call(this, | ||
{ | ||
fileKeyMaker: fileKeyMaker, | ||
name: name, | ||
transformRead: transformRead, | ||
transformWrite: transformWrite }));_this. | ||
@@ -106,21 +114,13 @@ | ||
typeName = "gridfs";_this.chunkSize = chunkSize;_this.collectionName = ("" + collectionPrefix + name).trim();_this.grid = (0, _gridfsStream2.default)(db, mongodb);_this.mongodb = mongodb;return _this;}(0, _createClass3.default)(GridFSStore, [{ key: "_fileKeyMaker", value: function _fileKeyMaker(fileRecord) {var info = fileRecord.infoForCopy(this.name);var result = { _id: info.key || null, filename: info.name || fileRecord.name() || fileRecord.collectionName + "-" + fileRecord._id };(0, _debug2.default)("GridFSStore _fileKeyMaker result:", result);return result;} }, { key: "_getReadStream", value: function _getReadStream(fileKey) {var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},startPos = _ref2.start,endPos = _ref2.end;var opts = { _id: fileKey._id, root: this.collectionName }; // Add range if this should be a partial read | ||
if (typeof startPos === "number" && typeof endPos === "number") {opts.range = { startPos: startPos, endPos: endPos };}(0, _debug2.default)("GridFSStore _getReadStream opts:", opts);return this.grid.createReadStream(opts);} }, { key: "_getWriteStream", value: function _getWriteStream(fileKey) {var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};var opts = (0, _extends3.default)({ chunk_size: this.chunkSize, // eslint-disable-line camelcase | ||
content_type: "application/octet-stream", // eslint-disable-line camelcase | ||
filename: fileKey.filename, mode: "w", // overwrite any existing data | ||
root: this.collectionName }, options);if (fileKey._id) opts._id = fileKey._id;(0, _debug2.default)("GridFSStore _getWriteStream opts:", opts);var writeStream = this.grid.createWriteStream(opts);writeStream.on("close", function (file) {if (!file) {// gridfs-stream will emit "close" without passing a file | ||
// if there is an error. We can simply exit here because | ||
// the "error" listener will also be called in this case. | ||
return;} // Emit end and return the fileKey, size, and updated date | ||
writeStream.emit("stored", { // Set the generated _id so that we know it for future reads and writes. | ||
// We store the _id as a string and only convert to ObjectID right before | ||
// reading, writing, or deleting. | ||
fileKey: file._id.toString(), size: file.length, storedAt: file.uploadDate || new Date() });});return writeStream;} }, { key: "_removeFile", value: function _removeFile(fileKey) {var _this2 = this;(0, _debug2.default)("GridFSStore _removeFile called for fileKey", fileKey);if (!fileKey._id) return _promise2.default.resolve();return new _promise2.default(function (resolve, reject) {_this2.grid.remove({ _id: fileKey._id, root: _this2.collectionName }, function (error, result) {if (error) {reject(error);} else {resolve(result);}});});} }]);return GridFSStore;}(_fileCollectionsSaBase2.default);exports.default = GridFSStore; | ||
"gridfs");this.chunkSize = chunkSize;this.collectionName = `${collectionPrefix}${name}`.trim();this.grid = (0, _gridfsStream.default)(db, mongodb);this.mongodb = mongodb;}_fileKeyMaker(fileRecord) {const info = fileRecord.infoForCopy(this.name);const result = { _id: info.key || null, filename: info.name || fileRecord.name() || `${fileRecord.collectionName}-${fileRecord._id}` };(0, _debug.default)("GridFSStore _fileKeyMaker result:", result);return result;}_getReadStream(fileKey, { start: startPos, end: endPos } = {}) {const opts = { _id: fileKey._id, root: this.collectionName }; // Add range if this should be a partial read | ||
if (typeof startPos === "number" && typeof endPos === "number") {opts.range = { startPos, endPos };}(0, _debug.default)("GridFSStore _getReadStream opts:", opts);return this.grid.createReadStream(opts);}_getWriteStream(fileKey, options = {}) {const opts = _objectSpread({ chunk_size: this.chunkSize, // eslint-disable-line camelcase | ||
content_type: "application/octet-stream", // eslint-disable-line camelcase | ||
filename: fileKey.filename, mode: "w", // overwrite any existing data | ||
root: this.collectionName }, options);if (fileKey._id) opts._id = fileKey._id;(0, _debug.default)("GridFSStore _getWriteStream opts:", opts);const writeStream = this.grid.createWriteStream(opts);writeStream.on("close", file => {if (!file) {// gridfs-stream will emit "close" without passing a file | ||
// if there is an error. We can simply exit here because | ||
// the "error" listener will also be called in this case. | ||
return;} // Emit end and return the fileKey, size, and updated date | ||
writeStream.emit("stored", { // Set the generated _id so that we know it for future reads and writes. | ||
// We store the _id as a string and only convert to ObjectID right before | ||
// reading, writing, or deleting. | ||
fileKey: file._id.toString(), size: file.length, storedAt: file.uploadDate || new Date() });});return writeStream;}_removeFile(fileKey) {(0, _debug.default)("GridFSStore _removeFile called for fileKey", fileKey);if (!fileKey._id) return _promise.default.resolve();return new _promise.default((resolve, reject) => {this.grid.remove({ _id: fileKey._id, root: this.collectionName }, (error, result) => {if (error) {reject(error);} else {resolve(result);}});});}}exports.default = GridFSStore; |
@@ -1,1 +0,3 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });var _GridFSStore = require("./GridFSStore");var _GridFSStore2 = _interopRequireDefault(_GridFSStore);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}exports.default = _GridFSStore2.default; | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");_Object$defineProperty(exports, "__esModule", { value: true });exports.default = void 0;var _GridFSStore = _interopRequireDefault(require("./GridFSStore"));var _default = | ||
_GridFSStore.default;exports.default = _default; |
{ | ||
"name": "@reactioncommerce/file-collections-sa-gridfs", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A GridFS storage adapter for Reaction FileCollections.", | ||
@@ -22,7 +22,32 @@ "author": "Reaction Commerce (https://reactioncommerce.com/)", | ||
"plugins": [ | ||
"transform-runtime" | ||
[ | ||
"@babel/plugin-transform-runtime", | ||
{ | ||
"corejs": 2 | ||
} | ||
], | ||
"@babel/plugin-syntax-dynamic-import", | ||
"@babel/plugin-syntax-import-meta", | ||
"@babel/plugin-proposal-class-properties", | ||
"@babel/plugin-proposal-json-strings", | ||
[ | ||
"@babel/plugin-proposal-decorators", | ||
{ | ||
"legacy": true | ||
} | ||
], | ||
"@babel/plugin-proposal-function-sent", | ||
"@babel/plugin-proposal-export-namespace-from", | ||
"@babel/plugin-proposal-numeric-separator", | ||
"@babel/plugin-proposal-throw-expressions" | ||
], | ||
"presets": [ | ||
"es2015", | ||
"stage-2" | ||
[ | ||
"@babel/env", | ||
{ | ||
"targets": { | ||
"node": "8" | ||
} | ||
} | ||
] | ||
], | ||
@@ -33,12 +58,15 @@ "sourceMaps": true, | ||
"eslintConfig": { | ||
"extends": "@reactioncommerce" | ||
"extends": "@reactioncommerce", | ||
"rules": { | ||
"node/no-unsupported-features/es-syntax": "off" | ||
} | ||
}, | ||
"main": "./dist/index.js", | ||
"scripts": { | ||
"build": "rm -rf dist/** && babel src --out-dir dist --ignore *.test.js,__snapshots__", | ||
"build": "rm -rf dist/** && babel src --out-dir dist --ignore \"**/*.test.js\"", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"dependencies": { | ||
"@reactioncommerce/file-collections-sa-base": "^0.1.0", | ||
"babel-runtime": "^6.26.0", | ||
"@babel/runtime-corejs2": "^7.7.6", | ||
"@reactioncommerce/file-collections-sa-base": "^0.1.1", | ||
"debug": "^3.1.0", | ||
@@ -48,9 +76,18 @@ "gridfs-stream": "^1.1.1" | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.0", | ||
"babel-eslint": "^8.2.1", | ||
"babel-jest": "^22.0.4", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-preset-stage-2": "^6.24.1" | ||
"@babel/cli": "^7.7.5", | ||
"@babel/core": "^7.7.5", | ||
"@babel/plugin-proposal-class-properties": "^7.7.4", | ||
"@babel/plugin-proposal-decorators": "^7.7.4", | ||
"@babel/plugin-proposal-export-namespace-from": "^7.7.4", | ||
"@babel/plugin-proposal-function-sent": "^7.7.4", | ||
"@babel/plugin-proposal-json-strings": "^7.7.4", | ||
"@babel/plugin-proposal-numeric-separator": "^7.7.4", | ||
"@babel/plugin-proposal-throw-expressions": "^7.7.4", | ||
"@babel/plugin-syntax-dynamic-import": "^7.7.4", | ||
"@babel/plugin-syntax-import-meta": "^7.7.4", | ||
"@babel/plugin-transform-runtime": "^7.7.6", | ||
"@babel/preset-env": "^7.7.6", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-eslint": "^10.0.3", | ||
"babel-jest": "^24.9.0" | ||
}, | ||
@@ -60,3 +97,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "9a9358ac4c895bfcbe3d530f78df2b0577d237b9" | ||
"gitHead": "efc2cf55dd2e421b4ef676f3502d543fc523f930" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
11695
47
1
16
- Removedbabel-runtime@^6.26.0
- Removedbabel-runtime@6.26.0(transitive)
- Removedregenerator-runtime@0.11.1(transitive)