semantic-typescript 2.0.0 → 2.0.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.
@@ -3,6 +3,7 @@ import { isFunction, isNumber, isBigInt, isObject, isString, isAsynchronousColle
3
3
  import { useCompare } from "#semantic/hook";
4
4
  import { AsynchronousOrderedCollectableSymbol, AsynchronousCollectableSymbol, AsynchronousUnorderedCollectableSymbol } from "#semantic/symbol";
5
5
  import { invalidate, validate } from "#semantic/utility";
6
+ import { readonlyMap } from "#semantic/readonly-map";
6
7
  const SURROGATE_BASE = 1n << 96n;
7
8
  export class AsynchronousCollectable {
8
9
  AsynchronousCollectable = AsynchronousCollectableSymbol;
@@ -591,10 +592,15 @@ export class AsynchronousUnorderedCollectable extends AsynchronousCollectable {
591
592
  }
592
593
  this.ready = (async () => {
593
594
  let surrogate = 0n;
594
- await generator((element, index) => {
595
- let key = this.buffer.has(index) ? SURROGATE_BASE + (surrogate++) : index;
596
- this.buffer.set(key, element);
597
- }, () => false);
595
+ try {
596
+ await generator((element, index) => {
597
+ let key = this.buffer.has(index) ? SURROGATE_BASE + (surrogate++) : index;
598
+ this.buffer.set(key, element);
599
+ }, () => false);
600
+ }
601
+ finally {
602
+ this.buffer = readonlyMap(this.buffer);
603
+ }
598
604
  })();
599
605
  void this.ready.catch(() => { });
600
606
  Object.defineProperty(this, "AsynchronousUnorderedCollectable", {
package/dist/optional.js CHANGED
@@ -120,4 +120,3 @@ export class Optional {
120
120
  ;
121
121
  Object.freeze(Optional);
122
122
  Object.freeze(Optional.prototype);
123
- Object.freeze(Object.getPrototypeOf(Optional));
@@ -0,0 +1 @@
1
+ export declare const readonlyMap: <K, V>(source: Map<K, V>) => ReadonlyMap<K, V>;
@@ -0,0 +1,26 @@
1
+ export const readonlyMap = (source) => {
2
+ const target = new Map(source);
3
+ const mutators = new Set(["set", "delete", "clear"]);
4
+ let facade;
5
+ facade = new Proxy(target, {
6
+ get(map, property) {
7
+ if (mutators.has(property)) {
8
+ return () => { throw new TypeError("This Map is read-only."); };
9
+ }
10
+ if (property === "forEach") {
11
+ return (callback, thisArg) => {
12
+ map.forEach((value, key) => callback.call(thisArg, value, key, facade));
13
+ };
14
+ }
15
+ if (property === "valueOf") {
16
+ return () => facade;
17
+ }
18
+ const value = Reflect.get(map, property, map);
19
+ return typeof value === "function" ? value.bind(map) : value;
20
+ },
21
+ set() { return false; },
22
+ defineProperty() { return false; },
23
+ deleteProperty() { return false; }
24
+ });
25
+ return facade;
26
+ };
@@ -3,6 +3,7 @@ import { isFunction, isNumber, isBigInt, isObject, isString, isSynchronousCollec
3
3
  import { useCompare } from "#semantic/hook";
4
4
  import { SynchronousOrderedCollectableSymbol, SynchronousCollectableSymbol, SynchronousUnorderedCollectableSymbol } from "#semantic/symbol";
5
5
  import { invalidate, validate } from "#semantic/utility";
6
+ import { readonlyMap } from "#semantic/readonly-map";
6
7
  import { SynchronousCollector } from "#semantic/synchronous/collector";
7
8
  import { Optional } from "#semantic/optional";
8
9
  const SURROGATE_BASE = 1n << 96n;
@@ -600,7 +601,7 @@ export class SynchronousUnorderedCollectable extends SynchronousCollectable {
600
601
  let key = this.buffer.has(index) ? SURROGATE_BASE + (surrogate++) : index;
601
602
  this.buffer.set(key, element);
602
603
  }, () => false);
603
- Object.freeze(this.buffer);
604
+ this.buffer = readonlyMap(this.buffer);
604
605
  Object.defineProperties(this, {
605
606
  "SynchronousUnorderedCollectable": {
606
607
  value: SynchronousUnorderedCollectableSymbol,
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "url": "https://github.com/eloyhere"
7
7
  },
8
8
  "description": "A modern type-safe stream processing library inspired by JavaScript Generator, Java Stream, and MySQL Index. Supports lazy evaluation, async streams, statistics, and IO-like operations.",
9
- "version": "2.0.0",
9
+ "version": "2.0.1",
10
10
  "type": "module",
11
11
  "readme": "readme.md",
12
12
  "main": "dist/index.js",