@colyseus/schema 4.0.1 → 4.0.3

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 (190) hide show
  1. package/{lib → build}/Metadata.d.ts +2 -2
  2. package/{lib → build}/Reflection.d.ts +13 -13
  3. package/{lib → build}/Schema.d.ts +10 -10
  4. package/{lib → build}/annotations.d.ts +10 -10
  5. package/build/codegen/languages/cpp.d.ts +3 -0
  6. package/build/codegen/languages/csharp.d.ts +4 -0
  7. package/build/codegen/languages/haxe.d.ts +3 -0
  8. package/{lib → build}/codegen/languages/java.d.ts +2 -2
  9. package/build/codegen/languages/js.d.ts +3 -0
  10. package/build/codegen/languages/lua.d.ts +3 -0
  11. package/build/codegen/languages/ts.d.ts +3 -0
  12. package/{lib → build}/codegen/parser.d.ts +1 -1
  13. package/{lib → build}/decoder/DecodeOperation.d.ts +5 -5
  14. package/{lib → build}/decoder/Decoder.d.ts +7 -7
  15. package/{lib → build}/decoder/ReferenceTracker.d.ts +1 -1
  16. package/{lib → build}/decoder/strategy/Callbacks.d.ts +11 -11
  17. package/{lib → build}/decoder/strategy/RawChanges.d.ts +2 -2
  18. package/{lib → build}/decoder/strategy/getDecoderStateCallbacks.d.ts +3 -3
  19. package/{lib → build}/encoder/ChangeTree.d.ts +11 -11
  20. package/{lib → build}/encoder/EncodeOperation.d.ts +5 -5
  21. package/{lib → build}/encoder/Encoder.d.ts +6 -6
  22. package/{lib → build}/encoder/Root.d.ts +2 -2
  23. package/{lib → build}/encoder/StateView.d.ts +1 -1
  24. package/{lib → build}/encoding/assert.d.ts +6 -6
  25. package/{lib → build}/encoding/decode.d.ts +1 -1
  26. package/{lib → build}/encoding/encode.d.ts +1 -1
  27. package/build/{cjs/index.js → index.cjs} +1 -1
  28. package/build/index.cjs.map +1 -0
  29. package/build/index.d.ts +32 -0
  30. package/build/index.mjs.map +1 -0
  31. package/{lib → build}/types/HelperTypes.d.ts +6 -6
  32. package/{lib → build}/types/TypeContext.d.ts +1 -1
  33. package/{lib → build}/types/custom/ArraySchema.d.ts +8 -8
  34. package/{lib → build}/types/custom/CollectionSchema.d.ts +7 -7
  35. package/{lib → build}/types/custom/MapSchema.d.ts +7 -7
  36. package/{lib → build}/types/custom/SetSchema.d.ts +7 -7
  37. package/{lib → build}/types/registry.d.ts +2 -2
  38. package/{lib → build}/utils.d.ts +1 -1
  39. package/package.json +15 -14
  40. package/src/Metadata.ts +5 -5
  41. package/src/Reflection.ts +7 -7
  42. package/src/Schema.ts +11 -11
  43. package/src/annotations.ts +13 -13
  44. package/src/codegen/api.ts +10 -3
  45. package/src/codegen/cli.ts +2 -2
  46. package/src/codegen/languages/cpp.ts +2 -2
  47. package/src/codegen/languages/csharp.ts +3 -3
  48. package/src/codegen/languages/haxe.ts +2 -2
  49. package/src/codegen/languages/java.ts +2 -2
  50. package/src/codegen/languages/js.ts +2 -2
  51. package/src/codegen/languages/lua.ts +2 -2
  52. package/src/codegen/languages/ts.ts +2 -2
  53. package/src/codegen/parser.ts +7 -2
  54. package/src/codegen/types.ts +5 -0
  55. package/src/decoder/DecodeOperation.ts +14 -14
  56. package/src/decoder/Decoder.ts +11 -11
  57. package/src/decoder/ReferenceTracker.ts +8 -8
  58. package/src/decoder/strategy/Callbacks.ts +12 -12
  59. package/src/decoder/strategy/RawChanges.ts +2 -2
  60. package/src/decoder/strategy/getDecoderStateCallbacks.ts +10 -10
  61. package/src/encoder/ChangeTree.ts +13 -13
  62. package/src/encoder/EncodeOperation.ts +9 -9
  63. package/src/encoder/Encoder.ts +10 -10
  64. package/src/encoder/Root.ts +4 -4
  65. package/src/encoder/StateView.ts +7 -7
  66. package/src/encoding/assert.ts +6 -6
  67. package/src/encoding/decode.ts +1 -1
  68. package/src/encoding/encode.ts +1 -1
  69. package/src/index.ts +27 -27
  70. package/src/types/HelperTypes.ts +6 -6
  71. package/src/types/TypeContext.ts +3 -3
  72. package/src/types/custom/ArraySchema.ts +11 -11
  73. package/src/types/custom/CollectionSchema.ts +9 -9
  74. package/src/types/custom/MapSchema.ts +10 -10
  75. package/src/types/custom/SetSchema.ts +9 -9
  76. package/src/types/registry.ts +3 -3
  77. package/src/utils.ts +3 -3
  78. package/src/v3_bench.ts +1 -1
  79. package/build/cjs/index.js.map +0 -1
  80. package/build/esm/index.mjs.map +0 -1
  81. package/lib/Metadata.js +0 -260
  82. package/lib/Metadata.js.map +0 -1
  83. package/lib/Reflection.js +0 -182
  84. package/lib/Reflection.js.map +0 -1
  85. package/lib/Schema.js +0 -356
  86. package/lib/Schema.js.map +0 -1
  87. package/lib/annotations.js +0 -484
  88. package/lib/annotations.js.map +0 -1
  89. package/lib/bench_encode.d.ts +0 -1
  90. package/lib/bench_encode.js +0 -126
  91. package/lib/bench_encode.js.map +0 -1
  92. package/lib/codegen/api.js +0 -87
  93. package/lib/codegen/api.js.map +0 -1
  94. package/lib/codegen/argv.js +0 -41
  95. package/lib/codegen/argv.js.map +0 -1
  96. package/lib/codegen/cli.js +0 -63
  97. package/lib/codegen/cli.js.map +0 -1
  98. package/lib/codegen/languages/cpp.d.ts +0 -3
  99. package/lib/codegen/languages/cpp.js +0 -261
  100. package/lib/codegen/languages/cpp.js.map +0 -1
  101. package/lib/codegen/languages/csharp.d.ts +0 -4
  102. package/lib/codegen/languages/csharp.js +0 -157
  103. package/lib/codegen/languages/csharp.js.map +0 -1
  104. package/lib/codegen/languages/haxe.d.ts +0 -3
  105. package/lib/codegen/languages/haxe.js +0 -103
  106. package/lib/codegen/languages/haxe.js.map +0 -1
  107. package/lib/codegen/languages/java.js +0 -103
  108. package/lib/codegen/languages/java.js.map +0 -1
  109. package/lib/codegen/languages/js.d.ts +0 -3
  110. package/lib/codegen/languages/js.js +0 -104
  111. package/lib/codegen/languages/js.js.map +0 -1
  112. package/lib/codegen/languages/lua.d.ts +0 -3
  113. package/lib/codegen/languages/lua.js +0 -106
  114. package/lib/codegen/languages/lua.js.map +0 -1
  115. package/lib/codegen/languages/ts.d.ts +0 -3
  116. package/lib/codegen/languages/ts.js +0 -119
  117. package/lib/codegen/languages/ts.js.map +0 -1
  118. package/lib/codegen/parser.js +0 -364
  119. package/lib/codegen/parser.js.map +0 -1
  120. package/lib/codegen/types.js +0 -181
  121. package/lib/codegen/types.js.map +0 -1
  122. package/lib/decoder/DecodeOperation.js +0 -255
  123. package/lib/decoder/DecodeOperation.js.map +0 -1
  124. package/lib/decoder/Decoder.js +0 -118
  125. package/lib/decoder/Decoder.js.map +0 -1
  126. package/lib/decoder/ReferenceTracker.js +0 -139
  127. package/lib/decoder/ReferenceTracker.js.map +0 -1
  128. package/lib/decoder/strategy/Callbacks.js +0 -340
  129. package/lib/decoder/strategy/Callbacks.js.map +0 -1
  130. package/lib/decoder/strategy/RawChanges.js +0 -7
  131. package/lib/decoder/strategy/RawChanges.js.map +0 -1
  132. package/lib/decoder/strategy/getDecoderStateCallbacks.js +0 -277
  133. package/lib/decoder/strategy/getDecoderStateCallbacks.js.map +0 -1
  134. package/lib/encoder/ChangeTree.js +0 -542
  135. package/lib/encoder/ChangeTree.js.map +0 -1
  136. package/lib/encoder/EncodeOperation.js +0 -139
  137. package/lib/encoder/EncodeOperation.js.map +0 -1
  138. package/lib/encoder/Encoder.js +0 -208
  139. package/lib/encoder/Encoder.js.map +0 -1
  140. package/lib/encoder/Root.js +0 -233
  141. package/lib/encoder/Root.js.map +0 -1
  142. package/lib/encoder/StateView.js +0 -284
  143. package/lib/encoder/StateView.js.map +0 -1
  144. package/lib/encoding/assert.js +0 -55
  145. package/lib/encoding/assert.js.map +0 -1
  146. package/lib/encoding/decode.js +0 -221
  147. package/lib/encoding/decode.js.map +0 -1
  148. package/lib/encoding/encode.js +0 -282
  149. package/lib/encoding/encode.js.map +0 -1
  150. package/lib/encoding/spec.js +0 -29
  151. package/lib/encoding/spec.js.map +0 -1
  152. package/lib/index.d.ts +0 -32
  153. package/lib/index.js +0 -81
  154. package/lib/index.js.map +0 -1
  155. package/lib/symbol.shim.js +0 -4
  156. package/lib/symbol.shim.js.map +0 -1
  157. package/lib/types/HelperTypes.js +0 -3
  158. package/lib/types/HelperTypes.js.map +0 -1
  159. package/lib/types/TypeContext.js +0 -147
  160. package/lib/types/TypeContext.js.map +0 -1
  161. package/lib/types/custom/ArraySchema.js +0 -737
  162. package/lib/types/custom/ArraySchema.js.map +0 -1
  163. package/lib/types/custom/CollectionSchema.js +0 -174
  164. package/lib/types/custom/CollectionSchema.js.map +0 -1
  165. package/lib/types/custom/MapSchema.js +0 -226
  166. package/lib/types/custom/MapSchema.js.map +0 -1
  167. package/lib/types/custom/SetSchema.js +0 -182
  168. package/lib/types/custom/SetSchema.js.map +0 -1
  169. package/lib/types/registry.js +0 -37
  170. package/lib/types/registry.js.map +0 -1
  171. package/lib/types/symbols.js +0 -37
  172. package/lib/types/symbols.js.map +0 -1
  173. package/lib/types/utils.js +0 -16
  174. package/lib/types/utils.js.map +0 -1
  175. package/lib/utils.js +0 -54
  176. package/lib/utils.js.map +0 -1
  177. package/lib/v3_bench.js +0 -130
  178. package/lib/v3_bench.js.map +0 -1
  179. package/src/bench_encode.ts +0 -64
  180. /package/{lib → build}/codegen/api.d.ts +0 -0
  181. /package/{lib → build}/codegen/argv.d.ts +0 -0
  182. /package/{lib → build}/codegen/cli.d.ts +0 -0
  183. /package/{lib → build}/codegen/types.d.ts +0 -0
  184. /package/{lib → build}/encoding/spec.d.ts +0 -0
  185. /package/build/{umd/index.js → index.js} +0 -0
  186. /package/build/{esm/index.mjs → index.mjs} +0 -0
  187. /package/{lib → build}/symbol.shim.d.ts +0 -0
  188. /package/{lib → build}/types/symbols.d.ts +0 -0
  189. /package/{lib → build}/types/utils.d.ts +0 -0
  190. /package/{lib → build}/v3_bench.d.ts +0 -0
