@colyseus/schema 4.0.15 → 4.0.17

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
@@ -53,7 +53,7 @@ export declare class Schema<C = any> implements IRef {
53
53
  * @param jsonData JSON data to restore the instance from
54
54
  * @returns
55
55
  */
56
- restore(jsonData: ToJSON<this>): this;
56
+ restore<T extends Partial<this>>(jsonData: ToJSON<T>): this;
57
57
  /**
58
58
  * (Server-side): Flag a property to be encoded for the next patch.
59
59
  * @param instance Schema instance
@@ -62,7 +62,7 @@ export declare class Schema<C = any> implements IRef {
62
62
  */
63
63
  setDirty<K extends NonFunctionPropNames<this>>(property: K | number, operation?: OPERATION): void;
64
64
  clone(): this;
65
- toJSON(this: any): ToJSON<this>;
65
+ toJSON(this: any): ToJSON<Partial<this>>;
66
66
  /**
67
67
  * Used in tests only
68
68
  * @internal
@@ -63,7 +63,7 @@ export declare function view<T>(tag?: number): (target: T, fieldName: string) =>
63
63
  export declare function unreliable<T>(target: T, field: string): void;
64
64
  export declare function type(type: DefinitionType, options?: TypeOptions): PropertyDecorator;
65
65
  export declare function getPropertyDescriptor(fieldCached: string, fieldIndex: number, type: DefinitionType, complexTypeKlass: TypeDefinition): {
66
- get: (this: Schema) => number | ((index: number) => any) | ((index: number) => void) | (() => Schema<any>) | (<T extends Partial<Schema<any>>>(props: AssignableProps<T>) => Schema<any>) | ((jsonData: import("./index.js").ToJSON<Schema<any>>) => Schema<any>) | (<K extends "~refId">(property: number | K, operation?: OPERATION) => void) | ((this: any) => import("./index.js").ToJSON<Schema<any>>) | (() => void);
66
+ get: (this: Schema) => number | ((index: number) => any) | ((index: number) => void) | (() => Schema<any>) | (<T extends Partial<Schema<any>>>(props: AssignableProps<T>) => Schema<any>) | (<T extends Partial<Schema<any>>>(jsonData: import("./index.js").ToJSON<T>) => Schema<any>) | (<K extends "~refId">(property: number | K, operation?: OPERATION) => void) | ((this: any) => import("./index.js").ToJSON<Partial<Schema<any>>>) | (() => void);
67
67
  set: (this: Schema, value: any) => void;
68
68
  enumerable: boolean;
69
69
  configurable: boolean;
package/build/index.cjs CHANGED
@@ -5690,12 +5690,29 @@ class StateView {
5690
5690
  }
5691
5691
  else {
5692
5692
  // delete all "tagged" properties.
5693
- metadata?.[$viewFieldIndexes]?.forEach((index) => changes[index] = exports.OPERATION.DELETE);
5693
+ metadata?.[$viewFieldIndexes]?.forEach((index) => {
5694
+ changes[index] = exports.OPERATION.DELETE;
5695
+ // Remove child structures of @view() fields from visible set.
5696
+ // (They were added during view.add() via forEachChild)
5697
+ const value = changeTree.ref[metadata[index].name];
5698
+ if (value?.[$changes]) {
5699
+ this.visible.delete(value[$changes]);
5700
+ this._recursiveDeleteVisibleChangeTree(value[$changes]);
5701
+ }
5702
+ });
5694
5703
  }
5695
5704
  }
5696
5705
  else {
5697
5706
  // delete only tagged properties
5698
- metadata?.[$fieldIndexesByViewTag][tag].forEach((index) => changes[index] = exports.OPERATION.DELETE);
5707
+ metadata?.[$fieldIndexesByViewTag][tag].forEach((index) => {
5708
+ changes[index] = exports.OPERATION.DELETE;
5709
+ // Remove child structures from visible set
5710
+ const value = changeTree.ref[metadata[index].name];
5711
+ if (value?.[$changes]) {
5712
+ this.visible.delete(value[$changes]);
5713
+ this._recursiveDeleteVisibleChangeTree(value[$changes]);
5714
+ }
5715
+ });
5699
5716
  }
5700
5717
  // remove tag
5701
5718
  if (this.tags && this.tags.has(changeTree)) {