@rpldy/shared
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -10,16 +10,18 @@ "use strict"; | ||
var BATCH_STATES = Object.freeze({ | ||
ADDED: 1, | ||
PROCESSING: 2, | ||
UPLOADING: 3, | ||
CANCELLED: 4, | ||
FINISHED: 5 | ||
ADDED: "added", | ||
PROCESSING: "processing", | ||
UPLOADING: "uploading", | ||
CANCELLED: "cancelled", | ||
FINISHED: "finished", | ||
ABORTED: "aborted" | ||
}); | ||
exports.BATCH_STATES = BATCH_STATES; | ||
var FILE_STATES = Object.freeze({ | ||
ADDED: 1, | ||
UPLOADING: 2, | ||
CANCELLED: 3, | ||
FINISHED: 4, | ||
ERROR: 5 | ||
ADDED: "added", | ||
UPLOADING: "uploading", | ||
CANCELLED: "cancelled", | ||
FINISHED: "finished", | ||
ERROR: "error", | ||
ABORTED: "aborted" | ||
}); | ||
exports.FILE_STATES = FILE_STATES; |
@@ -26,2 +26,26 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "isSamePropInArrays", { | ||
enumerable: true, | ||
get: function get() { | ||
return _utils.isSamePropInArrays; | ||
} | ||
}); | ||
Object.defineProperty(exports, "triggerCancellable", { | ||
enumerable: true, | ||
get: function get() { | ||
return _triggerCancellable["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "triggerUpdater", { | ||
enumerable: true, | ||
get: function get() { | ||
return _triggerUpdater["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createBatchItem", { | ||
enumerable: true, | ||
get: function get() { | ||
return _batchItem["default"]; | ||
} | ||
}); | ||
exports.logger = void 0; | ||
@@ -37,4 +61,12 @@ | ||
var _triggerCancellable = _interopRequireDefault(require("./triggerCancellable")); | ||
var _triggerUpdater = _interopRequireDefault(require("./triggerUpdater")); | ||
var _batchItem = _interopRequireDefault(require("./batchItem")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.debugLog = exports.setDebug = void 0; | ||
exports.debugLog = exports.setDebug = exports.isDebugOn = void 0; | ||
@@ -15,3 +15,3 @@ var _consts = require("./consts"); | ||
if (typeof isDebug !== "boolean") { | ||
isDebug = process.env.DEBUG || ~window.location.search.indexOf("debug=true") || window[_consts.DEBUG_LOG_KEY] === true; | ||
isDebug = process.env.DEBUG || !!~window.location.search.indexOf("rpldy_debug=true") || window[_consts.DEBUG_LOG_KEY] === true; | ||
} | ||
@@ -22,5 +22,7 @@ | ||
exports.isDebugOn = isDebugOn; | ||
var setDebug = function setDebug(debugOn) { | ||
window[_consts.DEBUG_LOG_KEY] = debugOn; | ||
isDebug = null; | ||
isDebug = debugOn ? true : null; | ||
}; | ||
@@ -34,2 +36,3 @@ | ||
// eslint-disable-next-line no-console | ||
(_console = console).log.apply(_console, arguments); | ||
@@ -36,0 +39,0 @@ } |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.isFunction = void 0; | ||
exports.isSamePropInArrays = exports.isFunction = void 0; | ||
@@ -13,2 +13,52 @@ var isFunction = function isFunction(f) { | ||
exports.isFunction = isFunction; | ||
exports.isFunction = isFunction; | ||
var getPropsExtractor = function getPropsExtractor(prop) { | ||
var props = [].concat(prop); | ||
return function (arr) { | ||
return arr.map(function (i) { | ||
return props.map(function (p) { | ||
return i[p]; | ||
}).join(); | ||
}); | ||
}; | ||
}; | ||
/* | ||
stringifies props together - will return true for same type of value (ex: function) | ||
even if refs are different | ||
*/ | ||
var isSamePropInArrays = function isSamePropInArrays(arr1, arr2, prop) { | ||
var diff = true; | ||
var propsExtractor = getPropsExtractor(prop); | ||
if (arr1 && arr2 && arr1.length === arr2.length) { | ||
var props1 = propsExtractor(arr1), | ||
props2 = propsExtractor(arr2); | ||
diff = !!props1.find(function (p, i) { | ||
return p !== props2[i]; | ||
}); | ||
} | ||
return !diff; | ||
}; // /** | ||
// * stringifies an object (props) in a way that should lead | ||
// * to same string as long as keys/values stay the same | ||
// * while any change will result in a different string | ||
// * doesnt handle object ref properties - these will result in the same string even if different ref value | ||
// * only deals with own properties | ||
// * | ||
// * This is better than using JSON.stringify because it attempts to sort the properties | ||
// * however its less accurate due to object properties | ||
// */ | ||
// const getHookDependenciesString = (deps: Object): string => { | ||
// return Object.keys(deps) | ||
// .sort() | ||
// .reduce((res, key) => { | ||
// | ||
// }, ""); | ||
// }; | ||
exports.isSamePropInArrays = isSamePropInArrays; |
{ | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"name": "@rpldy/shared", | ||
@@ -15,8 +15,15 @@ "description": "", | ||
"scripts": { | ||
"build": "node ../../scripts/build.js" | ||
"build": "node ../../scripts/build.js", | ||
"flow:copy": "flow-copy-source ./src ./lib; cp src/types.js lib/types.js" | ||
}, | ||
"devDependencies": { | ||
"flow-bin": "^0.119.1" | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.17.15" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "ee693c1d4f8c2f7cb7809ed848d8c8b780459a2a" | ||
"gitHead": "0974c6250a302c0a59132e161237bebb9a135c41" | ||
} |
@@ -6,15 +6,17 @@ // @flow | ||
export const BATCH_STATES = Object.freeze({ | ||
ADDED: 1, | ||
PROCESSING: 2, | ||
UPLOADING: 3, | ||
CANCELLED: 4, | ||
FINISHED: 5, | ||
ADDED: "added", | ||
PROCESSING: "processing", | ||
UPLOADING: "uploading", | ||
CANCELLED: "cancelled", | ||
FINISHED: "finished", | ||
ABORTED: "aborted", | ||
}); | ||
export const FILE_STATES = Object.freeze({ | ||
ADDED: 1, | ||
UPLOADING: 2, | ||
CANCELLED: 3, | ||
FINISHED: 4, | ||
ERROR: 5, | ||
ADDED: "added", | ||
UPLOADING: "uploading", | ||
CANCELLED: "cancelled", | ||
FINISHED: "finished", | ||
ERROR: "error", | ||
ABORTED: "aborted", | ||
}); |
@@ -5,23 +5,7 @@ // @flow | ||
import * as logger from "./logger"; | ||
import { isFunction } from "./utils"; | ||
import { isFunction, isSamePropInArrays } from "./utils"; | ||
import triggerCancellable from "./triggerCancellable"; | ||
import triggerUpdater from "./triggerUpdater"; | ||
import createBatchItem from "./batchItem"; | ||
import type { | ||
UploadOptions, | ||
CreateOptions, | ||
Destination, | ||
UploadInfo, | ||
ProgressInfo, | ||
BatchState, | ||
FileState, | ||
NonMaybeTypeFunc, | ||
Batch, | ||
BatchItem, | ||
SendMethod, | ||
SendResult, | ||
UploadData, | ||
OnProgress, | ||
SendOptions, | ||
SenderProgressEvent, | ||
} from "./types"; | ||
export { | ||
@@ -33,2 +17,7 @@ BATCH_STATES, | ||
isFunction, | ||
isSamePropInArrays, | ||
triggerCancellable, | ||
triggerUpdater, | ||
createBatchItem, | ||
}; | ||
@@ -53,2 +42,8 @@ | ||
SenderProgressEvent, | ||
}; | ||
Trigger, | ||
Cancellable, | ||
Updater, | ||
FileLike, | ||
GetExact, | ||
FileFilterMethod, | ||
} from "./types"; |
@@ -9,3 +9,3 @@ // @flow | ||
isDebug = process.env.DEBUG || | ||
~window.location.search.indexOf("debug=true") || | ||
!!~window.location.search.indexOf("rpldy_debug=true") || | ||
window[DEBUG_LOG_KEY] === true; | ||
@@ -19,3 +19,3 @@ } | ||
window[DEBUG_LOG_KEY] = debugOn; | ||
isDebug = null; | ||
isDebug = debugOn ? true : null; | ||
}; | ||
@@ -25,2 +25,3 @@ | ||
if (isDebugOn()) { | ||
// eslint-disable-next-line no-console | ||
console.log(...args); | ||
@@ -31,4 +32,5 @@ } | ||
export { | ||
isDebugOn, | ||
setDebug, | ||
debugLog, | ||
}; | ||
}; |
// @flow | ||
import { BATCH_STATES, FILE_STATES } from "./consts"; | ||
import type { UploaderEnhancer } from "@rpldy/uploader"; | ||
@@ -8,7 +9,11 @@ export type NonMaybeTypeFunc = <T>(param: T) => $NonMaybeType<T>; | ||
//upload URL | ||
url: string, | ||
url: ?string, | ||
//The name of the param in the upload request (default: input element's name) | ||
filesParamName?: string, | ||
filesParamName?: ?string, | ||
//collection of params to pass along with the upload | ||
params?: Object, | ||
//collection of headers to send with | ||
headers?: Object, | ||
//HTTP method to use when uploading | ||
method?: ?string, | ||
}; | ||
@@ -36,3 +41,3 @@ | ||
request: Promise<UploadData>, | ||
abort: () => void | ||
abort: () => boolean, | ||
}; | ||
@@ -42,3 +47,3 @@ | ||
export type OnProgress = (e: SenderProgressEvent) => void; | ||
export type FormatParamGroupNameMethod = (number, string) => string; | ||
@@ -49,9 +54,9 @@ export type SendOptions = { | ||
params: Object, | ||
// encoding: string, | ||
headers?: Object, | ||
forceJsonResponse: ?boolean, | ||
withCredentials: ?boolean, | ||
formatGroupParamName: ?FormatParamGroupNameMethod, | ||
}; | ||
type BatchUrl = {| | ||
type BatchItemBase = {| | ||
id: string, | ||
@@ -61,3 +66,2 @@ batchId: string, | ||
uploadResponse?: any, | ||
abort: () => void, | ||
//percentage of upload completed | ||
@@ -67,20 +71,25 @@ completed: number, | ||
loaded: number, | ||
url: string, | ||
|}; | ||
type BatchFile = {| | ||
id: string, | ||
batchId: string, | ||
state: FileState, | ||
uploadResponse?: any, | ||
abort: () => void, | ||
//percentage of upload completed | ||
completed: number, | ||
//bytes uploaded | ||
loaded: number, | ||
file: Object, | ||
|}; | ||
export type FileLike = { | ||
name: string, | ||
size: number, | ||
type: string, | ||
lastModified: number, | ||
} | ||
export type BatchItem = BatchUrl | & BatchFile; | ||
type BatchUrl = { | ||
...BatchItemBase, | ||
url: string, | ||
}; | ||
type BatchFile = { | ||
...BatchItemBase, | ||
file: FileLike, | ||
}; | ||
export type BatchItem = BatchUrl & BatchFile; | ||
export type OnProgress = (e: SenderProgressEvent, Object[]) => void; | ||
export type Batch = { | ||
@@ -90,16 +99,22 @@ id: string, | ||
items: BatchItem[], | ||
state: BatchState | ||
state: BatchState, | ||
//average of percentage of upload completed for batch items | ||
completed: number, | ||
//sum of bytes uploaded for batch items | ||
loaded: number, | ||
}; | ||
export type SendMethod = (item: BatchItem, url: string, options: SendOptions, onProgress: OnProgress) => SendResult; | ||
export type SendMethod = (item: BatchItem[], url: string, options: SendOptions, onProgress: OnProgress) => SendResult; | ||
export type UploadOptions = { | ||
export type FileFilterMethod = (mixed) => boolean; | ||
export type UploadOptions = {| | ||
//whether to automatically upload files when they are added (default: true) | ||
autoUpload?: boolean, | ||
//destination properties related to the server files will be uploaded to | ||
destination?: Destination, | ||
destination?: ?Destination, | ||
//name (attribute) of the file input field (default: "file") | ||
inputFieldName?: string, | ||
//whether to allow more than one file to be selected for upload (default: true) | ||
multiple?: boolean, | ||
//optional function to determine the upload field name when more than file is grouped in a single upload | ||
formatGroupParamName?: FormatParamGroupNameMethod, | ||
//whether to group multiple files in a single request (default: false) | ||
@@ -109,9 +124,5 @@ grouped?: boolean, | ||
maxGroupSize?: number, | ||
//the regex or function to use to filter by filename/url | ||
fileFilter?: RegExp | Function, | ||
//The accept value to pass the file input | ||
inputAccept?: string, | ||
// //the upload encoding (default: "multipart/form-data") | ||
// encoding?: string, | ||
//HTTP method (default: POST) | ||
//optional function to use to filter by filename/url | ||
fileFilter?: FileFilterMethod, | ||
//HTTP method to use when uploading (default: POST) | ||
method?: string, | ||
@@ -124,5 +135,8 @@ //collection of params to pass along with the upload (Destination params take precedence) | ||
withCredentials?: boolean, | ||
}; | ||
|}; | ||
export type CreateOptions = UploadOptions & { | ||
export type CreateOptions = {| | ||
...UploadOptions, | ||
//uploader enhancer function | ||
enhancer?: UploaderEnhancer, | ||
//whether multiple upload requests can be issued simultaneously (default: false) | ||
@@ -134,2 +148,10 @@ concurrent?: boolean, | ||
send?: ?SendMethod, | ||
}; | ||
|}; | ||
export type Trigger<T> = (string, ...args: mixed[]) => Promise<?T>[]; | ||
export type Cancellable = (string, ...args: mixed[]) => Promise<boolean>; | ||
export type Updater<T> = (string, ...args: mixed[]) => Promise<?T>; | ||
export type GetExact<T> = T & $Shape<T>; |
// @flow | ||
const isFunction = (f: mixed) : boolean %checks => typeof (f) === "function"; | ||
const isFunction = (f: mixed): boolean %checks => typeof (f) === "function"; | ||
const getPropsExtractor = (prop: string | string[]) => { | ||
const props = [].concat(prop); | ||
return (arr: Object[]) => | ||
arr.map((i) => props.map((p) => i[p]).join()); | ||
}; | ||
/* | ||
stringifies props together - will return true for same type of value (ex: function) | ||
even if refs are different | ||
*/ | ||
const isSamePropInArrays = (arr1: Object[], arr2: Object[], prop: string | string[]): boolean => { | ||
let diff = true; | ||
const propsExtractor = getPropsExtractor(prop); | ||
if (arr1 && arr2 && arr1.length === arr2.length) { | ||
const props1 = propsExtractor(arr1), | ||
props2 = propsExtractor(arr2); | ||
diff = !!props1.find((p, i) => p !== props2[i]); | ||
} | ||
return !diff; | ||
}; | ||
// /** | ||
// * stringifies an object (props) in a way that should lead | ||
// * to same string as long as keys/values stay the same | ||
// * while any change will result in a different string | ||
// * doesnt handle object ref properties - these will result in the same string even if different ref value | ||
// * only deals with own properties | ||
// * | ||
// * This is better than using JSON.stringify because it attempts to sort the properties | ||
// * however its less accurate due to object properties | ||
// */ | ||
// const getHookDependenciesString = (deps: Object): string => { | ||
// return Object.keys(deps) | ||
// .sort() | ||
// .reduce((res, key) => { | ||
// | ||
// }, ""); | ||
// }; | ||
export { | ||
isFunction, | ||
}; | ||
isSamePropInArrays, | ||
// getHookDependenciesString, | ||
}; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
31326
23
873
1
1
1
+ Addedlodash@^4.17.15
+ Addedlodash@4.17.21(transitive)