@augment-vir/common 31.32.3 → 31.33.1

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.
@@ -11,6 +11,7 @@ import { ListenTarget } from 'typed-event-target';
11
11
  export type PromiseQueueItem<T = void> = {
12
12
  /** The original queue item that was added. */
13
13
  original: () => MaybePromise<T>;
14
+ id: undefined | PropertyKey;
14
15
  /**
15
16
  * A {@link DeferredPromise} instance with a promise that is resolved once this queue item has
16
17
  * met its turn and has finished executing.
@@ -63,14 +64,23 @@ export declare class PromiseQueueUpdateEvent extends PromiseQueueUpdateEvent_bas
63
64
  export declare class PromiseQueue extends ListenTarget<PromiseQueueUpdateEvent> {
64
65
  protected queue: PromiseQueueItem<any>[];
65
66
  protected currentlyAwaiting: undefined | PromiseQueueItem<any>;
67
+ protected queueItemIds: Set<PropertyKey>;
66
68
  /** The current size of the queue. */
67
69
  get size(): number;
68
70
  /**
69
- * Add an item to the queue.
71
+ * Add an item to the queue. Only await this if you want to wait for the promise to be added
72
+ * _and_ resolved (or rejected).
70
73
  *
71
74
  * @returns A promise that resolves at the same time as the added item.
72
75
  */
73
- add<T = void>(item: PromiseQueueItem<T>['original']): Promise<T>;
76
+ add<T = void>(item: PromiseQueueItem<T>['original'], id?: PropertyKey): Promise<T>;
77
+ /**
78
+ * Checks if the given id is currently in the queue.
79
+ *
80
+ * @returns `true` if the item is in the queue and has not been resolved or rejected. `false` if
81
+ * the item has never been in the queue or has been resolved / rejected from the queue.
82
+ */
83
+ hasItemById(id: PropertyKey): boolean;
74
84
  /** Handles a queue item finishing, whether it be a rejection or a resolution. */
75
85
  protected handleItemSettle({ rejection, resolution, }: RequireExactlyOne<{
76
86
  rejection: unknown;
@@ -21,21 +21,27 @@ export class PromiseQueueUpdateEvent extends defineTypedCustomEvent()('promise-q
21
21
  export class PromiseQueue extends ListenTarget {
22
22
  queue = [];
23
23
  currentlyAwaiting = undefined;
24
+ queueItemIds = new Set();
24
25
  /** The current size of the queue. */
25
26
  get size() {
26
27
  return this.queue.length;
27
28
  }
28
29
  /**
29
- * Add an item to the queue.
30
+ * Add an item to the queue. Only await this if you want to wait for the promise to be added
31
+ * _and_ resolved (or rejected).
30
32
  *
31
33
  * @returns A promise that resolves at the same time as the added item.
32
34
  */
33
- add(item) {
35
+ add(item, id) {
34
36
  const newItem = {
35
37
  original: item,
38
+ id,
36
39
  wrapper: new DeferredPromise(),
37
40
  };
38
41
  this.queue.push(newItem);
42
+ if (id != undefined) {
43
+ this.queueItemIds.add(id);
44
+ }
39
45
  this.dispatch(new PromiseQueueUpdateEvent({
40
46
  detail: {
41
47
  queueSize: this.size,
@@ -45,6 +51,15 @@ export class PromiseQueue extends ListenTarget {
45
51
  this.triggerNextQueueItem();
46
52
  return newItem.wrapper.promise;
47
53
  }
54
+ /**
55
+ * Checks if the given id is currently in the queue.
56
+ *
57
+ * @returns `true` if the item is in the queue and has not been resolved or rejected. `false` if
58
+ * the item has never been in the queue or has been resolved / rejected from the queue.
59
+ */
60
+ hasItemById(id) {
61
+ return this.queueItemIds.has(id);
62
+ }
48
63
  /** Handles a queue item finishing, whether it be a rejection or a resolution. */
49
64
  handleItemSettle({ rejection, resolution, }) {
50
65
  const item = this.currentlyAwaiting;
@@ -64,6 +79,9 @@ export class PromiseQueue extends ListenTarget {
64
79
  else {
65
80
  item.wrapper.resolve(resolution);
66
81
  }
82
+ if (item.id != undefined) {
83
+ this.queueItemIds.delete(item.id);
84
+ }
67
85
  this.currentlyAwaiting = undefined;
68
86
  this.triggerNextQueueItem();
69
87
  return item;
@@ -6,7 +6,7 @@
6
6
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
7
7
  */
8
8
  export function maybeCapitalize(input, casingOptions) {
9
- // eslint-disable-next-line sonarjs/deprecation, @typescript-eslint/no-deprecated
9
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
10
10
  return casingOptions.capitalizeFirstLetter ? capitalizeFirstLetter(input) : input;
11
11
  }
12
12
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "31.32.3",
3
+ "version": "31.33.1",
4
4
  "description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
5
5
  "keywords": [
6
6
  "augment",
@@ -33,16 +33,16 @@
33
33
  "types": "dist/index.d.ts",
34
34
  "scripts": {
35
35
  "compile": "virmator compile",
36
- "test": "concurrently --colors --kill-others-on-fail -c red,blue --names node,web \"npm run test:node\" \"npm run test:web\"",
36
+ "test": "runstorm --names node,web \"npm run test:node\" \"npm run test:web\"",
37
37
  "test:coverage": "virmator --no-deps test web coverage",
38
38
  "test:node": "virmator --no-deps test node",
39
39
  "test:update": "npm test",
40
40
  "test:web": "virmator --no-deps test web"
41
41
  },
42
42
  "dependencies": {
43
- "@augment-vir/assert": "^31.32.3",
44
- "@augment-vir/core": "^31.32.3",
45
- "@date-vir/duration": "^7.4.0",
43
+ "@augment-vir/assert": "^31.33.1",
44
+ "@augment-vir/core": "^31.33.1",
45
+ "@date-vir/duration": "^7.4.2",
46
46
  "ansi-styles": "^6.2.1",
47
47
  "deepcopy-esm": "^2.1.1",
48
48
  "json5": "^2.2.3",
@@ -55,9 +55,9 @@
55
55
  "@web/test-runner-commands": "^0.9.0",
56
56
  "@web/test-runner-playwright": "^0.11.1",
57
57
  "@web/test-runner-visual-regression": "^0.10.0",
58
- "concurrently": "^9.2.0",
59
- "execute-in-browser": "^1.0.8",
58
+ "execute-in-browser": "^1.0.9",
60
59
  "istanbul-smart-text-reporter": "^1.1.5",
60
+ "runstorm": "^0.6.2",
61
61
  "typescript": "^5.9.2"
62
62
  },
63
63
  "engines": {