@oscarpalmer/atoms 0.182.1 → 0.184.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/dist/array/sort.d.mts +9 -1
- package/dist/index.d.mts +227 -4
- package/dist/index.mjs +287 -5
- package/dist/queue.d.mts +98 -3
- package/dist/queue.mjs +171 -3
- package/dist/string/normalize.d.mts +12 -0
- package/dist/string/normalize.mjs +13 -2
- package/dist/value/freeze.d.mts +35 -0
- package/dist/value/freeze.mjs +38 -0
- package/dist/value/index.d.mts +2 -1
- package/dist/value/index.mjs +2 -1
- package/dist/value/merge.d.mts +32 -1
- package/dist/value/merge.mjs +27 -1
- package/dist/value/shake.d.mts +5 -0
- package/dist/value/shake.mjs +5 -0
- package/dist/value/transform.d.mts +43 -0
- package/dist/value/transform.mjs +38 -0
- package/package.json +1 -1
- package/plugin/index.js +2 -0
- package/plugin/rules.js +4 -1
- package/src/array/sort.ts +14 -1
- package/src/index.ts +1 -0
- package/src/queue.ts +293 -6
- package/src/string/normalize.ts +33 -1
- package/src/value/freeze.ts +108 -0
- package/src/value/index.ts +1 -0
- package/src/value/merge.ts +56 -0
- package/src/value/shake.ts +5 -0
- package/src/value/transform.ts +140 -0
package/dist/index.mjs
CHANGED
|
@@ -2939,11 +2939,15 @@ function getNormalizeOptions(input) {
|
|
|
2939
2939
|
return {
|
|
2940
2940
|
deburr: options.deburr !== false,
|
|
2941
2941
|
lowerCase: options.lowerCase !== false,
|
|
2942
|
-
|
|
2942
|
+
special: options.special === true,
|
|
2943
|
+
trim: options.trim !== false,
|
|
2944
|
+
whitespace: options.whitespace !== false
|
|
2943
2945
|
};
|
|
2944
2946
|
}
|
|
2945
2947
|
/**
|
|
2946
2948
|
* Initialize a string normalizer
|
|
2949
|
+
*
|
|
2950
|
+
* Available as `initializeNormalizer` and `normalize.initialize`
|
|
2947
2951
|
* @param options Normalization options
|
|
2948
2952
|
* @returns Normalizer function
|
|
2949
2953
|
*/
|
|
@@ -2967,9 +2971,11 @@ function normalizeString(value, options) {
|
|
|
2967
2971
|
if (typeof value !== "string") return "";
|
|
2968
2972
|
let result = value;
|
|
2969
2973
|
if (options.trim) result = result.trim();
|
|
2974
|
+
if (options.whitespace) result = result.replace(WHITESPACE_PATTERN, WHITESPACE_REPLACEMENT);
|
|
2970
2975
|
if (options.deburr) result = deburr(result);
|
|
2971
2976
|
if (options.lowerCase) result = lowerCase(result);
|
|
2972
|
-
|
|
2977
|
+
if (options.special) result = result.replace(SPECIAL_PATTERN, SPECIAL_REPLACEMENT);
|
|
2978
|
+
return result.normalize(NORMALIZATION_NORMALIZATION);
|
|
2973
2979
|
}
|
|
2974
2980
|
const DEBURR_CHARACTERS = {
|
|
2975
2981
|
Æ: "AE",
|
|
@@ -3006,6 +3012,11 @@ const DEBURR_CHARACTERS = {
|
|
|
3006
3012
|
const DEBURR_NORMALIZATION = "NFD";
|
|
3007
3013
|
const DEBURR_PATTERN_CHARACTERS = new RegExp(`(${Object.keys(DEBURR_CHARACTERS).join("|")})`, "g");
|
|
3008
3014
|
const DEBURR_PATTERN_SIMPLE = /[\u0300-\u036f]/g;
|
|
3015
|
+
const NORMALIZATION_NORMALIZATION = "NFC";
|
|
3016
|
+
const SPECIAL_PATTERN = /[\p{P}\p{S}]/gu;
|
|
3017
|
+
const SPECIAL_REPLACEMENT = "";
|
|
3018
|
+
const WHITESPACE_PATTERN = /\s+/g;
|
|
3019
|
+
const WHITESPACE_REPLACEMENT = " ";
|
|
3009
3020
|
let deburrMemoizer;
|
|
3010
3021
|
//#endregion
|
|
3011
3022
|
//#region src/string/template.ts
|
|
@@ -3304,6 +3315,42 @@ const DIFF_FULL = "full";
|
|
|
3304
3315
|
const DIFF_NONE = "none";
|
|
3305
3316
|
const DIFF_PARTIAL = "partial";
|
|
3306
3317
|
//#endregion
|
|
3318
|
+
//#region src/value/freeze.ts
|
|
3319
|
+
function freeze(value) {
|
|
3320
|
+
return freezeValue(value, /* @__PURE__ */ new WeakSet());
|
|
3321
|
+
}
|
|
3322
|
+
function freezeArray(array, references) {
|
|
3323
|
+
references.add(array);
|
|
3324
|
+
const { length } = array;
|
|
3325
|
+
for (let index = 0; index < length; index += 1) {
|
|
3326
|
+
const value = array[index];
|
|
3327
|
+
if (!references.has(value)) array[index] = freezeValue(array[index], references);
|
|
3328
|
+
}
|
|
3329
|
+
return Object.freeze(array);
|
|
3330
|
+
}
|
|
3331
|
+
function freezeFunction(fn, references) {
|
|
3332
|
+
references.add(fn);
|
|
3333
|
+
return Object.freeze(fn);
|
|
3334
|
+
}
|
|
3335
|
+
function freezeObject(object, references) {
|
|
3336
|
+
references.add(object);
|
|
3337
|
+
const keys = Object.keys(object);
|
|
3338
|
+
const { length } = keys;
|
|
3339
|
+
for (let index = 0; index < length; index += 1) {
|
|
3340
|
+
const key = keys[index];
|
|
3341
|
+
if (!references.has(object[key])) object[key] = freezeValue(object[key], references);
|
|
3342
|
+
}
|
|
3343
|
+
return Object.freeze(object);
|
|
3344
|
+
}
|
|
3345
|
+
function freezeValue(value, references) {
|
|
3346
|
+
switch (true) {
|
|
3347
|
+
case typeof value === "function": return freezeFunction(value, references);
|
|
3348
|
+
case Array.isArray(value): return freezeArray(value, references);
|
|
3349
|
+
case isPlainObject(value): return freezeObject(value, references);
|
|
3350
|
+
default: return value;
|
|
3351
|
+
}
|
|
3352
|
+
}
|
|
3353
|
+
//#endregion
|
|
3307
3354
|
//#region src/internal/value/partial.ts
|
|
3308
3355
|
function partial(value, providedKeys, omit) {
|
|
3309
3356
|
if (typeof value !== "object" || value === null) return {};
|
|
@@ -3342,6 +3389,11 @@ function pick(value, keys) {
|
|
|
3342
3389
|
}
|
|
3343
3390
|
//#endregion
|
|
3344
3391
|
//#region src/value/shake.ts
|
|
3392
|
+
/**
|
|
3393
|
+
* Shake an object, removing all keys with `undefined` values
|
|
3394
|
+
* @param value Object to shake
|
|
3395
|
+
* @returns Shaken object
|
|
3396
|
+
*/
|
|
3345
3397
|
function shake(value) {
|
|
3346
3398
|
const shaken = {};
|
|
3347
3399
|
if (isNonPlainObject(value)) return shaken;
|
|
@@ -3425,6 +3477,19 @@ function unsmush(value) {
|
|
|
3425
3477
|
}
|
|
3426
3478
|
//#endregion
|
|
3427
3479
|
//#region src/value/merge.ts
|
|
3480
|
+
/**
|
|
3481
|
+
* Assign values from multiple arrays or objects to the first one
|
|
3482
|
+
* @param to Value to assign to
|
|
3483
|
+
* @param from Values to assign
|
|
3484
|
+
* @param options Assigning options
|
|
3485
|
+
* @returns Assigned value
|
|
3486
|
+
*/
|
|
3487
|
+
function assign(to, from, options) {
|
|
3488
|
+
const actual = getMergeOptions(options);
|
|
3489
|
+
actual.assignValues = true;
|
|
3490
|
+
return mergeValues([to, ...from], actual, true);
|
|
3491
|
+
}
|
|
3492
|
+
assign.initialize = initializeAssigner;
|
|
3428
3493
|
function getMergeOptions(options) {
|
|
3429
3494
|
const actual = {
|
|
3430
3495
|
assignValues: false,
|
|
@@ -3447,6 +3512,18 @@ function handleMerge(values, options) {
|
|
|
3447
3512
|
return !Array.isArray(values) || values.length === 0 ? {} : mergeValues(values, options, true);
|
|
3448
3513
|
}
|
|
3449
3514
|
/**
|
|
3515
|
+
* Create an assigner with predefined options
|
|
3516
|
+
*
|
|
3517
|
+
* Available as `initializeAssigner` and `assign.initialize`
|
|
3518
|
+
* @param options Assigning options
|
|
3519
|
+
* @returns Assigner function
|
|
3520
|
+
*/
|
|
3521
|
+
function initializeAssigner(options) {
|
|
3522
|
+
const actual = getMergeOptions(options);
|
|
3523
|
+
actual.assignValues = true;
|
|
3524
|
+
return ((to, from) => mergeValues([to, ...from], actual, true));
|
|
3525
|
+
}
|
|
3526
|
+
/**
|
|
3450
3527
|
* Create a merger with predefined options
|
|
3451
3528
|
*
|
|
3452
3529
|
* Available as `initializeMerger` and `merge.initialize`
|
|
@@ -3460,6 +3537,7 @@ function initializeMerger(options) {
|
|
|
3460
3537
|
function merge(values, options) {
|
|
3461
3538
|
return handleMerge(values, getMergeOptions(options));
|
|
3462
3539
|
}
|
|
3540
|
+
merge.assign = assign;
|
|
3463
3541
|
merge.initialize = initializeMerger;
|
|
3464
3542
|
function mergeObjects(values, options, prefix) {
|
|
3465
3543
|
const { length } = values;
|
|
@@ -3486,6 +3564,42 @@ function mergeValues(values, options, validate, prefix) {
|
|
|
3486
3564
|
return actual.length > 1 ? mergeObjects(actual, options, prefix) : actual[0] ?? {};
|
|
3487
3565
|
}
|
|
3488
3566
|
//#endregion
|
|
3567
|
+
//#region src/value/transform.ts
|
|
3568
|
+
function getTransformer(input) {
|
|
3569
|
+
if (typeof input === "function") return input;
|
|
3570
|
+
if (isNonPlainObject(input)) return;
|
|
3571
|
+
const keys = Object.keys(input);
|
|
3572
|
+
const { length } = keys;
|
|
3573
|
+
const transformer = {};
|
|
3574
|
+
for (let index = 0; index < length; index += 1) {
|
|
3575
|
+
const key = keys[index];
|
|
3576
|
+
const value = input[key];
|
|
3577
|
+
if (typeof value === "function") transformer[key] = value;
|
|
3578
|
+
}
|
|
3579
|
+
if (Object.keys(transformer).length > 0) return transformer;
|
|
3580
|
+
}
|
|
3581
|
+
function initializeTransformer(transform) {
|
|
3582
|
+
const transformer = getTransformer(transform);
|
|
3583
|
+
return (value) => transformValue(value, transformer);
|
|
3584
|
+
}
|
|
3585
|
+
function transform(value, transform) {
|
|
3586
|
+
return transformValue(value, getTransformer(transform));
|
|
3587
|
+
}
|
|
3588
|
+
transform.initialize = initializeTransformer;
|
|
3589
|
+
function transformValue(value, transformer) {
|
|
3590
|
+
if (isNonPlainObject(value)) return {};
|
|
3591
|
+
if (transformer == null) return value;
|
|
3592
|
+
const keys = Object.keys(value);
|
|
3593
|
+
const { length } = keys;
|
|
3594
|
+
for (let index = 0; index < length; index += 1) {
|
|
3595
|
+
const key = keys[index];
|
|
3596
|
+
const val = value[key];
|
|
3597
|
+
if (typeof transformer === "function") value[key] = transformer(key, val);
|
|
3598
|
+
else value[key] = transformer[key]?.(val) ?? val;
|
|
3599
|
+
}
|
|
3600
|
+
return value;
|
|
3601
|
+
}
|
|
3602
|
+
//#endregion
|
|
3489
3603
|
//#region src/beacon.ts
|
|
3490
3604
|
var Beacon = class {
|
|
3491
3605
|
#options;
|
|
@@ -4828,11 +4942,161 @@ const TYPES = new Set([
|
|
|
4828
4942
|
]);
|
|
4829
4943
|
//#endregion
|
|
4830
4944
|
//#region src/queue.ts
|
|
4945
|
+
var KeyedQueue = class {
|
|
4946
|
+
#callback;
|
|
4947
|
+
#options;
|
|
4948
|
+
#queues = /* @__PURE__ */ new Map();
|
|
4949
|
+
/**
|
|
4950
|
+
* Is any queue active?
|
|
4951
|
+
*/
|
|
4952
|
+
get active() {
|
|
4953
|
+
return this.#getStatus(STATUS_ACTIVE);
|
|
4954
|
+
}
|
|
4955
|
+
/**
|
|
4956
|
+
* Does the queue automatically start when the first item is added?
|
|
4957
|
+
*/
|
|
4958
|
+
get autostart() {
|
|
4959
|
+
return this.#options.autostart;
|
|
4960
|
+
}
|
|
4961
|
+
/**
|
|
4962
|
+
* Maximum number of runners to process the queue concurrently
|
|
4963
|
+
*/
|
|
4964
|
+
get concurrency() {
|
|
4965
|
+
return this.#options.concurrency;
|
|
4966
|
+
}
|
|
4967
|
+
/**
|
|
4968
|
+
* Are all queues empty?
|
|
4969
|
+
*/
|
|
4970
|
+
get empty() {
|
|
4971
|
+
return this.#getStatus(STATUS_EMPTY);
|
|
4972
|
+
}
|
|
4973
|
+
/**
|
|
4974
|
+
* Are all queues full?
|
|
4975
|
+
*/
|
|
4976
|
+
get full() {
|
|
4977
|
+
return this.#getStatus(STATUS_FULL);
|
|
4978
|
+
}
|
|
4979
|
+
/**
|
|
4980
|
+
* Number of items in all queues
|
|
4981
|
+
*/
|
|
4982
|
+
get items() {
|
|
4983
|
+
const size = {};
|
|
4984
|
+
const queues = this.#queues.entries();
|
|
4985
|
+
for (const [key, queue] of queues) size[key] = queue.size;
|
|
4986
|
+
return size;
|
|
4987
|
+
}
|
|
4988
|
+
/**
|
|
4989
|
+
* Keys of all queues
|
|
4990
|
+
*/
|
|
4991
|
+
get keys() {
|
|
4992
|
+
return [...this.#queues.keys()];
|
|
4993
|
+
}
|
|
4994
|
+
/**
|
|
4995
|
+
* Maximum number of items allowed in the queue
|
|
4996
|
+
*/
|
|
4997
|
+
get maximum() {
|
|
4998
|
+
return this.#options.maximum;
|
|
4999
|
+
}
|
|
5000
|
+
/**
|
|
5001
|
+
* Are all queues paused?
|
|
5002
|
+
*/
|
|
5003
|
+
get paused() {
|
|
5004
|
+
return this.#getStatus(STATUS_PAUSED);
|
|
5005
|
+
}
|
|
5006
|
+
/**
|
|
5007
|
+
* Number of queues
|
|
5008
|
+
*/
|
|
5009
|
+
get queues() {
|
|
5010
|
+
return this.#queues.size;
|
|
5011
|
+
}
|
|
5012
|
+
constructor(callback, options) {
|
|
5013
|
+
this.#callback = callback;
|
|
5014
|
+
this.#options = options;
|
|
5015
|
+
}
|
|
5016
|
+
/**
|
|
5017
|
+
* Queue an item for a specific key
|
|
5018
|
+
* @param key Key to queue the item for
|
|
5019
|
+
* @param parameters Parameters to use when item runs
|
|
5020
|
+
* @param signal Optional signal to abort the item
|
|
5021
|
+
* @returns Queued item
|
|
5022
|
+
*/
|
|
5023
|
+
add(key, parameters, signal) {
|
|
5024
|
+
return this.#getQueue(key, true).add(parameters, signal);
|
|
5025
|
+
}
|
|
5026
|
+
/**
|
|
5027
|
+
* Clear all items for a specific key _(or all items for all keys, if no key is provided)_
|
|
5028
|
+
* @param key Optional key to clear the queue for
|
|
5029
|
+
*/
|
|
5030
|
+
clear(key) {
|
|
5031
|
+
this.#handleQueues(HANDLE_CLEAR, key);
|
|
5032
|
+
}
|
|
5033
|
+
/**
|
|
5034
|
+
* Get the queue for a specific key
|
|
5035
|
+
* @param key Key to get the queue for
|
|
5036
|
+
* @returns Queue for the key, or `undefined` if it doesn't exist
|
|
5037
|
+
*/
|
|
5038
|
+
get(key) {
|
|
5039
|
+
return this.#getQueue(key);
|
|
5040
|
+
}
|
|
5041
|
+
/**
|
|
5042
|
+
* Pause the queue for a specific key _(or all queues, if no key is provided)_
|
|
5043
|
+
* @param key Optional key to pause the queue for
|
|
5044
|
+
*/
|
|
5045
|
+
pause(key) {
|
|
5046
|
+
this.#handleQueues(HANDLE_PAUSE, key);
|
|
5047
|
+
}
|
|
5048
|
+
remove(key, id) {
|
|
5049
|
+
if (key == null) {
|
|
5050
|
+
this.#handleQueues(HANDLE_CLEAR);
|
|
5051
|
+
this.#queues.clear();
|
|
5052
|
+
return;
|
|
5053
|
+
}
|
|
5054
|
+
const queue = this.#getQueue(key);
|
|
5055
|
+
if (queue == null) return;
|
|
5056
|
+
if (typeof id === "number") {
|
|
5057
|
+
queue.remove(id);
|
|
5058
|
+
return;
|
|
5059
|
+
}
|
|
5060
|
+
queue.clear();
|
|
5061
|
+
this.#queues.delete(key);
|
|
5062
|
+
}
|
|
5063
|
+
/**
|
|
5064
|
+
* Resume the queue for a specific key _(or all queues, if no key is provided)_
|
|
5065
|
+
* @param key Optional key to resume the queue for
|
|
5066
|
+
*/
|
|
5067
|
+
resume(key) {
|
|
5068
|
+
this.#handleQueues(HANDLE_RESUME, key);
|
|
5069
|
+
}
|
|
5070
|
+
#getQueue(key, add) {
|
|
5071
|
+
if (typeof key !== "string" || key.trim().length === 0) throw new TypeError(MESSAGE_KEY);
|
|
5072
|
+
let queue = this.#queues.get(key);
|
|
5073
|
+
if (queue == null && add === true) {
|
|
5074
|
+
queue = new Queue(this.#callback, this.#options, key);
|
|
5075
|
+
this.#queues.set(key, queue);
|
|
5076
|
+
}
|
|
5077
|
+
return queue;
|
|
5078
|
+
}
|
|
5079
|
+
#getStatus(status) {
|
|
5080
|
+
const queues = this.#queues.entries();
|
|
5081
|
+
const result = [];
|
|
5082
|
+
for (const [key, queue] of queues) if (queue[status]) result.push(key);
|
|
5083
|
+
return result;
|
|
5084
|
+
}
|
|
5085
|
+
#handleQueues(type, key) {
|
|
5086
|
+
if (typeof key === "string") {
|
|
5087
|
+
this.#getQueue(key)?.[type]();
|
|
5088
|
+
return;
|
|
5089
|
+
}
|
|
5090
|
+
const queues = this.#queues.values();
|
|
5091
|
+
for (const queue of queues) queue[type]();
|
|
5092
|
+
}
|
|
5093
|
+
};
|
|
4831
5094
|
var Queue = class {
|
|
4832
5095
|
#callback;
|
|
4833
5096
|
#handled = [];
|
|
4834
5097
|
#id = 0;
|
|
4835
5098
|
#items = [];
|
|
5099
|
+
#key;
|
|
4836
5100
|
#options;
|
|
4837
5101
|
#paused;
|
|
4838
5102
|
#runners = 0;
|
|
@@ -4884,8 +5148,9 @@ var Queue = class {
|
|
|
4884
5148
|
get size() {
|
|
4885
5149
|
return this.#items.length;
|
|
4886
5150
|
}
|
|
4887
|
-
constructor(callback, options) {
|
|
5151
|
+
constructor(callback, options, key) {
|
|
4888
5152
|
this.#callback = callback;
|
|
5153
|
+
this.#key = key;
|
|
4889
5154
|
this.#options = options;
|
|
4890
5155
|
this.#paused = !options.autostart;
|
|
4891
5156
|
}
|
|
@@ -4913,6 +5178,7 @@ var Queue = class {
|
|
|
4913
5178
|
parameters,
|
|
4914
5179
|
promise,
|
|
4915
5180
|
abort: aborter,
|
|
5181
|
+
key: this.#key,
|
|
4916
5182
|
reject: rejector,
|
|
4917
5183
|
resolve: resolver,
|
|
4918
5184
|
signal: abortSignal
|
|
@@ -4981,7 +5247,10 @@ var Queue = class {
|
|
|
4981
5247
|
let error = false;
|
|
4982
5248
|
let result;
|
|
4983
5249
|
try {
|
|
4984
|
-
if (!(item.signal?.aborted ?? false))
|
|
5250
|
+
if (!(item.signal?.aborted ?? false)) {
|
|
5251
|
+
const parameters = item.key == null ? item.parameters : [item.key, ...item.parameters];
|
|
5252
|
+
result = await this.#callback(...parameters);
|
|
5253
|
+
}
|
|
4985
5254
|
} catch (thrown) {
|
|
4986
5255
|
error = true;
|
|
4987
5256
|
result = thrown;
|
|
@@ -5028,17 +5297,30 @@ function handleResult$1(item, error, result, finished) {
|
|
|
5028
5297
|
value: result
|
|
5029
5298
|
});
|
|
5030
5299
|
}
|
|
5300
|
+
function keyedQueue(callback, options) {
|
|
5301
|
+
if (typeof callback !== "function") throw new TypeError(MESSAGE_CALLBACK);
|
|
5302
|
+
return new KeyedQueue(callback, getOptions(options));
|
|
5303
|
+
}
|
|
5031
5304
|
function queue(callback, options) {
|
|
5032
5305
|
if (typeof callback !== "function") throw new TypeError(MESSAGE_CALLBACK);
|
|
5033
5306
|
return new Queue(callback, getOptions(options));
|
|
5034
5307
|
}
|
|
5308
|
+
queue.keyed = keyedQueue;
|
|
5035
5309
|
const ERROR_NAME = "QueueError";
|
|
5036
5310
|
const EVENT_NAME = "abort";
|
|
5037
5311
|
const EVENT_OPTIONS = { once: true };
|
|
5312
|
+
const HANDLE_CLEAR = "clear";
|
|
5313
|
+
const HANDLE_PAUSE = "pause";
|
|
5314
|
+
const HANDLE_RESUME = "resume";
|
|
5038
5315
|
const MESSAGE_CALLBACK = "A Queue requires a callback function";
|
|
5039
5316
|
const MESSAGE_CLEAR = "Queue was cleared";
|
|
5317
|
+
const MESSAGE_KEY = "Key must be a non-empty string";
|
|
5040
5318
|
const MESSAGE_MAXIMUM = "Queue has reached its maximum size";
|
|
5041
5319
|
const MESSAGE_REMOVE = "Item removed from queue";
|
|
5320
|
+
const STATUS_ACTIVE = "active";
|
|
5321
|
+
const STATUS_EMPTY = "empty";
|
|
5322
|
+
const STATUS_FULL = "full";
|
|
5323
|
+
const STATUS_PAUSED = "paused";
|
|
5042
5324
|
//#endregion
|
|
5043
5325
|
//#region src/random.ts
|
|
5044
5326
|
/**
|
|
@@ -5240,4 +5522,4 @@ var SizedSet = class extends Set {
|
|
|
5240
5522
|
}
|
|
5241
5523
|
};
|
|
5242
5524
|
//#endregion
|
|
5243
|
-
export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError,
|
|
5525
|
+
export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kalas, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
package/dist/queue.d.mts
CHANGED
|
@@ -1,6 +1,96 @@
|
|
|
1
1
|
import { GenericAsyncCallback, GenericCallback } from "./models.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/queue.d.ts
|
|
4
|
+
declare class KeyedQueue<CallbackParameters extends Parameters<GenericAsyncCallback>, CallbackResult> {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* Is any queue active?
|
|
8
|
+
*/
|
|
9
|
+
get active(): string[];
|
|
10
|
+
/**
|
|
11
|
+
* Does the queue automatically start when the first item is added?
|
|
12
|
+
*/
|
|
13
|
+
get autostart(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Maximum number of runners to process the queue concurrently
|
|
16
|
+
*/
|
|
17
|
+
get concurrency(): number;
|
|
18
|
+
/**
|
|
19
|
+
* Are all queues empty?
|
|
20
|
+
*/
|
|
21
|
+
get empty(): string[];
|
|
22
|
+
/**
|
|
23
|
+
* Are all queues full?
|
|
24
|
+
*/
|
|
25
|
+
get full(): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Number of items in all queues
|
|
28
|
+
*/
|
|
29
|
+
get items(): Record<string, number>;
|
|
30
|
+
/**
|
|
31
|
+
* Keys of all queues
|
|
32
|
+
*/
|
|
33
|
+
get keys(): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Maximum number of items allowed in the queue
|
|
36
|
+
*/
|
|
37
|
+
get maximum(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Are all queues paused?
|
|
40
|
+
*/
|
|
41
|
+
get paused(): string[];
|
|
42
|
+
/**
|
|
43
|
+
* Number of queues
|
|
44
|
+
*/
|
|
45
|
+
get queues(): number;
|
|
46
|
+
constructor(callback: GenericAsyncCallback, options: Required<QueueOptions>);
|
|
47
|
+
/**
|
|
48
|
+
* Queue an item for a specific key
|
|
49
|
+
* @param key Key to queue the item for
|
|
50
|
+
* @param parameters Parameters to use when item runs
|
|
51
|
+
* @param signal Optional signal to abort the item
|
|
52
|
+
* @returns Queued item
|
|
53
|
+
*/
|
|
54
|
+
add(key: string, parameters: Tail<CallbackParameters>, signal?: AbortSignal): Queued<CallbackResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Clear all items for a specific key _(or all items for all keys, if no key is provided)_
|
|
57
|
+
* @param key Optional key to clear the queue for
|
|
58
|
+
*/
|
|
59
|
+
clear(key?: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Get the queue for a specific key
|
|
62
|
+
* @param key Key to get the queue for
|
|
63
|
+
* @returns Queue for the key, or `undefined` if it doesn't exist
|
|
64
|
+
*/
|
|
65
|
+
get(key: string): Queue<Tail<CallbackParameters>, CallbackResult> | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Pause the queue for a specific key _(or all queues, if no key is provided)_
|
|
68
|
+
* @param key Optional key to pause the queue for
|
|
69
|
+
*/
|
|
70
|
+
pause(key?: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Remove a specific item for a specific key
|
|
73
|
+
* @param key Key to remove the item for
|
|
74
|
+
* @param id ID of the item to remove
|
|
75
|
+
*/
|
|
76
|
+
remove(key: string, id: number): void;
|
|
77
|
+
/**
|
|
78
|
+
* Remove a queue and its items for a specific key
|
|
79
|
+
*
|
|
80
|
+
* _(To remove all items for a specific key, use `clear()` instead)_
|
|
81
|
+
* @param key Key to remove the queue for
|
|
82
|
+
*/
|
|
83
|
+
remove(key: string): void;
|
|
84
|
+
/**
|
|
85
|
+
* Remove all queues and their items
|
|
86
|
+
*/
|
|
87
|
+
remove(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Resume the queue for a specific key _(or all queues, if no key is provided)_
|
|
90
|
+
* @param key Optional key to resume the queue for
|
|
91
|
+
*/
|
|
92
|
+
resume(key?: string): void;
|
|
93
|
+
}
|
|
4
94
|
declare class Queue<CallbackParameters extends Parameters<GenericAsyncCallback>, CallbackResult> {
|
|
5
95
|
#private;
|
|
6
96
|
/**
|
|
@@ -35,7 +125,7 @@ declare class Queue<CallbackParameters extends Parameters<GenericAsyncCallback>,
|
|
|
35
125
|
* Number of items in the queue
|
|
36
126
|
*/
|
|
37
127
|
get size(): number;
|
|
38
|
-
constructor(callback: GenericAsyncCallback, options: Required<QueueOptions
|
|
128
|
+
constructor(callback: GenericAsyncCallback, options: Required<QueueOptions>, key?: string);
|
|
39
129
|
/**
|
|
40
130
|
* Add an item to the queue
|
|
41
131
|
* @param parameters Parameters to use when item runs
|
|
@@ -101,13 +191,15 @@ type QueuedResult<Value> = {
|
|
|
101
191
|
*/
|
|
102
192
|
value: Value;
|
|
103
193
|
};
|
|
194
|
+
type Tail<Values extends any[]> = Values extends [infer _, ...infer Rest] ? Rest : never;
|
|
195
|
+
declare function keyedQueue<Callback extends GenericAsyncCallback>(callback: Callback, options?: QueueOptions): KeyedQueue<Parameters<Callback>, Awaited<ReturnType<Callback>>>;
|
|
104
196
|
/**
|
|
105
197
|
* Create a queue for an asynchronous callback function
|
|
106
198
|
* @param callback Callback function for queued items
|
|
107
199
|
* @param options Queue options
|
|
108
200
|
* @returns Queue instance
|
|
109
201
|
*/
|
|
110
|
-
declare function queue<Callback extends
|
|
202
|
+
declare function queue<Callback extends (key: string, ...parameters: any[]) => Promise<void>>(callback: Callback, options?: QueueOptions): Queue<Parameters<Callback>, Awaited<ReturnType<Callback>>>;
|
|
111
203
|
/**
|
|
112
204
|
* Create a queue for an asynchronous callback function
|
|
113
205
|
* @param callback Callback function for queued items
|
|
@@ -115,5 +207,8 @@ declare function queue<Callback extends GenericAsyncCallback>(callback: Callback
|
|
|
115
207
|
* @returns Queue instance
|
|
116
208
|
*/
|
|
117
209
|
declare function queue<Callback extends GenericCallback>(callback: Callback, options?: QueueOptions): Queue<Parameters<Callback>, ReturnType<Callback>>;
|
|
210
|
+
declare namespace queue {
|
|
211
|
+
var keyed: typeof keyedQueue;
|
|
212
|
+
}
|
|
118
213
|
//#endregion
|
|
119
|
-
export { type Queue, QueueError, type QueueOptions, type Queued, type QueuedResult, queue };
|
|
214
|
+
export { type KeyedQueue, type Queue, type QueueError, type QueueOptions, type Queued, type QueuedResult, keyedQueue, queue };
|