collect-your-stuff 2.1.1 → 2.2.0
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/README.md +32 -3241
- package/browser/collect-your-stuff.js +1585 -1193
- package/browser/collect-your-stuff.min.js +1 -1
- package/dist/collections/arrayable/ArrayElement.d.ts +33 -38
- package/dist/collections/arrayable/ArrayElement.js +64 -66
- package/dist/collections/arrayable/Arrayable.d.ts +107 -122
- package/dist/collections/arrayable/Arrayable.js +208 -223
- package/dist/collections/doubly-linked-list/DoubleLinker.d.ts +45 -50
- package/dist/collections/doubly-linked-list/DoubleLinker.js +71 -73
- package/dist/collections/doubly-linked-list/DoublyLinkedList.d.ts +108 -125
- package/dist/collections/doubly-linked-list/DoublyLinkedList.js +310 -327
- package/dist/collections/linked-list/LinkedList.d.ts +110 -126
- package/dist/collections/linked-list/LinkedList.js +283 -296
- package/dist/collections/linked-list/Linker.d.ts +41 -46
- package/dist/collections/linked-list/Linker.js +82 -84
- package/dist/collections/linked-tree-list/LinkedTreeList.d.ts +140 -159
- package/dist/collections/linked-tree-list/LinkedTreeList.js +274 -294
- package/dist/collections/linked-tree-list/TreeLinker.d.ts +65 -71
- package/dist/collections/linked-tree-list/TreeLinker.js +91 -94
- package/dist/collections/queue/Queue.d.ts +55 -59
- package/dist/collections/queue/Queue.js +114 -119
- package/dist/collections/queue/Queueable.d.ts +74 -83
- package/dist/collections/queue/Queueable.js +142 -146
- package/dist/collections/queue/TaskQueue.d.ts +59 -68
- package/dist/collections/queue/TaskQueue.js +128 -137
- package/dist/collections/scoped-collection/ScopedCollection.d.ts +42 -0
- package/dist/collections/scoped-collection/ScopedCollection.js +81 -0
- package/dist/collections/scoped-collection/ScopedCollection.min.js +1 -0
- package/dist/collections/stack/Stack.d.ts +60 -64
- package/dist/collections/stack/Stack.js +122 -127
- package/dist/collections/stack/Stackable.d.ts +52 -59
- package/dist/collections/stack/Stackable.js +81 -85
- package/dist/collections/stack/TaskStack.d.ts +56 -65
- package/dist/collections/stack/TaskStack.js +98 -107
- package/dist/main.d.ts +4 -5
- package/dist/main.js +9 -5
- package/dist/main.min.js +1 -1
- package/dist/recipes/ArrayIterator.d.ts +20 -20
- package/dist/recipes/ArrayIterator.js +39 -39
- package/dist/recipes/DoubleLinkerIterator.d.ts +18 -18
- package/dist/recipes/DoubleLinkerIterator.js +33 -33
- package/dist/recipes/IsArrayable.d.ts +85 -105
- package/dist/recipes/IsArrayable.js +5 -5
- package/dist/recipes/IsDoubleLinker.d.ts +14 -14
- package/dist/recipes/IsDoubleLinker.js +5 -5
- package/dist/recipes/IsElement.d.ts +14 -14
- package/dist/recipes/IsElement.js +5 -5
- package/dist/recipes/IsLinker.d.ts +10 -10
- package/dist/recipes/IsLinker.js +5 -5
- package/dist/recipes/IsQueue.d.ts +32 -37
- package/dist/recipes/IsQueue.js +5 -5
- package/dist/recipes/IsScopedCollection.d.ts +27 -0
- package/dist/recipes/IsScopedCollection.js +5 -0
- package/dist/recipes/IsScopedCollection.min.js +1 -0
- package/dist/recipes/IsStack.d.ts +31 -36
- package/dist/recipes/IsStack.js +5 -5
- package/dist/recipes/IsTree.d.ts +11 -11
- package/dist/recipes/IsTree.js +5 -5
- package/dist/recipes/IsTreeNode.d.ts +29 -29
- package/dist/recipes/IsTreeNode.js +5 -5
- package/dist/recipes/LinkerIterator.d.ts +18 -18
- package/dist/recipes/LinkerIterator.js +33 -33
- package/dist/recipes/Runnable.d.ts +42 -55
- package/dist/recipes/Runnable.js +63 -69
- package/dist/recipes/TreeLinkerIterator.d.ts +20 -20
- package/dist/recipes/TreeLinkerIterator.js +36 -36
- package/dist/recipes/recipes.d.ts +12 -15
- package/dist/recipes/recipes.js +19 -22
- package/dist/services/parseTree.d.ts +8 -9
- package/dist/services/parseTree.js +23 -24
- package/dist/services/parseTreeNext.d.ts +16 -17
- package/dist/services/parseTreeNext.js +41 -42
- package/dist/services/services.d.ts +10 -13
- package/dist/services/services.js +19 -22
- package/package.json +4 -4
|
@@ -1,146 +1,142 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.Queueable = void 0
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Queueable represents a runnable entry in a queue.
|
|
10
|
-
* @extends Linker
|
|
11
|
-
*/
|
|
12
|
-
class Queueable {
|
|
13
|
-
/**
|
|
14
|
-
* Create a queueable item that can be used in a queue.
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
*/
|
|
20
|
-
constructor ({
|
|
21
|
-
task = null,
|
|
22
|
-
next = null,
|
|
23
|
-
ready = false
|
|
24
|
-
} = {}) {
|
|
25
|
-
/** The task (or data) this queueable holds. */
|
|
26
|
-
this.data = null
|
|
27
|
-
/** The queueable after this one, or null when this is the last. */
|
|
28
|
-
this.next = null
|
|
29
|
-
/** Whether this queueable has been run to completion. */
|
|
30
|
-
this.complete = false
|
|
31
|
-
/** Whether this queueable may run, or a function which answers that when asked. */
|
|
32
|
-
this.ready = false
|
|
33
|
-
/** Whether this queueable is running right now. */
|
|
34
|
-
this.running = false
|
|
35
|
-
this.classType = Queueable
|
|
36
|
-
this.data = task
|
|
37
|
-
this.next = next
|
|
38
|
-
this.complete = false
|
|
39
|
-
this.ready = ready
|
|
40
|
-
this.running = false
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Check ready state.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
context
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Set this queueable as completed.
|
|
66
|
-
* @param
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
*
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
* @param {IsLinker} [classType=Queueable] Provide the type of IsLinker to use.
|
|
144
|
-
* @returns {{head: Queueable, tail: Queueable}}
|
|
145
|
-
*/
|
|
146
|
-
Queueable.fromArray = (values = [], classType = Queueable) => _Linker.Linker.fromArray(values, classType)
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.Queueable = void 0
|
|
7
|
+
const _Linker = require('../linked-list/Linker')
|
|
8
|
+
/**
|
|
9
|
+
* Queueable represents a runnable entry in a queue.
|
|
10
|
+
* @extends Linker
|
|
11
|
+
*/
|
|
12
|
+
class Queueable {
|
|
13
|
+
/**
|
|
14
|
+
* Create a queueable item that can be used in a queue.
|
|
15
|
+
* @param queueableData The settings for the new queueable.
|
|
16
|
+
* @param queueableData.task The data to be stored in this queueable
|
|
17
|
+
* @param queueableData.next The reference to the next queueable if any
|
|
18
|
+
* @param queueableData.ready Indicate if the queueable is ready to run
|
|
19
|
+
*/
|
|
20
|
+
constructor ({
|
|
21
|
+
task = null,
|
|
22
|
+
next = null,
|
|
23
|
+
ready = false
|
|
24
|
+
} = {}) {
|
|
25
|
+
/** The task (or data) this queueable holds. */
|
|
26
|
+
this.data = null
|
|
27
|
+
/** The queueable after this one, or null when this is the last. */
|
|
28
|
+
this.next = null
|
|
29
|
+
/** Whether this queueable has been run to completion. */
|
|
30
|
+
this.complete = false
|
|
31
|
+
/** Whether this queueable may run, or a function which answers that when asked. */
|
|
32
|
+
this.ready = false
|
|
33
|
+
/** Whether this queueable is running right now. */
|
|
34
|
+
this.running = false
|
|
35
|
+
this.classType = Queueable
|
|
36
|
+
this.data = task
|
|
37
|
+
this.next = next
|
|
38
|
+
this.complete = false
|
|
39
|
+
this.ready = ready
|
|
40
|
+
this.running = false
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check ready state.
|
|
45
|
+
*/
|
|
46
|
+
get isReady () {
|
|
47
|
+
return typeof this.ready === 'function' ? this.ready() : this.ready
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Retrieve the data which should be formed as a task.
|
|
52
|
+
*/
|
|
53
|
+
get task () {
|
|
54
|
+
if (typeof this.data === 'function') {
|
|
55
|
+
return this.data
|
|
56
|
+
}
|
|
57
|
+
return complete => typeof complete === 'function'
|
|
58
|
+
? complete({
|
|
59
|
+
context: this.data
|
|
60
|
+
}).context
|
|
61
|
+
: this.data
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Set this queueable as completed.
|
|
66
|
+
* @param completeResponse The result to report for the task.
|
|
67
|
+
* @param completeResponse.success Indicate when the task failed (use false) or give a success message
|
|
68
|
+
* @param completeResponse.error Indicate a task was error-free (use false) or give an error message
|
|
69
|
+
* @param completeResponse.context Provide additional data in the response
|
|
70
|
+
*/
|
|
71
|
+
markCompleted ({
|
|
72
|
+
success = true,
|
|
73
|
+
error = false,
|
|
74
|
+
context = null
|
|
75
|
+
} = {}) {
|
|
76
|
+
this.complete = true
|
|
77
|
+
this.running = false
|
|
78
|
+
return {
|
|
79
|
+
success,
|
|
80
|
+
error,
|
|
81
|
+
context
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Intend to run the queued task when it is ready. If ready, mark this task as running and run the task.
|
|
87
|
+
*/
|
|
88
|
+
run () {
|
|
89
|
+
if (!this.isReady) {
|
|
90
|
+
// Not yet ready, return with errors
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
error: 'Task is not ready',
|
|
94
|
+
context: this.data
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (this.running) {
|
|
98
|
+
// Already running, return error since we cannot run again
|
|
99
|
+
return {
|
|
100
|
+
success: false,
|
|
101
|
+
error: 'Queued task is already running, possible missing \'complete\' callback',
|
|
102
|
+
context: this.data
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
this.running = true
|
|
106
|
+
// Wrap the task in the markCompleted function, so we can set flags and format the response
|
|
107
|
+
return this.task(this.markCompleted.bind(this))
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Make a new Queueable from the data given if it is not already a valid Queueable.
|
|
112
|
+
* @param queueable Return a valid Queueable instance from given data, or even an already valid one.
|
|
113
|
+
* @param classType Provide the type of IsLinker to use.
|
|
114
|
+
*/
|
|
115
|
+
exports.Queueable = Queueable
|
|
116
|
+
Queueable.make = (queueable, classType = Queueable) => {
|
|
117
|
+
if (queueable === null || typeof queueable !== 'object') {
|
|
118
|
+
// It is not an object (or it is null), so instantiate the Queueable with an element as the data
|
|
119
|
+
return new classType({
|
|
120
|
+
task: queueable,
|
|
121
|
+
ready: true
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
if (queueable.classType) {
|
|
125
|
+
// Already valid Queueable, return as-is
|
|
126
|
+
return queueable
|
|
127
|
+
}
|
|
128
|
+
if (!('task' in queueable)) {
|
|
129
|
+
queueable = {
|
|
130
|
+
task: queueable,
|
|
131
|
+
ready: true
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Create the new node as the configured #classType
|
|
135
|
+
return new classType(queueable)
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Convert an array into Queueable instances, return the head and tail Queueables.
|
|
139
|
+
* @param values Provide an array of data that will be converted to a chain of queueable linkers.
|
|
140
|
+
* @param classType Provide the type of IsLinker to use.
|
|
141
|
+
*/
|
|
142
|
+
Queueable.fromArray = (values = [], classType = Queueable) => _Linker.Linker.fromArray(values, classType)
|
|
@@ -1,68 +1,59 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Convert an array to a TaskQueue.
|
|
62
|
-
* @param {Array} values An array of values which will be converted to queueables in this queue
|
|
63
|
-
* @param {Queueable} queueableClass The class to use for each queueable
|
|
64
|
-
* @param {TaskQueue|Iterable} listClass The class to use to manage the queueables
|
|
65
|
-
* @returns {TaskQueue}
|
|
66
|
-
*/
|
|
67
|
-
static fromArray: (values?: Array<any>, queueableClass?: typeof Queueable, listClass?: any) => TaskQueue;
|
|
68
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* task queue
|
|
3
|
+
*/
|
|
4
|
+
import { Queueable } from './Queueable';
|
|
5
|
+
import { IsArrayable } from '../../recipes/IsArrayable';
|
|
6
|
+
import { IsLinker } from '../../recipes/IsLinker';
|
|
7
|
+
import { completeResponse } from '../../recipes/Runnable';
|
|
8
|
+
/**
|
|
9
|
+
* Maintain a series of queued tasks (Queueables): dequeue() takes the next task from the front and RUNS it, giving each
|
|
10
|
+
* task in turn a chance to run (a task which is not ready, or which has not finished, is placed at the back again).
|
|
11
|
+
* This is a task scheduler, for a plain first-in-first-out collection of items use Queue.
|
|
12
|
+
*/
|
|
13
|
+
export declare class TaskQueue {
|
|
14
|
+
/** The list which stores the queueables, the first is next to be dequeued. */
|
|
15
|
+
queuedList: IsArrayable<any>;
|
|
16
|
+
private listClass;
|
|
17
|
+
private queueableClass;
|
|
18
|
+
/**
|
|
19
|
+
* Instantiate the queue with the given queue list.
|
|
20
|
+
* @param queuedList Give the list of queueables to start in this queue.
|
|
21
|
+
* @param listClass The type of list to create when no queued list is given.
|
|
22
|
+
* @param queueableClass The class used to wrap queued items.
|
|
23
|
+
*/
|
|
24
|
+
constructor(queuedList?: IsArrayable<any>, listClass?: any, queueableClass?: typeof Queueable);
|
|
25
|
+
/**
|
|
26
|
+
* Take a queued task from the front of the queue and run it if ready. A task which is not ready yet is kept in the
|
|
27
|
+
* queue (never dropped), a task which is still running is reported as blocking and left to finish on its own, and
|
|
28
|
+
* completed tasks are discarded.
|
|
29
|
+
*/
|
|
30
|
+
dequeue(): completeResponse | any;
|
|
31
|
+
/**
|
|
32
|
+
* Return true if the queue is empty (there are no tasks in the queue list)
|
|
33
|
+
*/
|
|
34
|
+
empty(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Add a queued task to the end of the queue
|
|
37
|
+
* @param queueable Add a new queueable to the end of the queue
|
|
38
|
+
*/
|
|
39
|
+
enqueue(queueable: Queueable): void;
|
|
40
|
+
/**
|
|
41
|
+
* Take a look at the next queued task
|
|
42
|
+
*/
|
|
43
|
+
peek(): IsLinker;
|
|
44
|
+
/**
|
|
45
|
+
* Remove the next queued item and return it.
|
|
46
|
+
*/
|
|
47
|
+
remove(): Queueable | null;
|
|
48
|
+
/**
|
|
49
|
+
* Get the length of the current queue.
|
|
50
|
+
*/
|
|
51
|
+
size(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Convert an array to a TaskQueue.
|
|
54
|
+
* @param values An array of values which will be converted to queueables in this queue
|
|
55
|
+
* @param queueableClass The class to use for each queueable
|
|
56
|
+
* @param listClass The class to use to manage the queueables
|
|
57
|
+
*/
|
|
58
|
+
static fromArray: (values?: Array<any>, queueableClass?: typeof Queueable, listClass?: any) => TaskQueue;
|
|
59
|
+
}
|