@nocobase/plugin-backup-restore 1.6.20 → 1.6.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/d0c15e9119b8e3d3.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +5 -5
- package/dist/node_modules/@hapi/topo/package.json +1 -1
- package/dist/node_modules/archiver/index.js +2 -2
- package/dist/node_modules/archiver/node_modules/async/all.js +119 -0
- package/dist/node_modules/archiver/node_modules/async/allLimit.js +46 -0
- package/dist/node_modules/archiver/node_modules/async/allSeries.js +45 -0
- package/dist/node_modules/archiver/node_modules/async/any.js +122 -0
- package/dist/node_modules/archiver/node_modules/async/anyLimit.js +47 -0
- package/dist/node_modules/archiver/node_modules/async/anySeries.js +46 -0
- package/dist/node_modules/archiver/node_modules/async/apply.js +11 -0
- package/dist/node_modules/archiver/node_modules/async/applyEach.js +57 -0
- package/dist/node_modules/archiver/node_modules/async/applyEachSeries.js +37 -0
- package/dist/node_modules/archiver/node_modules/async/asyncify.js +118 -0
- package/dist/node_modules/archiver/node_modules/async/auto.js +333 -0
- package/dist/node_modules/archiver/node_modules/async/autoInject.js +182 -0
- package/dist/node_modules/archiver/node_modules/async/bower.json +17 -0
- package/dist/node_modules/archiver/node_modules/async/cargo.js +63 -0
- package/dist/node_modules/archiver/node_modules/async/cargoQueue.js +71 -0
- package/dist/node_modules/archiver/node_modules/async/compose.js +55 -0
- package/dist/node_modules/archiver/node_modules/async/concat.js +115 -0
- package/dist/node_modules/archiver/node_modules/async/concatLimit.js +60 -0
- package/dist/node_modules/archiver/node_modules/async/concatSeries.js +41 -0
- package/dist/node_modules/archiver/node_modules/async/constant.js +14 -0
- package/dist/node_modules/archiver/node_modules/async/detect.js +96 -0
- package/dist/node_modules/archiver/node_modules/async/detectLimit.js +48 -0
- package/dist/node_modules/archiver/node_modules/async/detectSeries.js +47 -0
- package/dist/node_modules/archiver/node_modules/async/dir.js +43 -0
- package/dist/node_modules/archiver/node_modules/async/dist/async.js +6062 -0
- package/dist/node_modules/archiver/node_modules/async/dist/async.min.js +1 -0
- package/dist/node_modules/archiver/node_modules/async/doDuring.js +68 -0
- package/dist/node_modules/archiver/node_modules/async/doUntil.js +46 -0
- package/dist/node_modules/archiver/node_modules/async/doWhilst.js +68 -0
- package/dist/node_modules/archiver/node_modules/async/during.js +78 -0
- package/dist/node_modules/archiver/node_modules/async/each.js +129 -0
- package/dist/node_modules/archiver/node_modules/async/eachLimit.js +50 -0
- package/dist/node_modules/archiver/node_modules/async/eachOf.js +185 -0
- package/dist/node_modules/archiver/node_modules/async/eachOfLimit.js +47 -0
- package/dist/node_modules/archiver/node_modules/async/eachOfSeries.js +39 -0
- package/dist/node_modules/archiver/node_modules/async/eachSeries.js +44 -0
- package/dist/node_modules/archiver/node_modules/async/ensureAsync.js +67 -0
- package/dist/node_modules/archiver/node_modules/async/every.js +119 -0
- package/dist/node_modules/archiver/node_modules/async/everyLimit.js +46 -0
- package/dist/node_modules/archiver/node_modules/async/everySeries.js +45 -0
- package/dist/node_modules/archiver/node_modules/async/filter.js +93 -0
- package/dist/node_modules/archiver/node_modules/async/filterLimit.js +45 -0
- package/dist/node_modules/archiver/node_modules/async/filterSeries.js +43 -0
- package/dist/node_modules/archiver/node_modules/async/find.js +96 -0
- package/dist/node_modules/archiver/node_modules/async/findLimit.js +48 -0
- package/dist/node_modules/archiver/node_modules/async/findSeries.js +47 -0
- package/dist/node_modules/archiver/node_modules/async/flatMap.js +115 -0
- package/dist/node_modules/archiver/node_modules/async/flatMapLimit.js +60 -0
- package/dist/node_modules/archiver/node_modules/async/flatMapSeries.js +41 -0
- package/dist/node_modules/archiver/node_modules/async/foldl.js +153 -0
- package/dist/node_modules/archiver/node_modules/async/foldr.js +41 -0
- package/dist/node_modules/archiver/node_modules/async/forEach.js +129 -0
- package/dist/node_modules/archiver/node_modules/async/forEachLimit.js +50 -0
- package/dist/node_modules/archiver/node_modules/async/forEachOf.js +185 -0
- package/dist/node_modules/archiver/node_modules/async/forEachOfLimit.js +47 -0
- package/dist/node_modules/archiver/node_modules/async/forEachOfSeries.js +39 -0
- package/dist/node_modules/archiver/node_modules/async/forEachSeries.js +44 -0
- package/dist/node_modules/archiver/node_modules/async/forever.js +68 -0
- package/dist/node_modules/archiver/node_modules/async/groupBy.js +108 -0
- package/dist/node_modules/archiver/node_modules/async/groupByLimit.js +71 -0
- package/dist/node_modules/archiver/node_modules/async/groupBySeries.js +36 -0
- package/dist/node_modules/archiver/node_modules/async/index.js +588 -0
- package/dist/node_modules/archiver/node_modules/async/inject.js +153 -0
- package/dist/node_modules/archiver/node_modules/async/internal/DoublyLinkedList.js +92 -0
- package/dist/node_modules/archiver/node_modules/async/internal/Heap.js +120 -0
- package/dist/node_modules/archiver/node_modules/async/internal/applyEach.js +29 -0
- package/dist/node_modules/archiver/node_modules/async/internal/asyncEachOfLimit.js +75 -0
- package/dist/node_modules/archiver/node_modules/async/internal/awaitify.js +28 -0
- package/dist/node_modules/archiver/node_modules/async/internal/breakLoop.js +10 -0
- package/dist/node_modules/archiver/node_modules/async/internal/consoleFunc.js +31 -0
- package/dist/node_modules/archiver/node_modules/async/internal/createTester.js +40 -0
- package/dist/node_modules/archiver/node_modules/async/internal/eachOfLimit.js +90 -0
- package/dist/node_modules/archiver/node_modules/async/internal/filter.js +55 -0
- package/dist/node_modules/archiver/node_modules/async/internal/getIterator.js +11 -0
- package/dist/node_modules/archiver/node_modules/async/internal/initialParams.js +14 -0
- package/dist/node_modules/archiver/node_modules/async/internal/isArrayLike.js +10 -0
- package/dist/node_modules/archiver/node_modules/async/internal/iterator.js +57 -0
- package/dist/node_modules/archiver/node_modules/async/internal/map.js +30 -0
- package/dist/node_modules/archiver/node_modules/async/internal/once.js +17 -0
- package/dist/node_modules/archiver/node_modules/async/internal/onlyOnce.js +15 -0
- package/dist/node_modules/archiver/node_modules/async/internal/parallel.js +34 -0
- package/dist/node_modules/archiver/node_modules/async/internal/promiseCallback.js +23 -0
- package/dist/node_modules/archiver/node_modules/async/internal/queue.js +294 -0
- package/dist/node_modules/archiver/node_modules/async/internal/range.js +14 -0
- package/dist/node_modules/archiver/node_modules/async/internal/reject.js +26 -0
- package/dist/node_modules/archiver/node_modules/async/internal/setImmediate.js +34 -0
- package/dist/node_modules/archiver/node_modules/async/internal/withoutIndex.js +10 -0
- package/dist/node_modules/archiver/node_modules/async/internal/wrapAsync.js +34 -0
- package/dist/node_modules/archiver/node_modules/async/log.js +41 -0
- package/dist/node_modules/archiver/node_modules/async/map.js +142 -0
- package/dist/node_modules/archiver/node_modules/async/mapLimit.js +45 -0
- package/dist/node_modules/archiver/node_modules/async/mapSeries.js +44 -0
- package/dist/node_modules/archiver/node_modules/async/mapValues.js +152 -0
- package/dist/node_modules/archiver/node_modules/async/mapValuesLimit.js +61 -0
- package/dist/node_modules/archiver/node_modules/async/mapValuesSeries.js +37 -0
- package/dist/node_modules/archiver/node_modules/async/memoize.js +91 -0
- package/dist/node_modules/archiver/node_modules/async/nextTick.js +52 -0
- package/dist/node_modules/archiver/node_modules/async/package.json +75 -0
- package/dist/node_modules/archiver/node_modules/async/parallel.js +180 -0
- package/dist/node_modules/archiver/node_modules/async/parallelLimit.js +41 -0
- package/dist/node_modules/archiver/node_modules/async/priorityQueue.js +60 -0
- package/dist/node_modules/archiver/node_modules/async/queue.js +24 -0
- package/dist/node_modules/archiver/node_modules/async/race.js +67 -0
- package/dist/node_modules/archiver/node_modules/async/reduce.js +153 -0
- package/dist/node_modules/archiver/node_modules/async/reduceRight.js +41 -0
- package/dist/node_modules/archiver/node_modules/async/reflect.js +78 -0
- package/dist/node_modules/archiver/node_modules/async/reflectAll.js +93 -0
- package/dist/node_modules/archiver/node_modules/async/reject.js +87 -0
- package/dist/node_modules/archiver/node_modules/async/rejectLimit.js +45 -0
- package/dist/node_modules/archiver/node_modules/async/rejectSeries.js +43 -0
- package/dist/node_modules/archiver/node_modules/async/retry.js +159 -0
- package/dist/node_modules/archiver/node_modules/async/retryable.js +77 -0
- package/dist/node_modules/archiver/node_modules/async/select.js +93 -0
- package/dist/node_modules/archiver/node_modules/async/selectLimit.js +45 -0
- package/dist/node_modules/archiver/node_modules/async/selectSeries.js +43 -0
- package/dist/node_modules/archiver/node_modules/async/seq.js +79 -0
- package/dist/node_modules/archiver/node_modules/async/series.js +186 -0
- package/dist/node_modules/archiver/node_modules/async/setImmediate.js +45 -0
- package/dist/node_modules/archiver/node_modules/async/some.js +122 -0
- package/dist/node_modules/archiver/node_modules/async/someLimit.js +47 -0
- package/dist/node_modules/archiver/node_modules/async/someSeries.js +46 -0
- package/dist/node_modules/archiver/node_modules/async/sortBy.js +190 -0
- package/dist/node_modules/archiver/node_modules/async/timeout.js +89 -0
- package/dist/node_modules/archiver/node_modules/async/times.js +50 -0
- package/dist/node_modules/archiver/node_modules/async/timesLimit.js +43 -0
- package/dist/node_modules/archiver/node_modules/async/timesSeries.js +32 -0
- package/dist/node_modules/archiver/node_modules/async/transform.js +173 -0
- package/dist/node_modules/archiver/node_modules/async/tryEach.js +78 -0
- package/dist/node_modules/archiver/node_modules/async/unmemoize.js +25 -0
- package/dist/node_modules/archiver/node_modules/async/until.js +61 -0
- package/dist/node_modules/archiver/node_modules/async/waterfall.js +105 -0
- package/dist/node_modules/archiver/node_modules/async/whilst.js +78 -0
- package/dist/node_modules/archiver/node_modules/async/wrapSync.js +118 -0
- package/dist/node_modules/archiver/package.json +1 -1
- package/dist/node_modules/decompress/package.json +1 -1
- package/dist/node_modules/mkdirp/package.json +1 -1
- package/dist/node_modules/moment/package.json +1 -1
- package/dist/node_modules/semver/bin/semver.js +7 -15
- package/dist/node_modules/semver/classes/range.js +28 -13
- package/dist/node_modules/semver/classes/semver.js +23 -7
- package/dist/node_modules/semver/functions/diff.js +5 -12
- package/dist/node_modules/semver/index.js +1 -1
- package/dist/node_modules/semver/internal/lrucache.js +40 -0
- package/dist/node_modules/semver/internal/re.js +2 -0
- package/dist/node_modules/semver/package.json +1 -1
- package/package.json +3 -3
- package/dist/client/04e68bac2ed0170d.js +0 -10
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = auto;
|
|
7
|
+
|
|
8
|
+
var _once = require('./internal/once.js');
|
|
9
|
+
|
|
10
|
+
var _once2 = _interopRequireDefault(_once);
|
|
11
|
+
|
|
12
|
+
var _onlyOnce = require('./internal/onlyOnce.js');
|
|
13
|
+
|
|
14
|
+
var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
|
|
15
|
+
|
|
16
|
+
var _wrapAsync = require('./internal/wrapAsync.js');
|
|
17
|
+
|
|
18
|
+
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
|
|
19
|
+
|
|
20
|
+
var _promiseCallback = require('./internal/promiseCallback.js');
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Determines the best order for running the {@link AsyncFunction}s in `tasks`, based on
|
|
26
|
+
* their requirements. Each function can optionally depend on other functions
|
|
27
|
+
* being completed first, and each function is run as soon as its requirements
|
|
28
|
+
* are satisfied.
|
|
29
|
+
*
|
|
30
|
+
* If any of the {@link AsyncFunction}s pass an error to their callback, the `auto` sequence
|
|
31
|
+
* will stop. Further tasks will not execute (so any other functions depending
|
|
32
|
+
* on it will not run), and the main `callback` is immediately called with the
|
|
33
|
+
* error.
|
|
34
|
+
*
|
|
35
|
+
* {@link AsyncFunction}s also receive an object containing the results of functions which
|
|
36
|
+
* have completed so far as the first argument, if they have dependencies. If a
|
|
37
|
+
* task function has no dependencies, it will only be passed a callback.
|
|
38
|
+
*
|
|
39
|
+
* @name auto
|
|
40
|
+
* @static
|
|
41
|
+
* @memberOf module:ControlFlow
|
|
42
|
+
* @method
|
|
43
|
+
* @category Control Flow
|
|
44
|
+
* @param {Object} tasks - An object. Each of its properties is either a
|
|
45
|
+
* function or an array of requirements, with the {@link AsyncFunction} itself the last item
|
|
46
|
+
* in the array. The object's key of a property serves as the name of the task
|
|
47
|
+
* defined by that property, i.e. can be used when specifying requirements for
|
|
48
|
+
* other tasks. The function receives one or two arguments:
|
|
49
|
+
* * a `results` object, containing the results of the previously executed
|
|
50
|
+
* functions, only passed if the task has any dependencies,
|
|
51
|
+
* * a `callback(err, result)` function, which must be called when finished,
|
|
52
|
+
* passing an `error` (which can be `null`) and the result of the function's
|
|
53
|
+
* execution.
|
|
54
|
+
* @param {number} [concurrency=Infinity] - An optional `integer` for
|
|
55
|
+
* determining the maximum number of tasks that can be run in parallel. By
|
|
56
|
+
* default, as many as possible.
|
|
57
|
+
* @param {Function} [callback] - An optional callback which is called when all
|
|
58
|
+
* the tasks have been completed. It receives the `err` argument if any `tasks`
|
|
59
|
+
* pass an error to their callback. Results are always returned; however, if an
|
|
60
|
+
* error occurs, no further `tasks` will be performed, and the results object
|
|
61
|
+
* will only contain partial results. Invoked with (err, results).
|
|
62
|
+
* @returns {Promise} a promise, if a callback is not passed
|
|
63
|
+
* @example
|
|
64
|
+
*
|
|
65
|
+
* //Using Callbacks
|
|
66
|
+
* async.auto({
|
|
67
|
+
* get_data: function(callback) {
|
|
68
|
+
* // async code to get some data
|
|
69
|
+
* callback(null, 'data', 'converted to array');
|
|
70
|
+
* },
|
|
71
|
+
* make_folder: function(callback) {
|
|
72
|
+
* // async code to create a directory to store a file in
|
|
73
|
+
* // this is run at the same time as getting the data
|
|
74
|
+
* callback(null, 'folder');
|
|
75
|
+
* },
|
|
76
|
+
* write_file: ['get_data', 'make_folder', function(results, callback) {
|
|
77
|
+
* // once there is some data and the directory exists,
|
|
78
|
+
* // write the data to a file in the directory
|
|
79
|
+
* callback(null, 'filename');
|
|
80
|
+
* }],
|
|
81
|
+
* email_link: ['write_file', function(results, callback) {
|
|
82
|
+
* // once the file is written let's email a link to it...
|
|
83
|
+
* callback(null, {'file':results.write_file, 'email':'user@example.com'});
|
|
84
|
+
* }]
|
|
85
|
+
* }, function(err, results) {
|
|
86
|
+
* if (err) {
|
|
87
|
+
* console.log('err = ', err);
|
|
88
|
+
* }
|
|
89
|
+
* console.log('results = ', results);
|
|
90
|
+
* // results = {
|
|
91
|
+
* // get_data: ['data', 'converted to array']
|
|
92
|
+
* // make_folder; 'folder',
|
|
93
|
+
* // write_file: 'filename'
|
|
94
|
+
* // email_link: { file: 'filename', email: 'user@example.com' }
|
|
95
|
+
* // }
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
98
|
+
* //Using Promises
|
|
99
|
+
* async.auto({
|
|
100
|
+
* get_data: function(callback) {
|
|
101
|
+
* console.log('in get_data');
|
|
102
|
+
* // async code to get some data
|
|
103
|
+
* callback(null, 'data', 'converted to array');
|
|
104
|
+
* },
|
|
105
|
+
* make_folder: function(callback) {
|
|
106
|
+
* console.log('in make_folder');
|
|
107
|
+
* // async code to create a directory to store a file in
|
|
108
|
+
* // this is run at the same time as getting the data
|
|
109
|
+
* callback(null, 'folder');
|
|
110
|
+
* },
|
|
111
|
+
* write_file: ['get_data', 'make_folder', function(results, callback) {
|
|
112
|
+
* // once there is some data and the directory exists,
|
|
113
|
+
* // write the data to a file in the directory
|
|
114
|
+
* callback(null, 'filename');
|
|
115
|
+
* }],
|
|
116
|
+
* email_link: ['write_file', function(results, callback) {
|
|
117
|
+
* // once the file is written let's email a link to it...
|
|
118
|
+
* callback(null, {'file':results.write_file, 'email':'user@example.com'});
|
|
119
|
+
* }]
|
|
120
|
+
* }).then(results => {
|
|
121
|
+
* console.log('results = ', results);
|
|
122
|
+
* // results = {
|
|
123
|
+
* // get_data: ['data', 'converted to array']
|
|
124
|
+
* // make_folder; 'folder',
|
|
125
|
+
* // write_file: 'filename'
|
|
126
|
+
* // email_link: { file: 'filename', email: 'user@example.com' }
|
|
127
|
+
* // }
|
|
128
|
+
* }).catch(err => {
|
|
129
|
+
* console.log('err = ', err);
|
|
130
|
+
* });
|
|
131
|
+
*
|
|
132
|
+
* //Using async/await
|
|
133
|
+
* async () => {
|
|
134
|
+
* try {
|
|
135
|
+
* let results = await async.auto({
|
|
136
|
+
* get_data: function(callback) {
|
|
137
|
+
* // async code to get some data
|
|
138
|
+
* callback(null, 'data', 'converted to array');
|
|
139
|
+
* },
|
|
140
|
+
* make_folder: function(callback) {
|
|
141
|
+
* // async code to create a directory to store a file in
|
|
142
|
+
* // this is run at the same time as getting the data
|
|
143
|
+
* callback(null, 'folder');
|
|
144
|
+
* },
|
|
145
|
+
* write_file: ['get_data', 'make_folder', function(results, callback) {
|
|
146
|
+
* // once there is some data and the directory exists,
|
|
147
|
+
* // write the data to a file in the directory
|
|
148
|
+
* callback(null, 'filename');
|
|
149
|
+
* }],
|
|
150
|
+
* email_link: ['write_file', function(results, callback) {
|
|
151
|
+
* // once the file is written let's email a link to it...
|
|
152
|
+
* callback(null, {'file':results.write_file, 'email':'user@example.com'});
|
|
153
|
+
* }]
|
|
154
|
+
* });
|
|
155
|
+
* console.log('results = ', results);
|
|
156
|
+
* // results = {
|
|
157
|
+
* // get_data: ['data', 'converted to array']
|
|
158
|
+
* // make_folder; 'folder',
|
|
159
|
+
* // write_file: 'filename'
|
|
160
|
+
* // email_link: { file: 'filename', email: 'user@example.com' }
|
|
161
|
+
* // }
|
|
162
|
+
* }
|
|
163
|
+
* catch (err) {
|
|
164
|
+
* console.log(err);
|
|
165
|
+
* }
|
|
166
|
+
* }
|
|
167
|
+
*
|
|
168
|
+
*/
|
|
169
|
+
function auto(tasks, concurrency, callback) {
|
|
170
|
+
if (typeof concurrency !== 'number') {
|
|
171
|
+
// concurrency is optional, shift the args.
|
|
172
|
+
callback = concurrency;
|
|
173
|
+
concurrency = null;
|
|
174
|
+
}
|
|
175
|
+
callback = (0, _once2.default)(callback || (0, _promiseCallback.promiseCallback)());
|
|
176
|
+
var numTasks = Object.keys(tasks).length;
|
|
177
|
+
if (!numTasks) {
|
|
178
|
+
return callback(null);
|
|
179
|
+
}
|
|
180
|
+
if (!concurrency) {
|
|
181
|
+
concurrency = numTasks;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
var results = {};
|
|
185
|
+
var runningTasks = 0;
|
|
186
|
+
var canceled = false;
|
|
187
|
+
var hasError = false;
|
|
188
|
+
|
|
189
|
+
var listeners = Object.create(null);
|
|
190
|
+
|
|
191
|
+
var readyTasks = [];
|
|
192
|
+
|
|
193
|
+
// for cycle detection:
|
|
194
|
+
var readyToCheck = []; // tasks that have been identified as reachable
|
|
195
|
+
// without the possibility of returning to an ancestor task
|
|
196
|
+
var uncheckedDependencies = {};
|
|
197
|
+
|
|
198
|
+
Object.keys(tasks).forEach(key => {
|
|
199
|
+
var task = tasks[key];
|
|
200
|
+
if (!Array.isArray(task)) {
|
|
201
|
+
// no dependencies
|
|
202
|
+
enqueueTask(key, [task]);
|
|
203
|
+
readyToCheck.push(key);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
var dependencies = task.slice(0, task.length - 1);
|
|
208
|
+
var remainingDependencies = dependencies.length;
|
|
209
|
+
if (remainingDependencies === 0) {
|
|
210
|
+
enqueueTask(key, task);
|
|
211
|
+
readyToCheck.push(key);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
uncheckedDependencies[key] = remainingDependencies;
|
|
215
|
+
|
|
216
|
+
dependencies.forEach(dependencyName => {
|
|
217
|
+
if (!tasks[dependencyName]) {
|
|
218
|
+
throw new Error('async.auto task `' + key + '` has a non-existent dependency `' + dependencyName + '` in ' + dependencies.join(', '));
|
|
219
|
+
}
|
|
220
|
+
addListener(dependencyName, () => {
|
|
221
|
+
remainingDependencies--;
|
|
222
|
+
if (remainingDependencies === 0) {
|
|
223
|
+
enqueueTask(key, task);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
checkForDeadlocks();
|
|
230
|
+
processQueue();
|
|
231
|
+
|
|
232
|
+
function enqueueTask(key, task) {
|
|
233
|
+
readyTasks.push(() => runTask(key, task));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function processQueue() {
|
|
237
|
+
if (canceled) return;
|
|
238
|
+
if (readyTasks.length === 0 && runningTasks === 0) {
|
|
239
|
+
return callback(null, results);
|
|
240
|
+
}
|
|
241
|
+
while (readyTasks.length && runningTasks < concurrency) {
|
|
242
|
+
var run = readyTasks.shift();
|
|
243
|
+
run();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function addListener(taskName, fn) {
|
|
248
|
+
var taskListeners = listeners[taskName];
|
|
249
|
+
if (!taskListeners) {
|
|
250
|
+
taskListeners = listeners[taskName] = [];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
taskListeners.push(fn);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function taskComplete(taskName) {
|
|
257
|
+
var taskListeners = listeners[taskName] || [];
|
|
258
|
+
taskListeners.forEach(fn => fn());
|
|
259
|
+
processQueue();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function runTask(key, task) {
|
|
263
|
+
if (hasError) return;
|
|
264
|
+
|
|
265
|
+
var taskCallback = (0, _onlyOnce2.default)((err, ...result) => {
|
|
266
|
+
runningTasks--;
|
|
267
|
+
if (err === false) {
|
|
268
|
+
canceled = true;
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (result.length < 2) {
|
|
272
|
+
[result] = result;
|
|
273
|
+
}
|
|
274
|
+
if (err) {
|
|
275
|
+
var safeResults = {};
|
|
276
|
+
Object.keys(results).forEach(rkey => {
|
|
277
|
+
safeResults[rkey] = results[rkey];
|
|
278
|
+
});
|
|
279
|
+
safeResults[key] = result;
|
|
280
|
+
hasError = true;
|
|
281
|
+
listeners = Object.create(null);
|
|
282
|
+
if (canceled) return;
|
|
283
|
+
callback(err, safeResults);
|
|
284
|
+
} else {
|
|
285
|
+
results[key] = result;
|
|
286
|
+
taskComplete(key);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
runningTasks++;
|
|
291
|
+
var taskFn = (0, _wrapAsync2.default)(task[task.length - 1]);
|
|
292
|
+
if (task.length > 1) {
|
|
293
|
+
taskFn(results, taskCallback);
|
|
294
|
+
} else {
|
|
295
|
+
taskFn(taskCallback);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function checkForDeadlocks() {
|
|
300
|
+
// Kahn's algorithm
|
|
301
|
+
// https://en.wikipedia.org/wiki/Topological_sorting#Kahn.27s_algorithm
|
|
302
|
+
// http://connalle.blogspot.com/2013/10/topological-sortingkahn-algorithm.html
|
|
303
|
+
var currentTask;
|
|
304
|
+
var counter = 0;
|
|
305
|
+
while (readyToCheck.length) {
|
|
306
|
+
currentTask = readyToCheck.pop();
|
|
307
|
+
counter++;
|
|
308
|
+
getDependents(currentTask).forEach(dependent => {
|
|
309
|
+
if (--uncheckedDependencies[dependent] === 0) {
|
|
310
|
+
readyToCheck.push(dependent);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (counter !== numTasks) {
|
|
316
|
+
throw new Error('async.auto cannot execute tasks due to a recursive dependency');
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function getDependents(taskName) {
|
|
321
|
+
var result = [];
|
|
322
|
+
Object.keys(tasks).forEach(key => {
|
|
323
|
+
const task = tasks[key];
|
|
324
|
+
if (Array.isArray(task) && task.indexOf(taskName) >= 0) {
|
|
325
|
+
result.push(key);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
return result;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return callback[_promiseCallback.PROMISE_SYMBOL];
|
|
332
|
+
}
|
|
333
|
+
module.exports = exports.default;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = autoInject;
|
|
7
|
+
|
|
8
|
+
var _auto = require('./auto.js');
|
|
9
|
+
|
|
10
|
+
var _auto2 = _interopRequireDefault(_auto);
|
|
11
|
+
|
|
12
|
+
var _wrapAsync = require('./internal/wrapAsync.js');
|
|
13
|
+
|
|
14
|
+
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
var FN_ARGS = /^(?:async\s+)?(?:function)?\s*\w*\s*\(\s*([^)]+)\s*\)(?:\s*{)/;
|
|
19
|
+
var ARROW_FN_ARGS = /^(?:async\s+)?\(?\s*([^)=]+)\s*\)?(?:\s*=>)/;
|
|
20
|
+
var FN_ARG_SPLIT = /,/;
|
|
21
|
+
var FN_ARG = /(=.+)?(\s*)$/;
|
|
22
|
+
|
|
23
|
+
function stripComments(string) {
|
|
24
|
+
let stripped = '';
|
|
25
|
+
let index = 0;
|
|
26
|
+
let endBlockComment = string.indexOf('*/');
|
|
27
|
+
while (index < string.length) {
|
|
28
|
+
if (string[index] === '/' && string[index + 1] === '/') {
|
|
29
|
+
// inline comment
|
|
30
|
+
let endIndex = string.indexOf('\n', index);
|
|
31
|
+
index = endIndex === -1 ? string.length : endIndex;
|
|
32
|
+
} else if (endBlockComment !== -1 && string[index] === '/' && string[index + 1] === '*') {
|
|
33
|
+
// block comment
|
|
34
|
+
let endIndex = string.indexOf('*/', index);
|
|
35
|
+
if (endIndex !== -1) {
|
|
36
|
+
index = endIndex + 2;
|
|
37
|
+
endBlockComment = string.indexOf('*/', index);
|
|
38
|
+
} else {
|
|
39
|
+
stripped += string[index];
|
|
40
|
+
index++;
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
stripped += string[index];
|
|
44
|
+
index++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return stripped;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function parseParams(func) {
|
|
51
|
+
const src = stripComments(func.toString());
|
|
52
|
+
let match = src.match(FN_ARGS);
|
|
53
|
+
if (!match) {
|
|
54
|
+
match = src.match(ARROW_FN_ARGS);
|
|
55
|
+
}
|
|
56
|
+
if (!match) throw new Error('could not parse args in autoInject\nSource:\n' + src);
|
|
57
|
+
let [, args] = match;
|
|
58
|
+
return args.replace(/\s/g, '').split(FN_ARG_SPLIT).map(arg => arg.replace(FN_ARG, '').trim());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A dependency-injected version of the [async.auto]{@link module:ControlFlow.auto} function. Dependent
|
|
63
|
+
* tasks are specified as parameters to the function, after the usual callback
|
|
64
|
+
* parameter, with the parameter names matching the names of the tasks it
|
|
65
|
+
* depends on. This can provide even more readable task graphs which can be
|
|
66
|
+
* easier to maintain.
|
|
67
|
+
*
|
|
68
|
+
* If a final callback is specified, the task results are similarly injected,
|
|
69
|
+
* specified as named parameters after the initial error parameter.
|
|
70
|
+
*
|
|
71
|
+
* The autoInject function is purely syntactic sugar and its semantics are
|
|
72
|
+
* otherwise equivalent to [async.auto]{@link module:ControlFlow.auto}.
|
|
73
|
+
*
|
|
74
|
+
* @name autoInject
|
|
75
|
+
* @static
|
|
76
|
+
* @memberOf module:ControlFlow
|
|
77
|
+
* @method
|
|
78
|
+
* @see [async.auto]{@link module:ControlFlow.auto}
|
|
79
|
+
* @category Control Flow
|
|
80
|
+
* @param {Object} tasks - An object, each of whose properties is an {@link AsyncFunction} of
|
|
81
|
+
* the form 'func([dependencies...], callback). The object's key of a property
|
|
82
|
+
* serves as the name of the task defined by that property, i.e. can be used
|
|
83
|
+
* when specifying requirements for other tasks.
|
|
84
|
+
* * The `callback` parameter is a `callback(err, result)` which must be called
|
|
85
|
+
* when finished, passing an `error` (which can be `null`) and the result of
|
|
86
|
+
* the function's execution. The remaining parameters name other tasks on
|
|
87
|
+
* which the task is dependent, and the results from those tasks are the
|
|
88
|
+
* arguments of those parameters.
|
|
89
|
+
* @param {Function} [callback] - An optional callback which is called when all
|
|
90
|
+
* the tasks have been completed. It receives the `err` argument if any `tasks`
|
|
91
|
+
* pass an error to their callback, and a `results` object with any completed
|
|
92
|
+
* task results, similar to `auto`.
|
|
93
|
+
* @returns {Promise} a promise, if no callback is passed
|
|
94
|
+
* @example
|
|
95
|
+
*
|
|
96
|
+
* // The example from `auto` can be rewritten as follows:
|
|
97
|
+
* async.autoInject({
|
|
98
|
+
* get_data: function(callback) {
|
|
99
|
+
* // async code to get some data
|
|
100
|
+
* callback(null, 'data', 'converted to array');
|
|
101
|
+
* },
|
|
102
|
+
* make_folder: function(callback) {
|
|
103
|
+
* // async code to create a directory to store a file in
|
|
104
|
+
* // this is run at the same time as getting the data
|
|
105
|
+
* callback(null, 'folder');
|
|
106
|
+
* },
|
|
107
|
+
* write_file: function(get_data, make_folder, callback) {
|
|
108
|
+
* // once there is some data and the directory exists,
|
|
109
|
+
* // write the data to a file in the directory
|
|
110
|
+
* callback(null, 'filename');
|
|
111
|
+
* },
|
|
112
|
+
* email_link: function(write_file, callback) {
|
|
113
|
+
* // once the file is written let's email a link to it...
|
|
114
|
+
* // write_file contains the filename returned by write_file.
|
|
115
|
+
* callback(null, {'file':write_file, 'email':'user@example.com'});
|
|
116
|
+
* }
|
|
117
|
+
* }, function(err, results) {
|
|
118
|
+
* console.log('err = ', err);
|
|
119
|
+
* console.log('email_link = ', results.email_link);
|
|
120
|
+
* });
|
|
121
|
+
*
|
|
122
|
+
* // If you are using a JS minifier that mangles parameter names, `autoInject`
|
|
123
|
+
* // will not work with plain functions, since the parameter names will be
|
|
124
|
+
* // collapsed to a single letter identifier. To work around this, you can
|
|
125
|
+
* // explicitly specify the names of the parameters your task function needs
|
|
126
|
+
* // in an array, similar to Angular.js dependency injection.
|
|
127
|
+
*
|
|
128
|
+
* // This still has an advantage over plain `auto`, since the results a task
|
|
129
|
+
* // depends on are still spread into arguments.
|
|
130
|
+
* async.autoInject({
|
|
131
|
+
* //...
|
|
132
|
+
* write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) {
|
|
133
|
+
* callback(null, 'filename');
|
|
134
|
+
* }],
|
|
135
|
+
* email_link: ['write_file', function(write_file, callback) {
|
|
136
|
+
* callback(null, {'file':write_file, 'email':'user@example.com'});
|
|
137
|
+
* }]
|
|
138
|
+
* //...
|
|
139
|
+
* }, function(err, results) {
|
|
140
|
+
* console.log('err = ', err);
|
|
141
|
+
* console.log('email_link = ', results.email_link);
|
|
142
|
+
* });
|
|
143
|
+
*/
|
|
144
|
+
function autoInject(tasks, callback) {
|
|
145
|
+
var newTasks = {};
|
|
146
|
+
|
|
147
|
+
Object.keys(tasks).forEach(key => {
|
|
148
|
+
var taskFn = tasks[key];
|
|
149
|
+
var params;
|
|
150
|
+
var fnIsAsync = (0, _wrapAsync.isAsync)(taskFn);
|
|
151
|
+
var hasNoDeps = !fnIsAsync && taskFn.length === 1 || fnIsAsync && taskFn.length === 0;
|
|
152
|
+
|
|
153
|
+
if (Array.isArray(taskFn)) {
|
|
154
|
+
params = [...taskFn];
|
|
155
|
+
taskFn = params.pop();
|
|
156
|
+
|
|
157
|
+
newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn);
|
|
158
|
+
} else if (hasNoDeps) {
|
|
159
|
+
// no dependencies, use the function as-is
|
|
160
|
+
newTasks[key] = taskFn;
|
|
161
|
+
} else {
|
|
162
|
+
params = parseParams(taskFn);
|
|
163
|
+
if (taskFn.length === 0 && !fnIsAsync && params.length === 0) {
|
|
164
|
+
throw new Error("autoInject task functions require explicit parameters.");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// remove callback param
|
|
168
|
+
if (!fnIsAsync) params.pop();
|
|
169
|
+
|
|
170
|
+
newTasks[key] = params.concat(newTask);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function newTask(results, taskCb) {
|
|
174
|
+
var newArgs = params.map(name => results[name]);
|
|
175
|
+
newArgs.push(taskCb);
|
|
176
|
+
(0, _wrapAsync2.default)(taskFn)(...newArgs);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return (0, _auto2.default)(newTasks, callback);
|
|
181
|
+
}
|
|
182
|
+
module.exports = exports.default;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = cargo;
|
|
7
|
+
|
|
8
|
+
var _queue = require('./internal/queue.js');
|
|
9
|
+
|
|
10
|
+
var _queue2 = _interopRequireDefault(_queue);
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates a `cargo` object with the specified payload. Tasks added to the
|
|
16
|
+
* cargo will be processed altogether (up to the `payload` limit). If the
|
|
17
|
+
* `worker` is in progress, the task is queued until it becomes available. Once
|
|
18
|
+
* the `worker` has completed some tasks, each callback of those tasks is
|
|
19
|
+
* called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966)
|
|
20
|
+
* for how `cargo` and `queue` work.
|
|
21
|
+
*
|
|
22
|
+
* While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers
|
|
23
|
+
* at a time, cargo passes an array of tasks to a single worker, repeating
|
|
24
|
+
* when the worker is finished.
|
|
25
|
+
*
|
|
26
|
+
* @name cargo
|
|
27
|
+
* @static
|
|
28
|
+
* @memberOf module:ControlFlow
|
|
29
|
+
* @method
|
|
30
|
+
* @see [async.queue]{@link module:ControlFlow.queue}
|
|
31
|
+
* @category Control Flow
|
|
32
|
+
* @param {AsyncFunction} worker - An asynchronous function for processing an array
|
|
33
|
+
* of queued tasks. Invoked with `(tasks, callback)`.
|
|
34
|
+
* @param {number} [payload=Infinity] - An optional `integer` for determining
|
|
35
|
+
* how many tasks should be processed per round; if omitted, the default is
|
|
36
|
+
* unlimited.
|
|
37
|
+
* @returns {module:ControlFlow.QueueObject} A cargo object to manage the tasks. Callbacks can
|
|
38
|
+
* attached as certain properties to listen for specific events during the
|
|
39
|
+
* lifecycle of the cargo and inner queue.
|
|
40
|
+
* @example
|
|
41
|
+
*
|
|
42
|
+
* // create a cargo object with payload 2
|
|
43
|
+
* var cargo = async.cargo(function(tasks, callback) {
|
|
44
|
+
* for (var i=0; i<tasks.length; i++) {
|
|
45
|
+
* console.log('hello ' + tasks[i].name);
|
|
46
|
+
* }
|
|
47
|
+
* callback();
|
|
48
|
+
* }, 2);
|
|
49
|
+
*
|
|
50
|
+
* // add some items
|
|
51
|
+
* cargo.push({name: 'foo'}, function(err) {
|
|
52
|
+
* console.log('finished processing foo');
|
|
53
|
+
* });
|
|
54
|
+
* cargo.push({name: 'bar'}, function(err) {
|
|
55
|
+
* console.log('finished processing bar');
|
|
56
|
+
* });
|
|
57
|
+
* await cargo.push({name: 'baz'});
|
|
58
|
+
* console.log('finished processing baz');
|
|
59
|
+
*/
|
|
60
|
+
function cargo(worker, payload) {
|
|
61
|
+
return (0, _queue2.default)(worker, 1, payload);
|
|
62
|
+
}
|
|
63
|
+
module.exports = exports.default;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = cargo;
|
|
7
|
+
|
|
8
|
+
var _queue = require('./internal/queue.js');
|
|
9
|
+
|
|
10
|
+
var _queue2 = _interopRequireDefault(_queue);
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates a `cargoQueue` object with the specified payload. Tasks added to the
|
|
16
|
+
* cargoQueue will be processed together (up to the `payload` limit) in `concurrency` parallel workers.
|
|
17
|
+
* If the all `workers` are in progress, the task is queued until one becomes available. Once
|
|
18
|
+
* a `worker` has completed some tasks, each callback of those tasks is
|
|
19
|
+
* called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966)
|
|
20
|
+
* for how `cargo` and `queue` work.
|
|
21
|
+
*
|
|
22
|
+
* While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers
|
|
23
|
+
* at a time, and [`cargo`]{@link module:ControlFlow.cargo} passes an array of tasks to a single worker,
|
|
24
|
+
* the cargoQueue passes an array of tasks to multiple parallel workers.
|
|
25
|
+
*
|
|
26
|
+
* @name cargoQueue
|
|
27
|
+
* @static
|
|
28
|
+
* @memberOf module:ControlFlow
|
|
29
|
+
* @method
|
|
30
|
+
* @see [async.queue]{@link module:ControlFlow.queue}
|
|
31
|
+
* @see [async.cargo]{@link module:ControlFLow.cargo}
|
|
32
|
+
* @category Control Flow
|
|
33
|
+
* @param {AsyncFunction} worker - An asynchronous function for processing an array
|
|
34
|
+
* of queued tasks. Invoked with `(tasks, callback)`.
|
|
35
|
+
* @param {number} [concurrency=1] - An `integer` for determining how many
|
|
36
|
+
* `worker` functions should be run in parallel. If omitted, the concurrency
|
|
37
|
+
* defaults to `1`. If the concurrency is `0`, an error is thrown.
|
|
38
|
+
* @param {number} [payload=Infinity] - An optional `integer` for determining
|
|
39
|
+
* how many tasks should be processed per round; if omitted, the default is
|
|
40
|
+
* unlimited.
|
|
41
|
+
* @returns {module:ControlFlow.QueueObject} A cargoQueue object to manage the tasks. Callbacks can
|
|
42
|
+
* attached as certain properties to listen for specific events during the
|
|
43
|
+
* lifecycle of the cargoQueue and inner queue.
|
|
44
|
+
* @example
|
|
45
|
+
*
|
|
46
|
+
* // create a cargoQueue object with payload 2 and concurrency 2
|
|
47
|
+
* var cargoQueue = async.cargoQueue(function(tasks, callback) {
|
|
48
|
+
* for (var i=0; i<tasks.length; i++) {
|
|
49
|
+
* console.log('hello ' + tasks[i].name);
|
|
50
|
+
* }
|
|
51
|
+
* callback();
|
|
52
|
+
* }, 2, 2);
|
|
53
|
+
*
|
|
54
|
+
* // add some items
|
|
55
|
+
* cargoQueue.push({name: 'foo'}, function(err) {
|
|
56
|
+
* console.log('finished processing foo');
|
|
57
|
+
* });
|
|
58
|
+
* cargoQueue.push({name: 'bar'}, function(err) {
|
|
59
|
+
* console.log('finished processing bar');
|
|
60
|
+
* });
|
|
61
|
+
* cargoQueue.push({name: 'baz'}, function(err) {
|
|
62
|
+
* console.log('finished processing baz');
|
|
63
|
+
* });
|
|
64
|
+
* cargoQueue.push({name: 'boo'}, function(err) {
|
|
65
|
+
* console.log('finished processing boo');
|
|
66
|
+
* });
|
|
67
|
+
*/
|
|
68
|
+
function cargo(worker, concurrency, payload) {
|
|
69
|
+
return (0, _queue2.default)(worker, concurrency, payload);
|
|
70
|
+
}
|
|
71
|
+
module.exports = exports.default;
|