@colyseus/schema 2.0.28 → 2.0.30

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.
Files changed (55) hide show
  1. package/build/cjs/index.js +29 -31
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/esm/index.mjs +26 -43
  4. package/build/esm/index.mjs.map +1 -1
  5. package/build/umd/index.js +29 -31
  6. package/lib/index.js +2 -4
  7. package/lib/index.js.map +1 -1
  8. package/lib/types/ArraySchema.js +7 -0
  9. package/lib/types/ArraySchema.js.map +1 -1
  10. package/lib/utils.d.ts +0 -1
  11. package/lib/utils.js +1 -26
  12. package/lib/utils.js.map +1 -1
  13. package/package.json +1 -1
  14. package/src/index.ts +0 -3
  15. package/src/types/ArraySchema.ts +7 -0
  16. package/src/utils.ts +0 -25
  17. package/lib/Decoder.d.ts +0 -16
  18. package/lib/Decoder.js +0 -182
  19. package/lib/Decoder.js.map +0 -1
  20. package/lib/Encoder.d.ts +0 -13
  21. package/lib/Encoder.js +0 -79
  22. package/lib/Encoder.js.map +0 -1
  23. package/lib/Metadata.d.ts +0 -22
  24. package/lib/Metadata.js +0 -65
  25. package/lib/Metadata.js.map +0 -1
  26. package/lib/changes/ChangeSet.d.ts +0 -12
  27. package/lib/changes/ChangeSet.js +0 -35
  28. package/lib/changes/ChangeSet.js.map +0 -1
  29. package/lib/changes/DecodeOperation.d.ts +0 -15
  30. package/lib/changes/DecodeOperation.js +0 -186
  31. package/lib/changes/DecodeOperation.js.map +0 -1
  32. package/lib/changes/EncodeOperation.d.ts +0 -18
  33. package/lib/changes/EncodeOperation.js +0 -130
  34. package/lib/changes/EncodeOperation.js.map +0 -1
  35. package/lib/changes/consts.d.ts +0 -14
  36. package/lib/changes/consts.js +0 -18
  37. package/lib/changes/consts.js.map +0 -1
  38. package/lib/decoder/strategy/StateCallbacks.d.ts +0 -6
  39. package/lib/decoder/strategy/StateCallbacks.js +0 -20
  40. package/lib/decoder/strategy/StateCallbacks.js.map +0 -1
  41. package/lib/decoding/decode.d.ts +0 -48
  42. package/lib/decoding/decode.js +0 -267
  43. package/lib/decoding/decode.js.map +0 -1
  44. package/lib/encoding/assert.d.ts +0 -9
  45. package/lib/encoding/assert.js +0 -47
  46. package/lib/encoding/assert.js.map +0 -1
  47. package/lib/symbol.shim.d.ts +0 -6
  48. package/lib/symbol.shim.js +0 -4
  49. package/lib/symbol.shim.js.map +0 -1
  50. package/lib/usage.d.ts +0 -1
  51. package/lib/usage.js +0 -22
  52. package/lib/usage.js.map +0 -1
  53. package/lib/v3.d.ts +0 -1
  54. package/lib/v3.js +0 -313
  55. package/lib/v3.js.map +0 -1
@@ -479,6 +479,13 @@ var ArraySchema = /** @class */ (function () {
479
479
  //
480
480
  // FIXME: this should be O(1)
481
481
  //
482
+ index = Math.trunc(index) || 0;
483
+ // Allow negative indexing from the end
484
+ if (index < 0)
485
+ index += this.length;
486
+ // OOB access is guaranteed to return undefined
487
+ if (index < 0 || index >= this.length)
488
+ return undefined;
482
489
  var key = Array.from(this.$items.keys())[index];
483
490
  return this.$items.get(key);
484
491
  };
@@ -3184,6 +3191,28 @@ var Schema = /** @class */ (function () {
3184
3191
  return Schema;
3185
3192
  }());
3186
3193
 
3194
+ function dumpChanges(schema) {
3195
+ var changeTrees = [schema['$changes']];
3196
+ var numChangeTrees = 1;
3197
+ var dump = {};
3198
+ var currentStructure = dump;
3199
+ var _loop_1 = function (i) {
3200
+ var changeTree = changeTrees[i];
3201
+ changeTree.changes.forEach(function (change) {
3202
+ var ref = changeTree.ref;
3203
+ var fieldIndex = change.index;
3204
+ var field = (ref['_definition'])
3205
+ ? ref['_definition'].fieldsByIndex[fieldIndex]
3206
+ : ref['$indexes'].get(fieldIndex);
3207
+ currentStructure[field] = changeTree.getValue(fieldIndex);
3208
+ });
3209
+ };
3210
+ for (var i = 0; i < numChangeTrees; i++) {
3211
+ _loop_1(i);
3212
+ }
3213
+ return dump;
3214
+ }
3215
+
3187
3216
  var reflectionContext = { context: new Context() };
3188
3217
  /**
3189
3218
  * Reflection
@@ -3342,41 +3371,10 @@ var Reflection = /** @class */ (function (_super) {
3342
3371
  return Reflection;
3343
3372
  }(Schema));
3344
3373
 
3345
- function dumpChanges(schema) {
3346
- var changeTrees = [schema['$changes']];
3347
- var numChangeTrees = 1;
3348
- var dump = {};
3349
- var currentStructure = dump;
3350
- var _loop_1 = function (i) {
3351
- var changeTree = changeTrees[i];
3352
- changeTree.changes.forEach(function (change) {
3353
- var ref = changeTree.ref;
3354
- var fieldIndex = change.index;
3355
- var field = (ref['_definition'])
3356
- ? ref['_definition'].fieldsByIndex[fieldIndex]
3357
- : ref['$indexes'].get(fieldIndex);
3358
- currentStructure[field] = changeTree.getValue(fieldIndex);
3359
- });
3360
- };
3361
- for (var i = 0; i < numChangeTrees; i++) {
3362
- _loop_1(i);
3363
- }
3364
- return dump;
3365
- }
3366
- function checkTypeScriptConfig() {
3367
- var r = new ReflectionField();
3368
- var descriptor = Object.getOwnPropertyDescriptor(r, "name");
3369
- if (descriptor.get === undefined || descriptor.set === undefined) {
3370
- console.error("\n\u203C\uFE0F Please check your tsconfig.json \u203C\uFE0F\n\n@colyseus/schema requires the following settings:\n-------------------------------------------------\n\n \"compilerOptions\": {\n // ...\n \"useDefineForClassFields\": false,\n \"experimentalDecorators\": true,\n // ...\n }\n\n-------------------------------------------------\nMore info \u2192 https://github.com/colyseus/colyseus/issues/510#issuecomment-1507828422\n");
3371
- process.exit(1);
3372
- }
3373
- }
3374
-
3375
3374
  registerType("map", { constructor: MapSchema });
3376
3375
  registerType("array", { constructor: ArraySchema });
3377
3376
  registerType("set", { constructor: SetSchema });
3378
3377
  registerType("collection", { constructor: CollectionSchema, });
3379
- checkTypeScriptConfig();
3380
3378
 
3381
3379
  exports.ArraySchema = ArraySchema;
3382
3380
  exports.CollectionSchema = CollectionSchema;