mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2025-07-26 12:48:50 +00:00
apps
data analysis
website
functions
node_modules
.bin
@firebase
@google-cloud
@grpc
@mrmlnc
@nodelib
@protobufjs
@types
accepts
acorn
acorn-es7-plugin
ajv
ansi-regex
arr-diff
arr-flatten
arr-union
array-filter
array-flatten
array-union
array-uniq
array-unique
arrify
ascli
asn1
assert-plus
assign-symbols
async
dist
internal
CHANGELOG.md
LICENSE
README.md
all.js
allLimit.js
allSeries.js
any.js
anyLimit.js
anySeries.js
apply.js
applyEach.js
applyEachSeries.js
asyncify.js
auto.js
autoInject.js
bower.json
cargo.js
compose.js
concat.js
concatLimit.js
concatSeries.js
constant.js
detect.js
detectLimit.js
detectSeries.js
dir.js
doDuring.js
doUntil.js
doWhilst.js
during.js
each.js
eachLimit.js
eachOf.js
eachOfLimit.js
eachOfSeries.js
eachSeries.js
ensureAsync.js
every.js
everyLimit.js
everySeries.js
filter.js
filterLimit.js
filterSeries.js
find.js
findLimit.js
findSeries.js
foldl.js
foldr.js
forEach.js
forEachLimit.js
forEachOf.js
forEachOfLimit.js
forEachOfSeries.js
forEachSeries.js
forever.js
groupBy.js
groupByLimit.js
groupBySeries.js
index.js
inject.js
log.js
map.js
mapLimit.js
mapSeries.js
mapValues.js
mapValuesLimit.js
mapValuesSeries.js
memoize.js
nextTick.js
package.json
parallel.js
parallelLimit.js
priorityQueue.js
queue.js
race.js
reduce.js
reduceRight.js
reflect.js
reflectAll.js
reject.js
rejectLimit.js
rejectSeries.js
retry.js
retryable.js
select.js
selectLimit.js
selectSeries.js
seq.js
series.js
setImmediate.js
some.js
someLimit.js
someSeries.js
sortBy.js
timeout.js
times.js
timesLimit.js
timesSeries.js
transform.js
tryEach.js
unmemoize.js
until.js
waterfall.js
whilst.js
wrapSync.js
asynckit
atob
aws-sign2
aws4
axios
balanced-match
base
bcrypt-pbkdf
body-parser
brace-expansion
braces
buffer-equal-constant-time
buffer-from
bun
bytebuffer
bytes
cache-base
call-me-maybe
call-signature
camelcase
capture-stack-trace
caseless
class-utils
cliui
code-point-at
collection-visit
colour
combined-stream
component-emitter
compressible
concat-map
concat-stream
configstore
content-disposition
content-type
cookie
cookie-signature
copy-descriptor
core-js
core-util-is
cors
create-error-class
crypto-random-string
dashdash
debug
decamelize
decode-uri-component
deep-equal
define-properties
define-property
delayed-stream
depd
destroy
diff-match-patch
dir-glob
dom-storage
dot-prop
duplexify
eastasianwidth
ecc-jsbn
ecdsa-sig-formatter
ee-first
empower
empower-core
encodeurl
end-of-stream
ent
escape-html
espurify
estraverse
etag
expand-brackets
express
extend
extend-shallow
extglob
extsprintf
fast-deep-equal
fast-glob
fast-json-stable-stringify
faye-websocket
fill-range
finalhandler
firebase-admin
firebase-functions
follow-redirects
for-in
forever-agent
form-data
forwarded
fragment-cache
fresh
fs.realpath
functional-red-black-tree
gcp-metadata
gcs-resumable-upload
get-value
getpass
glob
glob-parent
glob-to-regexp
globby
google-auth-library
google-auto-auth
google-gax
google-p12-pem
google-proto-files
graceful-fs
grpc
gtoken
har-schema
har-validator
has-value
has-values
hash-stream-validation
http-errors
http-parser-js
http-signature
iconv-lite
ignore
imurmurhash
indexof
inflight
inherits
invert-kv
ipaddr.js
is
is-accessor-descriptor
is-buffer
is-data-descriptor
is-descriptor
is-extendable
is-extglob
is-fullwidth-code-point
is-glob
is-number
is-obj
is-plain-object
is-stream-ended
is-typedarray
is-windows
isarray
isobject
isstream
jsbn
json-schema
json-schema-traverse
json-stringify-safe
jsonwebtoken
jsprim
jwa
jws
kind-of
lcid
lodash
lodash.camelcase
lodash.clone
lodash.includes
lodash.isboolean
lodash.isinteger
lodash.isnumber
lodash.isplainobject
lodash.isstring
lodash.merge
lodash.once
log-driver
long
lru-cache
make-dir
map-cache
map-visit
media-typer
merge-descriptors
merge2
methmeth
methods
micromatch
mime
mime-db
mime-types
minimatch
mixin-deep
modelo
ms
nan
nanomatch
negotiator
node-forge
number-is-nan
oauth-sign
object-assign
object-copy
object-keys
object-visit
object.pick
on-finished
once
optjs
os-locale
parseurl
pascalcase
path-dirname
path-is-absolute
path-to-regexp
path-type
performance-now
pify
posix-character-classes
power-assert
power-assert-context-formatter
power-assert-context-reducer-ast
power-assert-context-traversal
power-assert-formatter
power-assert-renderer-assertion
power-assert-renderer-base
power-assert-renderer-comparison
power-assert-renderer-diagram
power-assert-renderer-file
power-assert-util-string-width
process-nextick-args
protobufjs
proxy-addr
pseudomap
psl
pump
pumpify
punycode
qs
range-parser
raw-body
readable-stream
regex-not
repeat-element
repeat-string
request
resolve-url
ret
retry-axios
retry-request
safe-buffer
safe-regex
safer-buffer
send
serve-static
set-value
setprototypeof
signal-exit
slash
snakeize
snapdragon
snapdragon-node
snapdragon-util
source-map
source-map-resolve
source-map-url
split-array-stream
split-string
sshpk
static-extend
statuses
stream-events
stream-shift
string-format-obj
string-width
string_decoder
stringifier
strip-ansi
stubs
through2
to-object-path
to-regex
to-regex-range
tough-cookie
traverse
tslib
tunnel-agent
tweetnacl
type-is
type-name
typedarray
union-value
unique-string
universal-deep-strict-equal
unpipe
unset-value
uri-js
urix
use
util-deprecate
utils-merge
uuid
vary
verror
websocket-driver
websocket-extensions
window-size
wrap-ansi
wrappy
write-file-atomic
xdg-basedir
xmlhttprequest
xtend
y18n
yallist
yargs
index.js
package-lock.json
package.json
node_modules
public
.firebaserc
.gitignore
.runtimeconfig.json
firebase.json
firestore.indexes.json
firestore.rules
package-lock.json
.gitattributes
.gitignore
170 lines
6.3 KiB
JavaScript
170 lines
6.3 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = autoInject;
|
|
|
|
var _auto = require('./auto');
|
|
|
|
var _auto2 = _interopRequireDefault(_auto);
|
|
|
|
var _baseForOwn = require('lodash/_baseForOwn');
|
|
|
|
var _baseForOwn2 = _interopRequireDefault(_baseForOwn);
|
|
|
|
var _arrayMap = require('lodash/_arrayMap');
|
|
|
|
var _arrayMap2 = _interopRequireDefault(_arrayMap);
|
|
|
|
var _isArray = require('lodash/isArray');
|
|
|
|
var _isArray2 = _interopRequireDefault(_isArray);
|
|
|
|
var _trim = require('lodash/trim');
|
|
|
|
var _trim2 = _interopRequireDefault(_trim);
|
|
|
|
var _wrapAsync = require('./internal/wrapAsync');
|
|
|
|
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
var FN_ARGS = /^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m;
|
|
var FN_ARG_SPLIT = /,/;
|
|
var FN_ARG = /(=.+)?(\s*)$/;
|
|
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
|
|
|
|
function parseParams(func) {
|
|
func = func.toString().replace(STRIP_COMMENTS, '');
|
|
func = func.match(FN_ARGS)[2].replace(' ', '');
|
|
func = func ? func.split(FN_ARG_SPLIT) : [];
|
|
func = func.map(function (arg) {
|
|
return (0, _trim2.default)(arg.replace(FN_ARG, ''));
|
|
});
|
|
return func;
|
|
}
|
|
|
|
/**
|
|
* A dependency-injected version of the [async.auto]{@link module:ControlFlow.auto} function. Dependent
|
|
* tasks are specified as parameters to the function, after the usual callback
|
|
* parameter, with the parameter names matching the names of the tasks it
|
|
* depends on. This can provide even more readable task graphs which can be
|
|
* easier to maintain.
|
|
*
|
|
* If a final callback is specified, the task results are similarly injected,
|
|
* specified as named parameters after the initial error parameter.
|
|
*
|
|
* The autoInject function is purely syntactic sugar and its semantics are
|
|
* otherwise equivalent to [async.auto]{@link module:ControlFlow.auto}.
|
|
*
|
|
* @name autoInject
|
|
* @static
|
|
* @memberOf module:ControlFlow
|
|
* @method
|
|
* @see [async.auto]{@link module:ControlFlow.auto}
|
|
* @category Control Flow
|
|
* @param {Object} tasks - An object, each of whose properties is an {@link AsyncFunction} of
|
|
* the form 'func([dependencies...], callback). The object's key of a property
|
|
* serves as the name of the task defined by that property, i.e. can be used
|
|
* when specifying requirements for other tasks.
|
|
* * The `callback` parameter is a `callback(err, result)` which must be called
|
|
* when finished, passing an `error` (which can be `null`) and the result of
|
|
* the function's execution. The remaining parameters name other tasks on
|
|
* which the task is dependent, and the results from those tasks are the
|
|
* arguments of those parameters.
|
|
* @param {Function} [callback] - An optional callback which is called when all
|
|
* the tasks have been completed. It receives the `err` argument if any `tasks`
|
|
* pass an error to their callback, and a `results` object with any completed
|
|
* task results, similar to `auto`.
|
|
* @example
|
|
*
|
|
* // The example from `auto` can be rewritten as follows:
|
|
* async.autoInject({
|
|
* get_data: function(callback) {
|
|
* // async code to get some data
|
|
* callback(null, 'data', 'converted to array');
|
|
* },
|
|
* make_folder: function(callback) {
|
|
* // async code to create a directory to store a file in
|
|
* // this is run at the same time as getting the data
|
|
* callback(null, 'folder');
|
|
* },
|
|
* write_file: function(get_data, make_folder, callback) {
|
|
* // once there is some data and the directory exists,
|
|
* // write the data to a file in the directory
|
|
* callback(null, 'filename');
|
|
* },
|
|
* email_link: function(write_file, callback) {
|
|
* // once the file is written let's email a link to it...
|
|
* // write_file contains the filename returned by write_file.
|
|
* callback(null, {'file':write_file, 'email':'user@example.com'});
|
|
* }
|
|
* }, function(err, results) {
|
|
* console.log('err = ', err);
|
|
* console.log('email_link = ', results.email_link);
|
|
* });
|
|
*
|
|
* // If you are using a JS minifier that mangles parameter names, `autoInject`
|
|
* // will not work with plain functions, since the parameter names will be
|
|
* // collapsed to a single letter identifier. To work around this, you can
|
|
* // explicitly specify the names of the parameters your task function needs
|
|
* // in an array, similar to Angular.js dependency injection.
|
|
*
|
|
* // This still has an advantage over plain `auto`, since the results a task
|
|
* // depends on are still spread into arguments.
|
|
* async.autoInject({
|
|
* //...
|
|
* write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) {
|
|
* callback(null, 'filename');
|
|
* }],
|
|
* email_link: ['write_file', function(write_file, callback) {
|
|
* callback(null, {'file':write_file, 'email':'user@example.com'});
|
|
* }]
|
|
* //...
|
|
* }, function(err, results) {
|
|
* console.log('err = ', err);
|
|
* console.log('email_link = ', results.email_link);
|
|
* });
|
|
*/
|
|
function autoInject(tasks, callback) {
|
|
var newTasks = {};
|
|
|
|
(0, _baseForOwn2.default)(tasks, function (taskFn, key) {
|
|
var params;
|
|
var fnIsAsync = (0, _wrapAsync.isAsync)(taskFn);
|
|
var hasNoDeps = !fnIsAsync && taskFn.length === 1 || fnIsAsync && taskFn.length === 0;
|
|
|
|
if ((0, _isArray2.default)(taskFn)) {
|
|
params = taskFn.slice(0, -1);
|
|
taskFn = taskFn[taskFn.length - 1];
|
|
|
|
newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn);
|
|
} else if (hasNoDeps) {
|
|
// no dependencies, use the function as-is
|
|
newTasks[key] = taskFn;
|
|
} else {
|
|
params = parseParams(taskFn);
|
|
if (taskFn.length === 0 && !fnIsAsync && params.length === 0) {
|
|
throw new Error("autoInject task functions require explicit parameters.");
|
|
}
|
|
|
|
// remove callback param
|
|
if (!fnIsAsync) params.pop();
|
|
|
|
newTasks[key] = params.concat(newTask);
|
|
}
|
|
|
|
function newTask(results, taskCb) {
|
|
var newArgs = (0, _arrayMap2.default)(params, function (name) {
|
|
return results[name];
|
|
});
|
|
newArgs.push(taskCb);
|
|
(0, _wrapAsync2.default)(taskFn).apply(null, newArgs);
|
|
}
|
|
});
|
|
|
|
(0, _auto2.default)(newTasks, callback);
|
|
}
|
|
module.exports = exports['default']; |