@colyseus/schema 4.0.4 → 4.0.5

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.js CHANGED
@@ -3672,6 +3672,15 @@
3672
3672
  static is(type) {
3673
3673
  return typeof (type[Symbol.metadata]) === "object";
3674
3674
  }
3675
+ /**
3676
+ * Check if a value is an instance of Schema.
3677
+ * This method uses duck-typing to avoid issues with multiple @colyseus/schema versions.
3678
+ * @param obj Value to check
3679
+ * @returns true if the value is a Schema instance
3680
+ */
3681
+ static isSchema(obj) {
3682
+ return typeof obj?.assign === "function";
3683
+ }
3675
3684
  /**
3676
3685
  * Track property changes
3677
3686
  */
@@ -4876,13 +4885,13 @@
4876
4885
  // trigger onRemove on child structure.
4877
4886
  //
4878
4887
  if ((change.op & exports.OPERATION.DELETE) === exports.OPERATION.DELETE &&
4879
- change.previousValue instanceof Schema) {
4888
+ Schema.isSchema(change.previousValue)) {
4880
4889
  const deleteCallbacks = callbacks[change.previousValue[$refId]]?.[exports.OPERATION.DELETE];
4881
4890
  for (let i = deleteCallbacks?.length - 1; i >= 0; i--) {
4882
4891
  deleteCallbacks[i]();
4883
4892
  }
4884
4893
  }
4885
- if (ref instanceof Schema) {
4894
+ if (Schema.isSchema(ref)) {
4886
4895
  //
4887
4896
  // Handle schema instance
4888
4897
  //
@@ -5266,7 +5275,7 @@
5266
5275
  // trigger onRemove on child structure.
5267
5276
  //
5268
5277
  if ((change.op & exports.OPERATION.DELETE) === exports.OPERATION.DELETE &&
5269
- change.previousValue instanceof Schema) {
5278
+ Schema.isSchema(change.previousValue)) {
5270
5279
  const childRefId = change.previousValue[$refId];
5271
5280
  const deleteCallbacks = this.callbacks[childRefId]?.[exports.OPERATION.DELETE];
5272
5281
  if (deleteCallbacks) {
@@ -5275,7 +5284,7 @@
5275
5284
  }
5276
5285
  }
5277
5286
  }
5278
- if (ref instanceof Schema) {
5287
+ if (Schema.isSchema(ref)) {
5279
5288
  //
5280
5289
  // Handle Schema instance
5281
5290
  //
package/build/index.mjs CHANGED
@@ -3666,6 +3666,15 @@ class Schema {
3666
3666
  static is(type) {
3667
3667
  return typeof (type[Symbol.metadata]) === "object";
3668
3668
  }
3669
+ /**
3670
+ * Check if a value is an instance of Schema.
3671
+ * This method uses duck-typing to avoid issues with multiple @colyseus/schema versions.
3672
+ * @param obj Value to check
3673
+ * @returns true if the value is a Schema instance
3674
+ */
3675
+ static isSchema(obj) {
3676
+ return typeof obj?.assign === "function";
3677
+ }
3669
3678
  /**
3670
3679
  * Track property changes
3671
3680
  */
@@ -4870,13 +4879,13 @@ function getDecoderStateCallbacks(decoder) {
4870
4879
  // trigger onRemove on child structure.
4871
4880
  //
4872
4881
  if ((change.op & OPERATION.DELETE) === OPERATION.DELETE &&
4873
- change.previousValue instanceof Schema) {
4882
+ Schema.isSchema(change.previousValue)) {
4874
4883
  const deleteCallbacks = callbacks[change.previousValue[$refId]]?.[OPERATION.DELETE];
4875
4884
  for (let i = deleteCallbacks?.length - 1; i >= 0; i--) {
4876
4885
  deleteCallbacks[i]();
4877
4886
  }
4878
4887
  }
4879
- if (ref instanceof Schema) {
4888
+ if (Schema.isSchema(ref)) {
4880
4889
  //
4881
4890
  // Handle schema instance
4882
4891
  //
@@ -5260,7 +5269,7 @@ class StateCallbackStrategy {
5260
5269
  // trigger onRemove on child structure.
5261
5270
  //
5262
5271
  if ((change.op & OPERATION.DELETE) === OPERATION.DELETE &&
5263
- change.previousValue instanceof Schema) {
5272
+ Schema.isSchema(change.previousValue)) {
5264
5273
  const childRefId = change.previousValue[$refId];
5265
5274
  const deleteCallbacks = this.callbacks[childRefId]?.[OPERATION.DELETE];
5266
5275
  if (deleteCallbacks) {
@@ -5269,7 +5278,7 @@ class StateCallbackStrategy {
5269
5278
  }
5270
5279
  }
5271
5280
  }
5272
- if (ref instanceof Schema) {
5281
+ if (Schema.isSchema(ref)) {
5273
5282
  //
5274
5283
  // Handle Schema instance
5275
5284
  //