@@ -1,9 +1,9 @@
1
- import type { Definition, DefinitionType, PrimitiveType } from "../annotations";
2
- import type { Schema } from "../Schema";
3
- import type { ArraySchema } from "./custom/ArraySchema";
4
- import type { CollectionSchema } from "./custom/CollectionSchema";
5
- import type { MapSchema } from "./custom/MapSchema";
6
- import type { SetSchema } from "./custom/SetSchema";
1
+ import type { Definition, DefinitionType, PrimitiveType } from "../annotations.js";
2
+ import type { Schema } from "../Schema.js";
3
+ import type { ArraySchema } from "./custom/ArraySchema.js";
4
+ import type { CollectionSchema } from "./custom/CollectionSchema.js";
5
+ import type { MapSchema } from "./custom/MapSchema.js";
6
+ import type { SetSchema } from "./custom/SetSchema.js";
7
7
  export type Constructor<T = {}> = new (...args: any[]) => T;
8
8
  type PrimitiveStringToType<T> = T extends "string" ? string : T extends "number" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "int64" | "uint64" | "float32" | "float64" ? number : T extends "boolean" ? boolean : T;
9
9
  export interface Collection<K = any, V = any, IT = V> {
@@ -1,4 +1,4 @@
1
- import { Schema } from "../Schema";
1
+ import { Schema } from "../Schema.js";
2
2
  export declare class TypeContext {
3
3
  types: {
4
4
  [id: number]: typeof Schema;
@@ -1,9 +1,9 @@
1
- import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $onDecodeEnd, $refId } from "../symbols";
2
- import type { Schema } from "../../Schema";
3
- import { type IRef, ChangeTree } from "../../encoder/ChangeTree";
4
- import { OPERATION } from "../../encoding/spec";
5
- import { Collection } from "../HelperTypes";
6
- import type { StateView } from "../../encoder/StateView";
1
+ import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $onDecodeEnd, $refId } from "../symbols.js";
2
+ import type { Schema } from "../../Schema.js";
3
+ import { type IRef, ChangeTree } from "../../encoder/ChangeTree.js";
4
+ import { OPERATION } from "../../encoding/spec.js";
5
+ import { Collection } from "../HelperTypes.js";
6
+ import type { StateView } from "../../encoder/StateView.js";
7
7
  export declare class ArraySchema<V = any> implements Array<V>, Collection<number, V>, IRef {
8
8
  [n: number]: V;
9
9
  [$changes]: ChangeTree;
@@ -15,8 +15,8 @@ export declare class ArraySchema<V = any> implements Array<V>, Collection<number
15
15
  [index: number]: boolean;
16
16
  };
17
17
  protected isMovingItems: boolean;
18
- static [$encoder]: import("../../encoder/EncodeOperation").EncodeOperation<any>;
19
- static [$decoder]: import("../../decoder/DecodeOperation").DecodeOperation<any>;
18
+ static [$encoder]: import("../../encoder/EncodeOperation.js").EncodeOperation<any>;
19
+ static [$decoder]: import("../../decoder/DecodeOperation.js").DecodeOperation<any>;
20
20
  /**
21
21
  * Determine if a property must be filtered.
22
22
  * - If returns false, the property is NOT going to be encoded.
@@ -1,8 +1,8 @@
1
- import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd, $refId } from "../symbols";
2
- import { ChangeTree, type IRef } from "../../encoder/ChangeTree";
3
- import { Collection } from "../HelperTypes";
4
- import type { StateView } from "../../encoder/StateView";
5
- import type { Schema } from "../../Schema";
1
+ import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd, $refId } from "../symbols.js";
2
+ import { ChangeTree, type IRef } from "../../encoder/ChangeTree.js";
3
+ import { Collection } from "../HelperTypes.js";
4
+ import type { StateView } from "../../encoder/StateView.js";
5
+ import type { Schema } from "../../Schema.js";
6
6
  type K = number;
7
7
  export declare class CollectionSchema<V = any> implements Collection<K, V>, IRef {
8
8
  [$changes]: ChangeTree;
@@ -14,8 +14,8 @@ export declare class CollectionSchema<V = any> implements Collection<K, V>, IRef
14
14
  [field: string]: V;
15
15
  };
16
16
  protected $refId: number;
17
- static [$encoder]: import("../../encoder/EncodeOperation").EncodeOperation<any>;
18
- static [$decoder]: import("../../decoder/DecodeOperation").DecodeOperation<any>;
17
+ static [$encoder]: import("../../encoder/EncodeOperation.js").EncodeOperation<any>;
18
+ static [$decoder]: import("../../decoder/DecodeOperation.js").DecodeOperation<any>;
19
19
  /**
20
20
  * Determine if a property must be filtered.
21
21
  * - If returns false, the property is NOT going to be encoded.
@@ -1,8 +1,8 @@
1
- import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $refId } from "../symbols";
2
- import { ChangeTree, IRef } from "../../encoder/ChangeTree";
3
- import { Collection } from "../HelperTypes";
4
- import type { StateView } from "../../encoder/StateView";
5
- import type { Schema } from "../../Schema";
1
+ import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $refId } from "../symbols.js";
2
+ import { ChangeTree, IRef } from "../../encoder/ChangeTree.js";
3
+ import { Collection } from "../HelperTypes.js";
4
+ import type { StateView } from "../../encoder/StateView.js";
5
+ import type { Schema } from "../../Schema.js";
6
6
  export declare class MapSchema<V = any, K extends string = string> implements Map<K, V>, Collection<K, V, [K, V]>, IRef {
7
7
  [$changes]: ChangeTree;
8
8
  [$refId]?: number;
@@ -13,8 +13,8 @@ export declare class MapSchema<V = any, K extends string = string> implements Ma
13
13
  protected deletedItems: {
14
14
  [index: string]: V;
15
15
  };
16
- static [$encoder]: import("../../encoder/EncodeOperation").EncodeOperation<any>;
17
- static [$decoder]: import("../../decoder/DecodeOperation").DecodeOperation<any>;
16
+ static [$encoder]: import("../../encoder/EncodeOperation.js").EncodeOperation<any>;
17
+ static [$decoder]: import("../../decoder/DecodeOperation.js").DecodeOperation<any>;
18
18
  /**
19
19
  * Determine if a property must be filtered.
20
20
  * - If returns false, the property is NOT going to be encoded.
@@ -1,8 +1,8 @@
1
- import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd, $refId } from "../symbols";
2
- import { Collection } from "../HelperTypes";
3
- import { ChangeTree, type IRef } from "../../encoder/ChangeTree";
4
- import type { StateView } from "../../encoder/StateView";
5
- import type { Schema } from "../../Schema";
1
+ import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd, $refId } from "../symbols.js";
2
+ import { Collection } from "../HelperTypes.js";
3
+ import { ChangeTree, type IRef } from "../../encoder/ChangeTree.js";
4
+ import type { StateView } from "../../encoder/StateView.js";
5
+ import type { Schema } from "../../Schema.js";
6
6
  export declare class SetSchema<V = any> implements Collection<number, V>, IRef {
7
7
  [$changes]: ChangeTree;
8
8
  [$refId]?: number;
@@ -13,8 +13,8 @@ export declare class SetSchema<V = any> implements Collection<number, V>, IRef {
13
13
  [field: string]: V;
14
14
  };
15
15
  protected $refId: number;
16
- static [$encoder]: import("../../encoder/EncodeOperation").EncodeOperation<any>;
17
- static [$decoder]: import("../../decoder/DecodeOperation").DecodeOperation<any>;
16
+ static [$encoder]: import("../../encoder/EncodeOperation.js").EncodeOperation<any>;
17
+ static [$decoder]: import("../../decoder/DecodeOperation.js").DecodeOperation<any>;
18
18
  /**
19
19
  * Determine if a property must be filtered.
20
20
  * - If returns false, the property is NOT going to be encoded.
@@ -1,5 +1,5 @@
1
- import { BufferLike } from "../encoding/encode";
2
- import { Iterator } from "../encoding/decode";
1
+ import { BufferLike } from "../encoding/encode.js";
2
+ import { Iterator } from "../encoding/decode.js";
3
3
  export interface TypeDefinition {
4
4
  constructor?: any;
5
5
  encode?: (bytes: BufferLike, value: any, it: Iterator) => any;
@@ -1,4 +1,4 @@
1
- import type { Schema } from "./Schema";
1
+ import type { Schema } from "./Schema.js";
2
2
  interface ChangeDump {
3
3
  ops: {
4
4
  ADD?: number;
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@colyseus/schema",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "Binary state serializer with delta encoding for games",
5
+ "type": "module",
5
6
  "bin": {
6
7
  "schema-codegen": "bin/schema-codegen",
7
8
  "schema-debug": "bin/schema-debug"
@@ -27,20 +28,19 @@
27
28
  },
28
29
  "files": [
29
30
  "src",
30
- "lib",
31
31
  "build",
32
32
  "bin"
33
33
  ],
34
- "types": "lib/index.d.ts",
35
- "main": "build/cjs/index.js",
36
- "module": "build/esm/index.mjs",
37
- "browser": "./build/umd/index.js",
34
+ "types": "./build/index.d.ts",
35
+ "main": "./build/index.cjs",
36
+ "module": "./build/index.mjs",
37
+ "browser": "./build/index.js",
38
38
  "exports": {
39
39
  ".": {
40
- "browser": "./build/umd/index.js",
41
- "import": "./build/esm/index.mjs",
42
- "require": "./build/cjs/index.js",
43
- "types": "./lib/index.d.ts"
40
+ "browser": "./build/index.mjs",
41
+ "import": "./build/index.mjs",
42
+ "require": "./build/index.cjs",
43
+ "types": "./build/index.d.ts"
44
44
  }
45
45
  },
46
46
  "repository": {
@@ -60,21 +60,19 @@
60
60
  "@msgpack/msgpack": "^1.9.1",
61
61
  "@rollup/plugin-typescript": "^11.1.6",
62
62
  "@types/benchmark": "^2.1.0",
63
- "@types/glob": "^7.1.1",
64
63
  "@types/mocha": "^5.2.5",
65
64
  "@types/node": "^14.0.13",
66
- "@types/rimraf": "^2.0.3",
67
65
  "@types/sinon": "^7.0.3",
68
66
  "benchmark": "^2.1.4",
69
67
  "c8": "^10.1.2",
70
68
  "core-js": "^3.44.0",
71
69
  "flatbuffers": "^1.10.2",
72
70
  "fossil-delta": "^1.0.2",
73
- "glob": "^7.1.5",
71
+ "glob": "^13.0.0",
74
72
  "mocha": "^10.2.0",
75
73
  "msgpackr": "^1.6.1",
76
74
  "nanoid": "^5.1.6",
77
- "rimraf": "^3.0.0",
75
+ "rimraf": "^6.1.2",
78
76
  "rollup": "^4.18.0",
79
77
  "sinon": "^7.2.2",
80
78
  "source-map-support": "^0.5.13",
@@ -82,6 +80,9 @@
82
80
  "tsx": "^4.21.0",
83
81
  "typescript": "^5.9.3"
84
82
  },
83
+ "peerDependencies": {
84
+ "typescript": "^5.9.3"
85
+ },
85
86
  "c8": {
86
87
  "include": [
87
88
  "src/**/*.ts"
package/src/Metadata.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { DefinitionType, getPropertyDescriptor } from "./annotations";
2
- import { Schema } from "./Schema";
3
- import { getType, registeredTypes } from "./types/registry";
4
- import { $decoder, $descriptors, $encoder, $fieldIndexesByViewTag, $numFields, $refTypeFieldIndexes, $track, $viewFieldIndexes } from "./types/symbols";
5
- import { TypeContext } from "./types/TypeContext";
1
+ import { DefinitionType, getPropertyDescriptor } from "./annotations.js";
2
+ import { Schema } from "./Schema.js";
3
+ import { getType, registeredTypes } from "./types/registry.js";
4
+ import { $decoder, $descriptors, $encoder, $fieldIndexesByViewTag, $numFields, $refTypeFieldIndexes, $track, $viewFieldIndexes } from "./types/symbols.js";
5
+ import { TypeContext } from "./types/TypeContext.js";
6
6
 
7
7
  export type MetadataField = {
8
8
  type: DefinitionType,
package/src/Reflection.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { PrimitiveType, schema, SchemaType } from "./annotations";
2
- import { TypeContext } from "./types/TypeContext";
3
- import { Metadata } from "./Metadata";
4
- import { Iterator } from "./encoding/decode";
5
- import { Encoder } from "./encoder/Encoder";
6
- import { Decoder } from "./decoder/Decoder";
7
- import { Schema } from "./Schema";
1
+ import { PrimitiveType, schema, SchemaType } from "./annotations.js";
2
+ import { TypeContext } from "./types/TypeContext.js";
3
+ import { Metadata } from "./Metadata.js";
4
+ import { Iterator } from "./encoding/decode.js";
5
+ import { Encoder } from "./encoder/Encoder.js";
6
+ import { Decoder } from "./decoder/Decoder.js";
7
+ import { Schema } from "./Schema.js";
8
8
 
9
9
  /**
10
10
  * Static methods available on Reflection
package/src/Schema.ts CHANGED
@@ -1,18 +1,18 @@
1
- import { OPERATION } from './encoding/spec';
2
- import { DEFAULT_VIEW_TAG, type DefinitionType } from "./annotations";
1
+ import { OPERATION } from './encoding/spec.js';
2
+ import { DEFAULT_VIEW_TAG, type DefinitionType } from "./annotations.js";
3
3
 
4
- import { AssignableProps, NonFunctionPropNames, ToJSON } from './types/HelperTypes';
4
+ import { AssignableProps, NonFunctionPropNames, ToJSON } from './types/HelperTypes.js';
5
5
 
6
- import { ChangeSet, ChangeSetName, ChangeTree, IRef, Ref } from './encoder/ChangeTree';
7
- import { $changes, $decoder, $deleteByIndex, $descriptors, $encoder, $filter, $getByIndex, $refId, $track } from './types/symbols';
8
- import { StateView } from './encoder/StateView';
6
+ import { ChangeSet, ChangeSetName, ChangeTree, IRef, Ref } from './encoder/ChangeTree.js';
7
+ import { $changes, $decoder, $deleteByIndex, $descriptors, $encoder, $filter, $getByIndex, $refId, $track } from './types/symbols.js';
8
+ import { StateView } from './encoder/StateView.js';
9
9
 
10
- import { encodeSchemaOperation } from './encoder/EncodeOperation';
11
- import { decodeSchemaOperation } from './decoder/DecodeOperation';
10
+ import { encodeSchemaOperation } from './encoder/EncodeOperation.js';
11
+ import { decodeSchemaOperation } from './decoder/DecodeOperation.js';
12
12
 
13
- import type { Decoder } from './decoder/Decoder';
14
- import type { Metadata, MetadataField } from './Metadata';
15
- import { getIndent } from './utils';
13
+ import type { Decoder } from './decoder/Decoder.js';
14
+ import type { Metadata, MetadataField } from './Metadata.js';
15
+ import { getIndent } from './utils.js';
16
16
 
17
17
  /**
18
18
  * Schema encoder / decoder
@@ -1,16 +1,16 @@
1
- import "./symbol.shim";
2
- import { Schema } from './Schema';
3
- import { ArraySchema } from './types/custom/ArraySchema';
4
- import { MapSchema } from './types/custom/MapSchema';
5
- import { getNormalizedType, Metadata } from "./Metadata";
6
- import { $changes, $childType, $descriptors, $numFields, $track } from "./types/symbols";
7
- import { TypeDefinition, getType } from "./types/registry";
8
- import { OPERATION } from "./encoding/spec";
9
- import { TypeContext } from "./types/TypeContext";
10
- import { assertInstanceType, assertType } from "./encoding/assert";
11
- import type { InferValueType, InferSchemaInstanceType, AssignableProps, IsNever } from "./types/HelperTypes";
12
- import { CollectionSchema } from "./types/custom/CollectionSchema";
13
- import { SetSchema } from "./types/custom/SetSchema";
1
+ import "./symbol.shim.js";
2
+ import { Schema } from './Schema.js';
3
+ import { ArraySchema } from './types/custom/ArraySchema.js';
4
+ import { MapSchema } from './types/custom/MapSchema.js';
5
+ import { getNormalizedType, Metadata } from "./Metadata.js";
6
+ import { $changes, $childType, $descriptors, $numFields, $track } from "./types/symbols.js";
7
+ import { TypeDefinition, getType } from "./types/registry.js";
8
+ import { OPERATION } from "./encoding/spec.js";
9
+ import { TypeContext } from "./types/TypeContext.js";
10
+ import { assertInstanceType, assertType } from "./encoding/assert.js";
11
+ import type { InferValueType, InferSchemaInstanceType, AssignableProps, IsNever } from "./types/HelperTypes.js";
12
+ import { CollectionSchema } from "./types/custom/CollectionSchema.js";
13
+ import { SetSchema } from "./types/custom/SetSchema.js";
14
14
 
15
15
  export type RawPrimitiveType = "string" |
16
16
  "number" |
@@ -1,8 +1,15 @@
1
1
  import * as fs from "fs";
2
2
  import * as path from "path";
3
+ import { createRequire } from "module";
4
+ // import { fileURLToPath } from "url";
3
5
 
4
- import { File } from "./types";
5
- import { parseFiles } from "./parser";
6
+ import { File } from "./types.js";
7
+ import { parseFiles } from "./parser.js";
8
+
9
+ // Create require relative to this file's location (for ESM compatibility)
10
+ // const __filename = fileURLToPath(import.meta.url);
11
+ // const __dirname = path.dirname(__filename);
12
+ const require = createRequire(import.meta.url);
6
13
 
7
14
  export interface GenerateOptions {
8
15
  files: string[],
@@ -15,7 +22,7 @@ export function generate(targetId: string, options: GenerateOptions) {
15
22
  let generator: Function;
16
23
 
17
24
  try {
18
- generator = require('./languages/' + targetId).generate;
25
+ generator = require('./languages/' + targetId + '.js').generate;
19
26
 
20
27
  } catch (e) {
21
28
  throw new Error("You must provide a valid generator as argument, such as: --csharp, --haxe or --cpp");
@@ -1,5 +1,5 @@
1
- import argv from "./argv";
2
- import { generate } from "./api";
1
+ import argv from "./argv.js";
2
+ import { generate } from "./api.js";
3
3
 
4
4
  const supportedTargets: Record<string, string> = {
5
5
  csharp: 'generate for C#/Unity',
@@ -1,5 +1,5 @@
1
- import { Class, Property, File, getCommentHeader, getInheritanceTree, Context } from "../types";
2
- import { GenerateOptions } from "../api";
1
+ import { Class, Property, File, getCommentHeader, getInheritanceTree, Context } from "../types.js";
2
+ import { GenerateOptions } from "../api.js";
3
3
 
4
4
  const typeMaps: { [key: string]: string } = {
5
5
  "string": "string",
@@ -5,9 +5,9 @@ import {
5
5
  getCommentHeader,
6
6
  Interface,
7
7
  Enum,
8
- } from "../types";
9
- import { GenerateOptions } from "../api";
10
- import { Context } from "../types";
8
+ } from "../types.js";
9
+ import { GenerateOptions } from "../api.js";
10
+ import { Context } from "../types.js";
11
11
 
12
12
  const typeMaps: { [key: string]: string } = {
13
13
  "string": "string",
@@ -1,5 +1,5 @@
1
- import { Class, Property, File, getCommentHeader, Context } from "../types";
2
- import { GenerateOptions } from "../api";
1
+ import { Class, Property, File, getCommentHeader, Context } from "../types.js";
2
+ import { GenerateOptions } from "../api.js";
3
3
 
4
4
  const typeMaps: { [key: string]: string } = {
5
5
  "string": "String",
@@ -1,5 +1,5 @@
1
- import { Class, Property, File, getCommentHeader, Context } from "../types";
2
- import { GenerateOptions } from "../api";
1
+ import { Class, Property, File, getCommentHeader, Context } from "../types.js";
2
+ import { GenerateOptions } from "../api.js";
3
3
 
4
4
  const typeMaps: { [key: string]: string } = {
5
5
  "string": "String",
@@ -1,5 +1,5 @@
1
- import { Class, Property, File, getCommentHeader, getInheritanceTree, Context } from "../types";
2
- import { GenerateOptions } from "../api";
1
+ import { Class, Property, File, getCommentHeader, getInheritanceTree, Context } from "../types.js";
2
+ import { GenerateOptions } from "../api.js";
3
3
 
4
4
  const typeMaps: { [key: string]: string } = {
5
5
  "string": "string",
@@ -1,5 +1,5 @@
1
- import { Class, Property, File, getCommentHeader, getInheritanceTree, Context } from "../types";
2
- import { GenerateOptions } from "../api";
1
+ import { Class, Property, File, getCommentHeader, getInheritanceTree, Context } from "../types.js";
2
+ import { GenerateOptions } from "../api.js";
3
3
 
4
4
  /**
5
5
  TODO:
@@ -1,5 +1,5 @@
1
- import { Class, Property, File, getCommentHeader, getInheritanceTree, Context, Interface } from "../types";
2
- import { GenerateOptions } from "../api";
1
+ import { Class, Property, File, getCommentHeader, getInheritanceTree, Context, Interface } from "../types.js";
2
+ import { GenerateOptions } from "../api.js";
3
3
 
4
4
  const typeMaps: { [key: string]: string } = {
5
5
  "string": "string",
@@ -1,7 +1,7 @@
1
1
  import * as ts from "typescript";
2
2
  import * as path from "path";
3
- import {readFileSync} from "fs";
4
- import {IStructure, Class, Interface, Property, Context, Enum} from "./types";
3
+ import { readFileSync } from "fs";
4
+ import { IStructure, Class, Interface, Property, Context, Enum } from "./types.js";
5
5
 
6
6
  let currentStructure: IStructure;
7
7
  let currentProperty: Property;
@@ -358,6 +358,11 @@ export function parseFiles(
358
358
  fileNameAlternatives.push(`${fileName}.ts`);
359
359
  fileNameAlternatives.push(`${fileName}/index.ts`);
360
360
 
361
+ } else if (fileName.endsWith(".js")) {
362
+ // Handle .js extensions by also trying .ts (ESM imports often use .js extension)
363
+ fileNameAlternatives.push(fileName);
364
+ fileNameAlternatives.push(fileName.replace(/\.js$/, ".ts"));
365
+
361
366
  } else {
362
367
  fileNameAlternatives.push(fileName);
363
368
  }
@@ -1,4 +1,9 @@
1
1
  import * as fs from "fs";
2
+ import * as path from "path";
3
+
4
+ if (typeof(__dirname) === "undefined") {
5
+ global.__dirname = path.dirname(new URL(import.meta.url).pathname);
6
+ }
2
7
 
3
8
  const VERSION = JSON.parse(fs.readFileSync(__dirname + "/../../package.json").toString()).version;
4
9
  const COMMENT_HEADER = `
@@ -1,17 +1,17 @@
1
- import { OPERATION } from "../encoding/spec";
2
- import { Metadata } from "../Metadata";
3
- import { Schema } from "../Schema";
4
- import type { Ref } from "../encoder/ChangeTree";
5
- import type { Decoder } from "./Decoder";
6
- import { Iterator, decode } from "../encoding/decode";
7
- import { $childType, $deleteByIndex, $getByIndex, $refId } from "../types/symbols";
8
-
9
- import type { MapSchema } from "../types/custom/MapSchema";
10
- import type { ArraySchema } from "../types/custom/ArraySchema";
11
- import type { CollectionSchema } from "../types/custom/CollectionSchema";
12
-
13
- import { getType } from "../types/registry";
14
- import { Collection } from "../types/HelperTypes";
1
+ import { OPERATION } from "../encoding/spec.js";
2
+ import { Metadata } from "../Metadata.js";
3
+ import { Schema } from "../Schema.js";
4
+ import type { Ref } from "../encoder/ChangeTree.js";
5
+ import type { Decoder } from "./Decoder.js";
6
+ import { Iterator, decode } from "../encoding/decode.js";
7
+ import { $childType, $deleteByIndex, $getByIndex, $refId } from "../types/symbols.js";
8
+
9
+ import type { MapSchema } from "../types/custom/MapSchema.js";
10
+ import type { ArraySchema } from "../types/custom/ArraySchema.js";
11
+ import type { CollectionSchema } from "../types/custom/CollectionSchema.js";
12
+
13
+ import { getType } from "../types/registry.js";
14
+ import { Collection } from "../types/HelperTypes.js";
15
15
 
16
16
  export interface DataChange<T = any, F = string> {
17
17
  ref: Ref,
@@ -1,14 +1,14 @@
1
- import { TypeContext } from "../types/TypeContext";
2
- import { $changes, $childType, $decoder, $onDecodeEnd, $refId } from "../types/symbols";
3
- import { Schema } from "../Schema";
4
-
5
- import { decode } from "../encoding/decode";
6
- import { OPERATION, SWITCH_TO_STRUCTURE, TYPE_ID } from '../encoding/spec';
7
- import type { Ref } from "../encoder/ChangeTree";
8
- import type { Iterator } from "../encoding/decode";
9
- import { ReferenceTracker } from "./ReferenceTracker";
10
- import { DEFINITION_MISMATCH, type DataChange, type DecodeOperation } from "./DecodeOperation";
11
- import { Collection } from "../types/HelperTypes";
1
+ import { TypeContext } from "../types/TypeContext.js";
2
+ import { $changes, $childType, $decoder, $onDecodeEnd, $refId } from "../types/symbols.js";
3
+ import { Schema } from "../Schema.js";
4
+
5
+ import { decode } from "../encoding/decode.js";
6
+ import { OPERATION, SWITCH_TO_STRUCTURE, TYPE_ID } from '../encoding/spec.js';
7
+ import type { Ref } from "../encoder/ChangeTree.js";
8
+ import type { Iterator } from "../encoding/decode.js";
9
+ import { ReferenceTracker } from "./ReferenceTracker.js";
10
+ import { DEFINITION_MISMATCH, type DataChange, type DecodeOperation } from "./DecodeOperation.js";
11
+ import { Collection } from "../types/HelperTypes.js";
12
12
 
13
13
  export class Decoder<T extends Schema = any> {
14
14
  context: TypeContext;
@@ -1,11 +1,11 @@
1
- import { Metadata } from "../Metadata";
2
- import { $childType, $refId } from "../types/symbols";
3
- import { Ref } from "../encoder/ChangeTree";
4
- import { spliceOne } from "../types/utils";
5
- import { OPERATION } from "../encoding/spec";
6
-
7
- import type { MapSchema } from "../types/custom/MapSchema";
8
- import type { Schema } from "../Schema";
1
+ import { Metadata } from "../Metadata.js";
2
+ import { $childType, $refId } from "../types/symbols.js";
3
+ import { Ref } from "../encoder/ChangeTree.js";
4
+ import { spliceOne } from "../types/utils.js";
5
+ import { OPERATION } from "../encoding/spec.js";
6
+
7
+ import type { MapSchema } from "../types/custom/MapSchema.js";
8
+ import type { Schema } from "../Schema.js";
9
9
 
10
10
  class DecodingWarning extends Error {
11
11
  constructor(message: string) {
@@ -1,15 +1,15 @@
1
- import { Metadata } from "../../Metadata";
2
- import { Collection, NonFunctionPropNames } from "../../types/HelperTypes";
3
- import { Ref } from "../../encoder/ChangeTree";
4
- import { Decoder } from "../Decoder";
5
- import { DataChange } from "../DecodeOperation";
6
- import { OPERATION } from "../../encoding/spec";
7
- import { Schema } from "../../Schema";
8
- import { $refId } from "../../types/symbols";
9
- import { MapSchema } from "../../types/custom/MapSchema";
10
- import { ArraySchema } from "../../types/custom/ArraySchema";
11
- import { getDecoderStateCallbacks, type SchemaCallbackProxy } from "./getDecoderStateCallbacks";
12
- import { getRawChangesCallback } from "./RawChanges";
1
+ import { Metadata } from "../../Metadata.js";
2
+ import { Collection, NonFunctionPropNames } from "../../types/HelperTypes.js";
3
+ import { Ref } from "../../encoder/ChangeTree.js";
4
+ import { Decoder } from "../Decoder.js";
5
+ import { DataChange } from "../DecodeOperation.js";
6
+ import { OPERATION } from "../../encoding/spec.js";
7
+ import { Schema } from "../../Schema.js";
8
+ import { $refId } from "../../types/symbols.js";
9
+ import { MapSchema } from "../../types/custom/MapSchema.js";
10
+ import { ArraySchema } from "../../types/custom/ArraySchema.js";
11
+ import { getDecoderStateCallbacks, type SchemaCallbackProxy } from "./getDecoderStateCallbacks.js";
12
+ import { getRawChangesCallback } from "./RawChanges.js";
13
13
 
14
14
  //
15
15
  // C#-style Callbacks API
@@ -1,5 +1,5 @@
1
- import { DataChange } from "../DecodeOperation";
2
- import { Decoder } from "../Decoder";
1
+ import { DataChange } from "../DecodeOperation.js";
2
+ import { Decoder } from "../Decoder.js";
3
3
 
4
4
  export function getRawChangesCallback(
5
5
  decoder: Decoder,
@@ -1,13 +1,13 @@
1
- import { Metadata } from "../../Metadata";
2
- import { Collection, NonFunctionNonPrimitivePropNames, NonFunctionPropNames } from "../../types/HelperTypes";
3
- import { IRef, Ref } from "../../encoder/ChangeTree";
4
- import { Decoder } from "../Decoder";
5
- import { DataChange } from "../DecodeOperation";
6
- import { OPERATION } from "../../encoding/spec";
7
- import { Schema } from "../../Schema";
8
- import { $refId } from "../../types/symbols";
9
- import type { DefinitionType } from "../../annotations";
10
- import type { CollectionSchema } from "../../types/custom/CollectionSchema";
1
+ import { Metadata } from "../../Metadata.js";
2
+ import { Collection, NonFunctionNonPrimitivePropNames, NonFunctionPropNames } from "../../types/HelperTypes.js";
3
+ import { IRef, Ref } from "../../encoder/ChangeTree.js";
4
+ import { Decoder } from "../Decoder.js";
5
+ import { DataChange } from "../DecodeOperation.js";
6
+ import { OPERATION } from "../../encoding/spec.js";
7
+ import { Schema } from "../../Schema.js";
8
+ import { $refId } from "../../types/symbols.js";
9
+ import type { DefinitionType } from "../../annotations.js";
10
+ import type { CollectionSchema } from "../../types/custom/CollectionSchema.js";
11
11
 
12
12
  //
13
13
  // Discussion: https://github.com/colyseus/schema/issues/155