@colyseus/schema 3.0.15 → 3.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.
@@ -520,7 +520,7 @@ export function schema<T extends Definition, P extends typeof Schema = typeof Sc
520
520
  }
521
521
  }
522
522
 
523
- const klass = Metadata.setFields(class extends inherits {
523
+ const klass = Metadata.setFields<any>(class extends inherits {
524
524
  constructor (...args: any[]) {
525
525
  args[0] = Object.assign({}, defaultValues, args[0]);
526
526
  super(...args);
@@ -73,18 +73,6 @@ export function decodeValue(
73
73
  const refId = decode.number(bytes, it);
74
74
  value = $root.refs.get(refId);
75
75
 
76
- if (previousValue) {
77
- const previousRefId = $root.refIds.get(previousValue);
78
- if (
79
- previousRefId &&
80
- refId !== previousRefId &&
81
- // FIXME: we may need to check for REPLACE operation as well
82
- ((operation & OPERATION.DELETE) === OPERATION.DELETE)
83
- ) {
84
- $root.removeRef(previousRefId);
85
- }
86
- }
87
-
88
76
  if ((operation & OPERATION.ADD) === OPERATION.ADD) {
89
77
  const childType = decoder.getInstanceType(bytes, it, type);
90
78
  if (!value) {
@@ -101,7 +89,6 @@ export function decodeValue(
101
89
  );
102
90
  }
103
91
 
104
-
105
92
  } else if (typeof(type) === "string") {
106
93
  //
107
94
  // primitive value (number, string, boolean, etc)
@@ -123,8 +110,6 @@ export function decodeValue(
123
110
  let previousRefId = $root.refIds.get(previousValue);
124
111
 
125
112
  if (previousRefId !== undefined && refId !== previousRefId) {
126
- $root.removeRef(previousRefId);
127
-
128
113
  //
129
114
  // enqueue onRemove if structure has been replaced.
130
115
  //
@@ -153,7 +138,10 @@ export function decodeValue(
153
138
  }
154
139
  }
155
140
 
156
- $root.addRef(refId, value, (valueRef !== previousValue));
141
+ $root.addRef(refId, value, (
142
+ valueRef !== previousValue ||
143
+ (operation === OPERATION.DELETE_AND_ADD && valueRef === previousValue)
144
+ ));
157
145
  }
158
146
 
159
147
  return { value, previousValue };
@@ -18,6 +18,7 @@ import type { CollectionSchema } from "../../types/custom/CollectionSchema";
18
18
  //
19
19
 
20
20
  export type SchemaCallbackProxy<RoomState> = (<T extends Schema>(instance: T) => CallbackProxy<T>);
21
+ export type GetCallbackProxy = SchemaCallbackProxy<any>; // workaround for compatibility for < colyseus.js0.16.6. Remove me on next major release.
21
22
 
22
23
  export type CallbackProxy<T> = unknown extends T // is "any"?
23
24
  ? SchemaCallback<T> & CollectionCallback<any, any>