@colyseus/schema 3.0.47 → 3.0.49
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/cjs/index.js +27 -9
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +27 -9
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +27 -9
- package/lib/annotations.d.ts +1 -1
- package/lib/annotations.js +21 -9
- package/lib/annotations.js.map +1 -1
- package/lib/decoder/DecodeOperation.js.map +1 -1
- package/lib/types/custom/MapSchema.d.ts +1 -1
- package/lib/types/custom/MapSchema.js +6 -0
- package/lib/types/custom/MapSchema.js.map +1 -1
- package/package.json +1 -1
- package/src/annotations.ts +24 -10
- package/src/decoder/DecodeOperation.ts +0 -1
- package/src/types/custom/MapSchema.ts +9 -1
- package/lib/bench_encode.d.ts +0 -1
- package/lib/bench_encode.js +0 -130
- package/lib/bench_encode.js.map +0 -1
- package/lib/debug.d.ts +0 -1
- package/lib/debug.js +0 -51
- package/lib/debug.js.map +0 -1
- package/src/bench_encode.ts +0 -108
- package/src/debug.ts +0 -55
package/build/cjs/index.js
CHANGED
|
@@ -2801,6 +2801,12 @@ class MapSchema {
|
|
|
2801
2801
|
this.$indexes.delete(index);
|
|
2802
2802
|
}
|
|
2803
2803
|
[$onEncodeEnd]() {
|
|
2804
|
+
const changeTree = this[$changes];
|
|
2805
|
+
// cleanup changeTree.indexes of deleted keys
|
|
2806
|
+
for (const indexStr in this.deletedItems) {
|
|
2807
|
+
const key = this.$indexes.get(parseInt(indexStr));
|
|
2808
|
+
delete changeTree.indexes[key];
|
|
2809
|
+
}
|
|
2804
2810
|
this.deletedItems = {};
|
|
2805
2811
|
}
|
|
2806
2812
|
toJSON() {
|
|
@@ -3174,20 +3180,29 @@ function defineTypes(target, fields, options) {
|
|
|
3174
3180
|
}
|
|
3175
3181
|
return target;
|
|
3176
3182
|
}
|
|
3177
|
-
function schema(
|
|
3183
|
+
function schema(fieldsAndMethods, name, inherits = Schema) {
|
|
3184
|
+
const fields = {};
|
|
3185
|
+
const methods = {};
|
|
3178
3186
|
const defaultValues = {};
|
|
3179
3187
|
const viewTagFields = {};
|
|
3180
|
-
for (let fieldName in
|
|
3181
|
-
const
|
|
3182
|
-
if (typeof (
|
|
3183
|
-
if (
|
|
3184
|
-
defaultValues[fieldName] =
|
|
3188
|
+
for (let fieldName in fieldsAndMethods) {
|
|
3189
|
+
const value = fieldsAndMethods[fieldName];
|
|
3190
|
+
if (typeof (value) === "object") {
|
|
3191
|
+
if (value['default'] !== undefined) {
|
|
3192
|
+
defaultValues[fieldName] = value['default'];
|
|
3185
3193
|
}
|
|
3186
|
-
if (
|
|
3187
|
-
viewTagFields[fieldName] = (typeof (
|
|
3194
|
+
if (value['view'] !== undefined) {
|
|
3195
|
+
viewTagFields[fieldName] = (typeof (value['view']) === "boolean")
|
|
3188
3196
|
? DEFAULT_VIEW_TAG
|
|
3189
|
-
:
|
|
3197
|
+
: value['view'];
|
|
3190
3198
|
}
|
|
3199
|
+
fields[fieldName] = value;
|
|
3200
|
+
}
|
|
3201
|
+
else if (typeof (value) === "function") {
|
|
3202
|
+
methods[fieldName] = value;
|
|
3203
|
+
}
|
|
3204
|
+
else {
|
|
3205
|
+
fields[fieldName] = value;
|
|
3191
3206
|
}
|
|
3192
3207
|
}
|
|
3193
3208
|
const klass = Metadata.setFields(class extends inherits {
|
|
@@ -3199,6 +3214,9 @@ function schema(fields, name, inherits = Schema) {
|
|
|
3199
3214
|
for (let fieldName in viewTagFields) {
|
|
3200
3215
|
view(viewTagFields[fieldName])(klass.prototype, fieldName);
|
|
3201
3216
|
}
|
|
3217
|
+
for (let methodName in methods) {
|
|
3218
|
+
klass.prototype[methodName] = methods[methodName];
|
|
3219
|
+
}
|
|
3202
3220
|
if (name) {
|
|
3203
3221
|
Object.defineProperty(klass, "name", { value: name });
|
|
3204
3222
|
}
|