@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/Schema.d.ts CHANGED
@@ -20,6 +20,13 @@ export declare class Schema<C = any> implements IRef {
20
20
  */
21
21
  static initialize(instance: any): void;
22
22
  static is(type: DefinitionType): boolean;
23
+ /**
24
+ * Check if a value is an instance of Schema.
25
+ * This method uses duck-typing to avoid issues with multiple @colyseus/schema versions.
26
+ * @param obj Value to check
27
+ * @returns true if the value is a Schema instance
28
+ */
29
+ static isSchema(obj: any): obj is Schema;
23
30
  /**
24
31
  * Track property changes
25
32
  */
package/build/index.cjs CHANGED
@@ -3668,6 +3668,15 @@ class Schema {
3668
3668
  static is(type) {
3669
3669
  return typeof (type[Symbol.metadata]) === "object";
3670
3670
  }
3671
+ /**
3672
+ * Check if a value is an instance of Schema.
3673
+ * This method uses duck-typing to avoid issues with multiple @colyseus/schema versions.
3674
+ * @param obj Value to check
3675
+ * @returns true if the value is a Schema instance
3676
+ */
3677
+ static isSchema(obj) {
3678
+ return typeof obj?.assign === "function";
3679
+ }
3671
3680
  /**
3672
3681
  * Track property changes
3673
3682
  */
@@ -4872,13 +4881,13 @@ function getDecoderStateCallbacks(decoder) {
4872
4881
  // trigger onRemove on child structure.
4873
4882
  //
4874
4883
  if ((change.op & exports.OPERATION.DELETE) === exports.OPERATION.DELETE &&
4875
- change.previousValue instanceof Schema) {
4884
+ Schema.isSchema(change.previousValue)) {
4876
4885
  const deleteCallbacks = callbacks[change.previousValue[$refId]]?.[exports.OPERATION.DELETE];
4877
4886
  for (let i = deleteCallbacks?.length - 1; i >= 0; i--) {
4878
4887
  deleteCallbacks[i]();
4879
4888
  }
4880
4889
  }
4881
- if (ref instanceof Schema) {
4890
+ if (Schema.isSchema(ref)) {
4882
4891
  //
4883
4892
  // Handle schema instance
4884
4893
  //
@@ -5262,7 +5271,7 @@ class StateCallbackStrategy {
5262
5271
  // trigger onRemove on child structure.
5263
5272
  //
5264
5273
  if ((change.op & exports.OPERATION.DELETE) === exports.OPERATION.DELETE &&
5265
- change.previousValue instanceof Schema) {
5274
+ Schema.isSchema(change.previousValue)) {
5266
5275
  const childRefId = change.previousValue[$refId];
5267
5276
  const deleteCallbacks = this.callbacks[childRefId]?.[exports.OPERATION.DELETE];
5268
5277
  if (deleteCallbacks) {
@@ -5271,7 +5280,7 @@ class StateCallbackStrategy {
5271
5280
  }
5272
5281
  }
5273
5282
  }
5274
- if (ref instanceof Schema) {
5283
+ if (Schema.isSchema(ref)) {
5275
5284
  //
5276
5285
  // Handle Schema instance
5277
5286
  //