@colyseus/schema 4.0.28 → 4.0.30
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/build/index.cjs +31 -0
- package/build/index.cjs.map +1 -1
- package/build/index.js +31 -0
- package/build/index.mjs +31 -0
- package/build/index.mjs.map +1 -1
- package/build/types/custom/MapSchema.d.ts +18 -1
- package/package.json +3 -2
- package/src/types/custom/MapSchema.ts +34 -1
package/build/index.js
CHANGED
|
@@ -2783,6 +2783,37 @@
|
|
|
2783
2783
|
get(key) {
|
|
2784
2784
|
return this.$items.get(key);
|
|
2785
2785
|
}
|
|
2786
|
+
/**
|
|
2787
|
+
* Returns the value for `key` if present. Otherwise inserts `defaultValue`
|
|
2788
|
+
* (tracked as an ADD change, like `set()`) and returns it.
|
|
2789
|
+
*
|
|
2790
|
+
* Mirrors `Map.prototype.getOrInsert` (TC39 "upsert" proposal, typed in
|
|
2791
|
+
* TypeScript 6's standard library).
|
|
2792
|
+
*/
|
|
2793
|
+
getOrInsert(key, defaultValue) {
|
|
2794
|
+
if (this.$items.has(key)) {
|
|
2795
|
+
return this.$items.get(key);
|
|
2796
|
+
}
|
|
2797
|
+
this.set(key, defaultValue);
|
|
2798
|
+
return defaultValue;
|
|
2799
|
+
}
|
|
2800
|
+
/**
|
|
2801
|
+
* Returns the value for `key` if present. Otherwise computes a value via
|
|
2802
|
+
* `callbackfn(key)`, inserts it (tracked as an ADD change, like `set()`)
|
|
2803
|
+
* and returns it. The callback is only invoked when the key is missing.
|
|
2804
|
+
*
|
|
2805
|
+
* Mirrors `Map.prototype.getOrInsertComputed` (TC39 "upsert" proposal,
|
|
2806
|
+
* typed in TypeScript 6's standard library).
|
|
2807
|
+
*/
|
|
2808
|
+
getOrInsertComputed(key, callbackfn) {
|
|
2809
|
+
if (this.$items.has(key)) {
|
|
2810
|
+
return this.$items.get(key);
|
|
2811
|
+
}
|
|
2812
|
+
const value = callbackfn(key);
|
|
2813
|
+
// per spec: overwrites even if callbackfn itself inserted `key`
|
|
2814
|
+
this.set(key, value);
|
|
2815
|
+
return value;
|
|
2816
|
+
}
|
|
2786
2817
|
delete(key) {
|
|
2787
2818
|
if (!this.$items.has(key)) {
|
|
2788
2819
|
return false;
|
package/build/index.mjs
CHANGED
|
@@ -2777,6 +2777,37 @@ class MapSchema {
|
|
|
2777
2777
|
get(key) {
|
|
2778
2778
|
return this.$items.get(key);
|
|
2779
2779
|
}
|
|
2780
|
+
/**
|
|
2781
|
+
* Returns the value for `key` if present. Otherwise inserts `defaultValue`
|
|
2782
|
+
* (tracked as an ADD change, like `set()`) and returns it.
|
|
2783
|
+
*
|
|
2784
|
+
* Mirrors `Map.prototype.getOrInsert` (TC39 "upsert" proposal, typed in
|
|
2785
|
+
* TypeScript 6's standard library).
|
|
2786
|
+
*/
|
|
2787
|
+
getOrInsert(key, defaultValue) {
|
|
2788
|
+
if (this.$items.has(key)) {
|
|
2789
|
+
return this.$items.get(key);
|
|
2790
|
+
}
|
|
2791
|
+
this.set(key, defaultValue);
|
|
2792
|
+
return defaultValue;
|
|
2793
|
+
}
|
|
2794
|
+
/**
|
|
2795
|
+
* Returns the value for `key` if present. Otherwise computes a value via
|
|
2796
|
+
* `callbackfn(key)`, inserts it (tracked as an ADD change, like `set()`)
|
|
2797
|
+
* and returns it. The callback is only invoked when the key is missing.
|
|
2798
|
+
*
|
|
2799
|
+
* Mirrors `Map.prototype.getOrInsertComputed` (TC39 "upsert" proposal,
|
|
2800
|
+
* typed in TypeScript 6's standard library).
|
|
2801
|
+
*/
|
|
2802
|
+
getOrInsertComputed(key, callbackfn) {
|
|
2803
|
+
if (this.$items.has(key)) {
|
|
2804
|
+
return this.$items.get(key);
|
|
2805
|
+
}
|
|
2806
|
+
const value = callbackfn(key);
|
|
2807
|
+
// per spec: overwrites even if callbackfn itself inserted `key`
|
|
2808
|
+
this.set(key, value);
|
|
2809
|
+
return value;
|
|
2810
|
+
}
|
|
2780
2811
|
delete(key) {
|
|
2781
2812
|
if (!this.$items.has(key)) {
|
|
2782
2813
|
return false;
|