@colyseus/schema 4.0.2 → 4.0.4
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/{lib → build}/Metadata.d.ts +2 -2
- package/{lib → build}/Reflection.d.ts +13 -13
- package/{lib → build}/Schema.d.ts +10 -10
- package/{lib/src → build}/annotations.d.ts +10 -10
- package/build/codegen/languages/cpp.d.ts +3 -0
- package/build/codegen/languages/csharp.d.ts +4 -0
- package/build/codegen/languages/haxe.d.ts +3 -0
- package/{lib → build}/codegen/languages/java.d.ts +2 -2
- package/build/codegen/languages/js.d.ts +3 -0
- package/build/codegen/languages/lua.d.ts +3 -0
- package/build/codegen/languages/ts.d.ts +3 -0
- package/{lib → build}/codegen/parser.d.ts +1 -1
- package/{lib → build}/decoder/DecodeOperation.d.ts +5 -5
- package/{lib/src → build}/decoder/Decoder.d.ts +7 -7
- package/{lib → build}/decoder/ReferenceTracker.d.ts +1 -1
- package/{lib → build}/decoder/strategy/Callbacks.d.ts +18 -43
- package/{lib → build}/decoder/strategy/RawChanges.d.ts +2 -2
- package/{lib → build}/decoder/strategy/getDecoderStateCallbacks.d.ts +3 -3
- package/{lib → build}/encoder/ChangeTree.d.ts +11 -11
- package/{lib → build}/encoder/EncodeOperation.d.ts +5 -5
- package/{lib → build}/encoder/Encoder.d.ts +6 -6
- package/{lib/src → build}/encoder/Root.d.ts +2 -2
- package/{lib/src → build}/encoder/StateView.d.ts +1 -1
- package/{lib/src → build}/encoding/assert.d.ts +6 -6
- package/{lib/src → build}/encoding/decode.d.ts +1 -1
- package/{lib/src → build}/encoding/encode.d.ts +1 -1
- package/build/{cjs/index.cjs → index.cjs} +8 -34
- package/build/index.cjs.map +1 -0
- package/build/index.d.ts +32 -0
- package/build/{umd/index.js → index.js} +8 -34
- package/build/{esm/index.mjs → index.mjs} +8 -34
- package/build/index.mjs.map +1 -0
- package/{lib → build}/types/HelperTypes.d.ts +6 -6
- package/{lib → build}/types/TypeContext.d.ts +1 -1
- package/{lib/src → build}/types/custom/ArraySchema.d.ts +8 -8
- package/{lib/src → build}/types/custom/CollectionSchema.d.ts +7 -7
- package/{lib → build}/types/custom/MapSchema.d.ts +7 -7
- package/{lib/src → build}/types/custom/SetSchema.d.ts +7 -7
- package/{lib/src → build}/types/registry.d.ts +2 -2
- package/{lib → build}/utils.d.ts +1 -1
- package/package.json +9 -10
- package/src/Metadata.ts +5 -5
- package/src/Reflection.ts +7 -7
- package/src/Schema.ts +11 -11
- package/src/annotations.ts +13 -13
- package/src/codegen/api.ts +3 -3
- package/src/codegen/cli.ts +2 -2
- package/src/codegen/languages/cpp.ts +2 -2
- package/src/codegen/languages/csharp.ts +3 -3
- package/src/codegen/languages/haxe.ts +2 -2
- package/src/codegen/languages/java.ts +2 -2
- package/src/codegen/languages/js.ts +2 -2
- package/src/codegen/languages/lua.ts +2 -2
- package/src/codegen/languages/ts.ts +2 -2
- package/src/codegen/parser.ts +6 -1
- package/src/decoder/DecodeOperation.ts +14 -14
- package/src/decoder/Decoder.ts +11 -11
- package/src/decoder/ReferenceTracker.ts +8 -8
- package/src/decoder/strategy/Callbacks.ts +27 -53
- package/src/decoder/strategy/RawChanges.ts +2 -2
- package/src/decoder/strategy/getDecoderStateCallbacks.ts +10 -10
- package/src/encoder/ChangeTree.ts +13 -13
- package/src/encoder/EncodeOperation.ts +9 -9
- package/src/encoder/Encoder.ts +10 -10
- package/src/encoder/Root.ts +4 -4
- package/src/encoder/StateView.ts +7 -7
- package/src/encoding/assert.ts +6 -6
- package/src/encoding/decode.ts +1 -1
- package/src/encoding/encode.ts +1 -1
- package/src/index.ts +27 -27
- package/src/types/HelperTypes.ts +6 -6
- package/src/types/TypeContext.ts +3 -3
- package/src/types/custom/ArraySchema.ts +11 -11
- package/src/types/custom/CollectionSchema.ts +9 -9
- package/src/types/custom/MapSchema.ts +10 -10
- package/src/types/custom/SetSchema.ts +9 -9
- package/src/types/registry.ts +3 -3
- package/src/utils.ts +3 -3
- package/src/v3_bench.ts +1 -1
- package/build/cjs/index.cjs.map +0 -1
- package/build/esm/index.mjs.map +0 -1
- package/lib/Metadata.js +0 -256
- package/lib/Metadata.js.map +0 -1
- package/lib/Reflection.js +0 -179
- package/lib/Reflection.js.map +0 -1
- package/lib/Schema.js +0 -352
- package/lib/Schema.js.map +0 -1
- package/lib/annotations.d.ts +0 -109
- package/lib/annotations.js +0 -473
- package/lib/annotations.js.map +0 -1
- package/lib/bench_encode.d.ts +0 -1
- package/lib/bench_encode.js +0 -91
- package/lib/bench_encode.js.map +0 -1
- package/lib/benchmark.d.ts +0 -1
- package/lib/benchmark.js +0 -218
- package/lib/benchmark.js.map +0 -1
- package/lib/codegen/api.js +0 -56
- package/lib/codegen/api.js.map +0 -1
- package/lib/codegen/argv.js +0 -39
- package/lib/codegen/argv.js.map +0 -1
- package/lib/codegen/cli.js +0 -58
- package/lib/codegen/cli.js.map +0 -1
- package/lib/codegen/languages/cpp.d.ts +0 -3
- package/lib/codegen/languages/cpp.js +0 -258
- package/lib/codegen/languages/cpp.js.map +0 -1
- package/lib/codegen/languages/csharp.d.ts +0 -4
- package/lib/codegen/languages/csharp.js +0 -154
- package/lib/codegen/languages/csharp.js.map +0 -1
- package/lib/codegen/languages/haxe.d.ts +0 -3
- package/lib/codegen/languages/haxe.js +0 -100
- package/lib/codegen/languages/haxe.js.map +0 -1
- package/lib/codegen/languages/java.js +0 -100
- package/lib/codegen/languages/java.js.map +0 -1
- package/lib/codegen/languages/js.d.ts +0 -3
- package/lib/codegen/languages/js.js +0 -101
- package/lib/codegen/languages/js.js.map +0 -1
- package/lib/codegen/languages/lua.d.ts +0 -3
- package/lib/codegen/languages/lua.js +0 -103
- package/lib/codegen/languages/lua.js.map +0 -1
- package/lib/codegen/languages/ts.d.ts +0 -3
- package/lib/codegen/languages/ts.js +0 -116
- package/lib/codegen/languages/ts.js.map +0 -1
- package/lib/codegen/parser.js +0 -327
- package/lib/codegen/parser.js.map +0 -1
- package/lib/codegen/types.js +0 -142
- package/lib/codegen/types.js.map +0 -1
- package/lib/decoder/DecodeOperation.js +0 -248
- package/lib/decoder/DecodeOperation.js.map +0 -1
- package/lib/decoder/Decoder.d.ts +0 -21
- package/lib/decoder/Decoder.js +0 -114
- package/lib/decoder/Decoder.js.map +0 -1
- package/lib/decoder/ReferenceTracker.js +0 -135
- package/lib/decoder/ReferenceTracker.js.map +0 -1
- package/lib/decoder/strategy/Callbacks.js +0 -336
- package/lib/decoder/strategy/Callbacks.js.map +0 -1
- package/lib/decoder/strategy/RawChanges.js +0 -4
- package/lib/decoder/strategy/RawChanges.js.map +0 -1
- package/lib/decoder/strategy/getDecoderStateCallbacks.js +0 -274
- package/lib/decoder/strategy/getDecoderStateCallbacks.js.map +0 -1
- package/lib/encoder/ChangeTree.js +0 -534
- package/lib/encoder/ChangeTree.js.map +0 -1
- package/lib/encoder/EncodeOperation.js +0 -132
- package/lib/encoder/EncodeOperation.js.map +0 -1
- package/lib/encoder/Encoder.js +0 -204
- package/lib/encoder/Encoder.js.map +0 -1
- package/lib/encoder/Root.d.ts +0 -28
- package/lib/encoder/Root.js +0 -229
- package/lib/encoder/Root.js.map +0 -1
- package/lib/encoder/StateView.d.ts +0 -34
- package/lib/encoder/StateView.js +0 -279
- package/lib/encoder/StateView.js.map +0 -1
- package/lib/encoding/assert.d.ts +0 -10
- package/lib/encoding/assert.js +0 -49
- package/lib/encoding/assert.js.map +0 -1
- package/lib/encoding/decode.d.ts +0 -67
- package/lib/encoding/decode.js +0 -217
- package/lib/encoding/decode.js.map +0 -1
- package/lib/encoding/encode.d.ts +0 -40
- package/lib/encoding/encode.js +0 -279
- package/lib/encoding/encode.js.map +0 -1
- package/lib/encoding/spec.js +0 -26
- package/lib/encoding/spec.js.map +0 -1
- package/lib/index.d.ts +0 -32
- package/lib/index.js +0 -39
- package/lib/index.js.map +0 -1
- package/lib/src/Metadata.d.ts +0 -49
- package/lib/src/Metadata.js +0 -256
- package/lib/src/Metadata.js.map +0 -1
- package/lib/src/Reflection.d.ts +0 -71
- package/lib/src/Reflection.js +0 -179
- package/lib/src/Reflection.js.map +0 -1
- package/lib/src/Schema.d.ts +0 -86
- package/lib/src/Schema.js +0 -352
- package/lib/src/Schema.js.map +0 -1
- package/lib/src/annotations.js +0 -473
- package/lib/src/annotations.js.map +0 -1
- package/lib/src/bench_encode.d.ts +0 -1
- package/lib/src/bench_encode.js +0 -91
- package/lib/src/bench_encode.js.map +0 -1
- package/lib/src/codegen/api.d.ts +0 -7
- package/lib/src/codegen/api.js +0 -56
- package/lib/src/codegen/api.js.map +0 -1
- package/lib/src/codegen/argv.d.ts +0 -6
- package/lib/src/codegen/argv.js +0 -39
- package/lib/src/codegen/argv.js.map +0 -1
- package/lib/src/codegen/cli.d.ts +0 -1
- package/lib/src/codegen/cli.js +0 -58
- package/lib/src/codegen/cli.js.map +0 -1
- package/lib/src/codegen/languages/cpp.d.ts +0 -3
- package/lib/src/codegen/languages/cpp.js +0 -258
- package/lib/src/codegen/languages/cpp.js.map +0 -1
- package/lib/src/codegen/languages/csharp.d.ts +0 -4
- package/lib/src/codegen/languages/csharp.js +0 -154
- package/lib/src/codegen/languages/csharp.js.map +0 -1
- package/lib/src/codegen/languages/haxe.d.ts +0 -3
- package/lib/src/codegen/languages/haxe.js +0 -100
- package/lib/src/codegen/languages/haxe.js.map +0 -1
- package/lib/src/codegen/languages/java.d.ts +0 -6
- package/lib/src/codegen/languages/java.js +0 -100
- package/lib/src/codegen/languages/java.js.map +0 -1
- package/lib/src/codegen/languages/js.d.ts +0 -3
- package/lib/src/codegen/languages/js.js +0 -101
- package/lib/src/codegen/languages/js.js.map +0 -1
- package/lib/src/codegen/languages/lua.d.ts +0 -3
- package/lib/src/codegen/languages/lua.js +0 -103
- package/lib/src/codegen/languages/lua.js.map +0 -1
- package/lib/src/codegen/languages/ts.d.ts +0 -3
- package/lib/src/codegen/languages/ts.js +0 -116
- package/lib/src/codegen/languages/ts.js.map +0 -1
- package/lib/src/codegen/parser.d.ts +0 -13
- package/lib/src/codegen/parser.js +0 -327
- package/lib/src/codegen/parser.js.map +0 -1
- package/lib/src/codegen/types.d.ts +0 -52
- package/lib/src/codegen/types.js +0 -142
- package/lib/src/codegen/types.js.map +0 -1
- package/lib/src/decoder/DecodeOperation.d.ts +0 -23
- package/lib/src/decoder/DecodeOperation.js +0 -248
- package/lib/src/decoder/DecodeOperation.js.map +0 -1
- package/lib/src/decoder/Decoder.js +0 -114
- package/lib/src/decoder/Decoder.js.map +0 -1
- package/lib/src/decoder/ReferenceTracker.d.ts +0 -25
- package/lib/src/decoder/ReferenceTracker.js +0 -135
- package/lib/src/decoder/ReferenceTracker.js.map +0 -1
- package/lib/src/decoder/strategy/Callbacks.d.ts +0 -154
- package/lib/src/decoder/strategy/Callbacks.js +0 -336
- package/lib/src/decoder/strategy/Callbacks.js.map +0 -1
- package/lib/src/decoder/strategy/RawChanges.d.ts +0 -3
- package/lib/src/decoder/strategy/RawChanges.js +0 -4
- package/lib/src/decoder/strategy/RawChanges.js.map +0 -1
- package/lib/src/decoder/strategy/getDecoderStateCallbacks.d.ts +0 -76
- package/lib/src/decoder/strategy/getDecoderStateCallbacks.js +0 -274
- package/lib/src/decoder/strategy/getDecoderStateCallbacks.js.map +0 -1
- package/lib/src/encoder/ChangeTree.d.ts +0 -135
- package/lib/src/encoder/ChangeTree.js +0 -534
- package/lib/src/encoder/ChangeTree.js.map +0 -1
- package/lib/src/encoder/EncodeOperation.d.ts +0 -22
- package/lib/src/encoder/EncodeOperation.js +0 -132
- package/lib/src/encoder/EncodeOperation.js.map +0 -1
- package/lib/src/encoder/Encoder.d.ts +0 -22
- package/lib/src/encoder/Encoder.js +0 -204
- package/lib/src/encoder/Encoder.js.map +0 -1
- package/lib/src/encoder/Root.js +0 -229
- package/lib/src/encoder/Root.js.map +0 -1
- package/lib/src/encoder/StateView.js +0 -279
- package/lib/src/encoder/StateView.js.map +0 -1
- package/lib/src/encoding/assert.js +0 -49
- package/lib/src/encoding/assert.js.map +0 -1
- package/lib/src/encoding/decode.js +0 -217
- package/lib/src/encoding/decode.js.map +0 -1
- package/lib/src/encoding/encode.js +0 -279
- package/lib/src/encoding/encode.js.map +0 -1
- package/lib/src/encoding/spec.d.ts +0 -24
- package/lib/src/encoding/spec.js +0 -26
- package/lib/src/encoding/spec.js.map +0 -1
- package/lib/src/index.d.ts +0 -32
- package/lib/src/index.js +0 -39
- package/lib/src/index.js.map +0 -1
- package/lib/src/symbol.shim.js +0 -3
- package/lib/src/symbol.shim.js.map +0 -1
- package/lib/src/types/HelperTypes.d.ts +0 -77
- package/lib/src/types/HelperTypes.js +0 -2
- package/lib/src/types/HelperTypes.js.map +0 -1
- package/lib/src/types/TypeContext.d.ts +0 -31
- package/lib/src/types/TypeContext.js +0 -143
- package/lib/src/types/TypeContext.js.map +0 -1
- package/lib/src/types/custom/ArraySchema.js +0 -733
- package/lib/src/types/custom/ArraySchema.js.map +0 -1
- package/lib/src/types/custom/CollectionSchema.js +0 -170
- package/lib/src/types/custom/CollectionSchema.js.map +0 -1
- package/lib/src/types/custom/MapSchema.d.ts +0 -51
- package/lib/src/types/custom/MapSchema.js +0 -222
- package/lib/src/types/custom/MapSchema.js.map +0 -1
- package/lib/src/types/custom/SetSchema.js +0 -178
- package/lib/src/types/custom/SetSchema.js.map +0 -1
- package/lib/src/types/registry.js +0 -30
- package/lib/src/types/registry.js.map +0 -1
- package/lib/src/types/symbols.js +0 -34
- package/lib/src/types/symbols.js.map +0 -1
- package/lib/src/types/utils.js +0 -13
- package/lib/src/types/utils.js.map +0 -1
- package/lib/src/utils.d.ts +0 -13
- package/lib/src/utils.js +0 -49
- package/lib/src/utils.js.map +0 -1
- package/lib/src/v3_bench.js +0 -128
- package/lib/src/v3_bench.js.map +0 -1
- package/lib/symbol.shim.d.ts +0 -6
- package/lib/symbol.shim.js +0 -3
- package/lib/symbol.shim.js.map +0 -1
- package/lib/types/HelperTypes.js +0 -2
- package/lib/types/HelperTypes.js.map +0 -1
- package/lib/types/TypeContext.js +0 -143
- package/lib/types/TypeContext.js.map +0 -1
- package/lib/types/custom/ArraySchema.d.ts +0 -270
- package/lib/types/custom/ArraySchema.js +0 -733
- package/lib/types/custom/ArraySchema.js.map +0 -1
- package/lib/types/custom/CollectionSchema.d.ts +0 -51
- package/lib/types/custom/CollectionSchema.js +0 -170
- package/lib/types/custom/CollectionSchema.js.map +0 -1
- package/lib/types/custom/MapSchema.js +0 -222
- package/lib/types/custom/MapSchema.js.map +0 -1
- package/lib/types/custom/SetSchema.d.ts +0 -48
- package/lib/types/custom/SetSchema.js +0 -178
- package/lib/types/custom/SetSchema.js.map +0 -1
- package/lib/types/registry.d.ts +0 -16
- package/lib/types/registry.js +0 -30
- package/lib/types/registry.js.map +0 -1
- package/lib/types/symbols.d.ts +0 -33
- package/lib/types/symbols.js +0 -34
- package/lib/types/symbols.js.map +0 -1
- package/lib/types/utils.d.ts +0 -1
- package/lib/types/utils.js +0 -13
- package/lib/types/utils.js.map +0 -1
- package/lib/utils.js +0 -49
- package/lib/utils.js.map +0 -1
- package/lib/v3_bench.d.ts +0 -1
- package/lib/v3_bench.js +0 -128
- package/lib/v3_bench.js.map +0 -1
- /package/{lib → build}/codegen/api.d.ts +0 -0
- /package/{lib → build}/codegen/argv.d.ts +0 -0
- /package/{lib → build}/codegen/cli.d.ts +0 -0
- /package/{lib → build}/codegen/types.d.ts +0 -0
- /package/{lib → build}/encoding/spec.d.ts +0 -0
- /package/{lib/src → build}/symbol.shim.d.ts +0 -0
- /package/{lib/src → build}/types/symbols.d.ts +0 -0
- /package/{lib/src → build}/types/utils.d.ts +0 -0
- /package/{lib/src → build}/v3_bench.d.ts +0 -0
|
@@ -1,28 +1,28 @@
|
|
|
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
|
-
// C#-style Callbacks API
|
|
16
|
-
// Matches the API from: https://docs.colyseus.io/state/callbacks
|
|
15
|
+
// C#-style Callbacks API (https://docs.colyseus.io/state/callbacks)
|
|
17
16
|
//
|
|
18
17
|
// Key features:
|
|
19
18
|
// - Uses string property names with TypeScript auto-completion
|
|
20
|
-
// -
|
|
19
|
+
// - Parameter order (value, key) for onAdd/onRemove callbacks
|
|
21
20
|
// - Overloaded methods for nested instance callbacks
|
|
22
21
|
//
|
|
23
22
|
|
|
24
23
|
type PropertyChangeCallback<K> = (currentValue: K, previousValue: K) => void;
|
|
25
24
|
type KeyValueCallback<K, V> = (key: K, value: V) => void;
|
|
25
|
+
type ValueKeyCallback<V, K> = (value: V, key: K) => void;
|
|
26
26
|
type InstanceChangeCallback = () => void;
|
|
27
27
|
|
|
28
28
|
// Exclude internal properties from valid property names
|
|
@@ -45,32 +45,6 @@ type CollectionKeyType<T, K extends keyof T> =
|
|
|
45
45
|
T[K] extends ArraySchema<any> ? number :
|
|
46
46
|
T[K] extends Collection<infer Key, any, any> ? Key : never;
|
|
47
47
|
|
|
48
|
-
/**
|
|
49
|
-
* State Callbacks handler
|
|
50
|
-
*
|
|
51
|
-
* Usage:
|
|
52
|
-
* ```ts
|
|
53
|
-
* const $ = Callbacks.get(decoder);
|
|
54
|
-
*
|
|
55
|
-
* // Listen to property changes
|
|
56
|
-
* $.listen("currentTurn", (currentValue, previousValue) => { ... });
|
|
57
|
-
*
|
|
58
|
-
* // Listen to collection additions
|
|
59
|
-
* $.onAdd("entities", (sessionId, entity) => {
|
|
60
|
-
* // Nested property listening
|
|
61
|
-
* $.listen(entity, "hp", (currentHp, previousHp) => { ... });
|
|
62
|
-
* });
|
|
63
|
-
*
|
|
64
|
-
* // Listen to collection removals
|
|
65
|
-
* $.onRemove("entities", (sessionId, entity) => { ... });
|
|
66
|
-
*
|
|
67
|
-
* // Listen to any property change on an instance
|
|
68
|
-
* $.onChange(entity, () => { ... });
|
|
69
|
-
*
|
|
70
|
-
* // Bind properties to another object
|
|
71
|
-
* $.bindTo(player, playerVisual);
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
48
|
export class StateCallbackStrategy<TState extends Schema> {
|
|
75
49
|
protected decoder: Decoder<TState>;
|
|
76
50
|
protected uniqueRefIds: Set<number> = new Set();
|
|
@@ -131,7 +105,7 @@ export class StateCallbackStrategy<TState extends Schema> {
|
|
|
131
105
|
|
|
132
106
|
if (operation === OPERATION.ADD && immediate) {
|
|
133
107
|
(collection as Collection<any, any>).forEach((value: any, key: any) => {
|
|
134
|
-
handler(
|
|
108
|
+
handler(value, key);
|
|
135
109
|
});
|
|
136
110
|
}
|
|
137
111
|
|
|
@@ -244,7 +218,7 @@ export class StateCallbackStrategy<TState extends Schema> {
|
|
|
244
218
|
*/
|
|
245
219
|
onAdd<K extends CollectionPropNames<TState>>(
|
|
246
220
|
property: K,
|
|
247
|
-
handler:
|
|
221
|
+
handler: ValueKeyCallback<CollectionValueType<TState, K>, CollectionKeyType<TState, K>>,
|
|
248
222
|
immediate?: boolean
|
|
249
223
|
): () => void;
|
|
250
224
|
|
|
@@ -254,7 +228,7 @@ export class StateCallbackStrategy<TState extends Schema> {
|
|
|
254
228
|
onAdd<TInstance extends Schema, K extends CollectionPropNames<TInstance>>(
|
|
255
229
|
instance: TInstance,
|
|
256
230
|
property: K,
|
|
257
|
-
handler:
|
|
231
|
+
handler: ValueKeyCallback<CollectionValueType<TInstance, K>, CollectionKeyType<TInstance, K>>,
|
|
258
232
|
immediate?: boolean
|
|
259
233
|
): () => void;
|
|
260
234
|
|
|
@@ -285,7 +259,7 @@ export class StateCallbackStrategy<TState extends Schema> {
|
|
|
285
259
|
*/
|
|
286
260
|
onRemove<K extends CollectionPropNames<TState>>(
|
|
287
261
|
property: K,
|
|
288
|
-
handler:
|
|
262
|
+
handler: ValueKeyCallback<CollectionValueType<TState, K>, CollectionKeyType<TState, K>>
|
|
289
263
|
): () => void;
|
|
290
264
|
|
|
291
265
|
/**
|
|
@@ -294,7 +268,7 @@ export class StateCallbackStrategy<TState extends Schema> {
|
|
|
294
268
|
onRemove<TInstance extends Schema, K extends CollectionPropNames<TInstance>>(
|
|
295
269
|
instance: TInstance,
|
|
296
270
|
property: K,
|
|
297
|
-
handler:
|
|
271
|
+
handler: ValueKeyCallback<CollectionValueType<TInstance, K>, CollectionKeyType<TInstance, K>>
|
|
298
272
|
): () => void;
|
|
299
273
|
|
|
300
274
|
onRemove(...args: any[]): () => void {
|
|
@@ -426,11 +400,11 @@ export class StateCallbackStrategy<TState extends Schema> {
|
|
|
426
400
|
// FIXME: `previousValue` should always be available.
|
|
427
401
|
//
|
|
428
402
|
if (change.previousValue !== undefined) {
|
|
429
|
-
// trigger onRemove (
|
|
403
|
+
// trigger onRemove (value, key)
|
|
430
404
|
const deleteCallbacks = $callbacks[OPERATION.DELETE];
|
|
431
405
|
if (deleteCallbacks) {
|
|
432
406
|
for (let j = deleteCallbacks.length - 1; j >= 0; j--) {
|
|
433
|
-
deleteCallbacks[j](
|
|
407
|
+
deleteCallbacks[j](change.previousValue, dynamicIndex);
|
|
434
408
|
}
|
|
435
409
|
}
|
|
436
410
|
}
|
|
@@ -441,7 +415,7 @@ export class StateCallbackStrategy<TState extends Schema> {
|
|
|
441
415
|
if (addCallbacks) {
|
|
442
416
|
this.isTriggering = true;
|
|
443
417
|
for (let j = addCallbacks.length - 1; j >= 0; j--) {
|
|
444
|
-
addCallbacks[j](
|
|
418
|
+
addCallbacks[j](change.value, dynamicIndex);
|
|
445
419
|
}
|
|
446
420
|
this.isTriggering = false;
|
|
447
421
|
}
|
|
@@ -451,12 +425,12 @@ export class StateCallbackStrategy<TState extends Schema> {
|
|
|
451
425
|
(change.op & OPERATION.ADD) === OPERATION.ADD &&
|
|
452
426
|
change.previousValue !== change.value
|
|
453
427
|
) {
|
|
454
|
-
// trigger onAdd (
|
|
428
|
+
// trigger onAdd (value, key)
|
|
455
429
|
const addCallbacks = $callbacks[OPERATION.ADD];
|
|
456
430
|
if (addCallbacks) {
|
|
457
431
|
this.isTriggering = true;
|
|
458
432
|
for (let j = addCallbacks.length - 1; j >= 0; j--) {
|
|
459
|
-
addCallbacks[j](
|
|
433
|
+
addCallbacks[j](change.value, dynamicIndex);
|
|
460
434
|
}
|
|
461
435
|
this.isTriggering = false;
|
|
462
436
|
}
|
|
@@ -493,13 +467,13 @@ export const Callbacks = {
|
|
|
493
467
|
* callbacks.listen("currentTurn", (currentValue, previousValue) => { ... });
|
|
494
468
|
*
|
|
495
469
|
* // Listen to collection additions
|
|
496
|
-
* callbacks.onAdd("entities", (
|
|
470
|
+
* callbacks.onAdd("entities", (entity, sessionId) => {
|
|
497
471
|
* // Nested property listening
|
|
498
472
|
* callbacks.listen(entity, "hp", (currentHp, previousHp) => { ... });
|
|
499
473
|
* });
|
|
500
474
|
*
|
|
501
475
|
* // Listen to collection removals
|
|
502
|
-
* callbacks.onRemove("entities", (
|
|
476
|
+
* callbacks.onRemove("entities", (entity, sessionId) => { ... });
|
|
503
477
|
*
|
|
504
478
|
* // Listen to any property change on an instance
|
|
505
479
|
* callbacks.onChange(entity, () => { ... });
|
|
@@ -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
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { OPERATION } from "../encoding/spec";
|
|
2
|
-
import { Schema } from "../Schema";
|
|
3
|
-
import { $changes, $childType, $decoder, $onEncodeEnd, $encoder, $getByIndex, $refId, $refTypeFieldIndexes, $viewFieldIndexes, type $deleteByIndex } from "../types/symbols";
|
|
4
|
-
|
|
5
|
-
import type { MapSchema } from "../types/custom/MapSchema";
|
|
6
|
-
import type { ArraySchema } from "../types/custom/ArraySchema";
|
|
7
|
-
import type { CollectionSchema } from "../types/custom/CollectionSchema";
|
|
8
|
-
import type { SetSchema } from "../types/custom/SetSchema";
|
|
9
|
-
|
|
10
|
-
import { Root } from "./Root";
|
|
11
|
-
import { Metadata } from "../Metadata";
|
|
12
|
-
import type { EncodeOperation } from "./EncodeOperation";
|
|
13
|
-
import type { DecodeOperation } from "../decoder/DecodeOperation";
|
|
1
|
+
import { OPERATION } from "../encoding/spec.js";
|
|
2
|
+
import { Schema } from "../Schema.js";
|
|
3
|
+
import { $changes, $childType, $decoder, $onEncodeEnd, $encoder, $getByIndex, $refId, $refTypeFieldIndexes, $viewFieldIndexes, type $deleteByIndex } from "../types/symbols.js";
|
|
4
|
+
|
|
5
|
+
import type { MapSchema } from "../types/custom/MapSchema.js";
|
|
6
|
+
import type { ArraySchema } from "../types/custom/ArraySchema.js";
|
|
7
|
+
import type { CollectionSchema } from "../types/custom/CollectionSchema.js";
|
|
8
|
+
import type { SetSchema } from "../types/custom/SetSchema.js";
|
|
9
|
+
|
|
10
|
+
import { Root } from "./Root.js";
|
|
11
|
+
import { Metadata } from "../Metadata.js";
|
|
12
|
+
import type { EncodeOperation } from "./EncodeOperation.js";
|
|
13
|
+
import type { DecodeOperation } from "../decoder/DecodeOperation.js";
|
|
14
14
|
|
|
15
15
|
declare global {
|
|
16
16
|
interface Object {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { OPERATION } from "../encoding/spec";
|
|
2
|
-
import { $changes, $childType, $getByIndex, $refId } from "../types/symbols";
|
|
1
|
+
import { OPERATION } from "../encoding/spec.js";
|
|
2
|
+
import { $changes, $childType, $getByIndex, $refId } from "../types/symbols.js";
|
|
3
3
|
|
|
4
|
-
import { encode } from "../encoding/encode";
|
|
4
|
+
import { encode } from "../encoding/encode.js";
|
|
5
5
|
|
|
6
|
-
import type { ChangeTree, Ref } from "./ChangeTree";
|
|
7
|
-
import type { Encoder } from "./Encoder";
|
|
8
|
-
import type { Schema } from "../Schema";
|
|
6
|
+
import type { ChangeTree, Ref } from "./ChangeTree.js";
|
|
7
|
+
import type { Encoder } from "./Encoder.js";
|
|
8
|
+
import type { Schema } from "../Schema.js";
|
|
9
9
|
|
|
10
|
-
import type { Iterator } from "../encoding/decode";
|
|
11
|
-
import type { ArraySchema } from "../types/custom/ArraySchema";
|
|
12
|
-
import type { Metadata } from "../Metadata";
|
|
10
|
+
import type { Iterator } from "../encoding/decode.js";
|
|
11
|
+
import type { ArraySchema } from "../types/custom/ArraySchema.js";
|
|
12
|
+
import type { Metadata } from "../Metadata.js";
|
|
13
13
|
|
|
14
14
|
export type EncodeOperation<T extends Ref = any> = (
|
|
15
15
|
encoder: Encoder,
|
package/src/encoder/Encoder.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { Schema } from "../Schema";
|
|
2
|
-
import { TypeContext } from "../types/TypeContext";
|
|
3
|
-
import { $changes, $encoder, $filter, $getByIndex, $refId } from "../types/symbols";
|
|
1
|
+
import type { Schema } from "../Schema.js";
|
|
2
|
+
import { TypeContext } from "../types/TypeContext.js";
|
|
3
|
+
import { $changes, $encoder, $filter, $getByIndex, $refId } from "../types/symbols.js";
|
|
4
4
|
|
|
5
|
-
import { encode } from "../encoding/encode";
|
|
6
|
-
import type { Iterator } from "../encoding/decode";
|
|
5
|
+
import { encode } from "../encoding/encode.js";
|
|
6
|
+
import type { Iterator } from "../encoding/decode.js";
|
|
7
7
|
|
|
8
|
-
import { OPERATION, SWITCH_TO_STRUCTURE, TYPE_ID } from '../encoding/spec';
|
|
9
|
-
import { Root } from "./Root";
|
|
8
|
+
import { OPERATION, SWITCH_TO_STRUCTURE, TYPE_ID } from '../encoding/spec.js';
|
|
9
|
+
import { Root } from "./Root.js";
|
|
10
10
|
|
|
11
|
-
import type { StateView } from "./StateView";
|
|
12
|
-
import type { ChangeSetName, ChangeTree, ChangeTreeList, ChangeTreeNode } from "./ChangeTree";
|
|
13
|
-
import { createChangeTreeList } from "./ChangeTree";
|
|
11
|
+
import type { StateView } from "./StateView.js";
|
|
12
|
+
import type { ChangeSetName, ChangeTree, ChangeTreeList, ChangeTreeNode } from "./ChangeTree.js";
|
|
13
|
+
import { createChangeTreeList } from "./ChangeTree.js";
|
|
14
14
|
|
|
15
15
|
function concatBytes(a: Uint8Array, b: Uint8Array): Uint8Array {
|
|
16
16
|
const result = new Uint8Array(a.length + b.length);
|
package/src/encoder/Root.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { OPERATION } from "../encoding/spec";
|
|
2
|
-
import { TypeContext } from "../types/TypeContext";
|
|
3
|
-
import { ChangeTree, setOperationAtIndex, ChangeTreeList, createChangeTreeList, ChangeSetName, type ChangeTreeNode } from "./ChangeTree";
|
|
4
|
-
import { $changes, $refId } from "../types/symbols";
|
|
1
|
+
import { OPERATION } from "../encoding/spec.js";
|
|
2
|
+
import { TypeContext } from "../types/TypeContext.js";
|
|
3
|
+
import { ChangeTree, setOperationAtIndex, ChangeTreeList, createChangeTreeList, ChangeSetName, type ChangeTreeNode } from "./ChangeTree.js";
|
|
4
|
+
import { $changes, $refId } from "../types/symbols.js";
|
|
5
5
|
|
|
6
6
|
export class Root {
|
|
7
7
|
protected nextUniqueId: number = 0;
|
package/src/encoder/StateView.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ChangeTree, IndexedOperations, Ref } from "./ChangeTree";
|
|
2
|
-
import { $changes, $fieldIndexesByViewTag, $refId, $viewFieldIndexes } from "../types/symbols";
|
|
3
|
-
import { DEFAULT_VIEW_TAG } from "../annotations";
|
|
4
|
-
import { OPERATION } from "../encoding/spec";
|
|
5
|
-
import { Metadata } from "../Metadata";
|
|
6
|
-
import { spliceOne } from "../types/utils";
|
|
7
|
-
import type { Schema } from "../Schema";
|
|
1
|
+
import { ChangeTree, IndexedOperations, Ref } from "./ChangeTree.js";
|
|
2
|
+
import { $changes, $fieldIndexesByViewTag, $refId, $viewFieldIndexes } from "../types/symbols.js";
|
|
3
|
+
import { DEFAULT_VIEW_TAG } from "../annotations.js";
|
|
4
|
+
import { OPERATION } from "../encoding/spec.js";
|
|
5
|
+
import { Metadata } from "../Metadata.js";
|
|
6
|
+
import { spliceOne } from "../types/utils.js";
|
|
7
|
+
import type { Schema } from "../Schema.js";
|
|
8
8
|
|
|
9
9
|
export function createView(iterable: boolean = false) {
|
|
10
10
|
return new StateView(iterable);
|
package/src/encoding/assert.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Schema } from "../Schema";
|
|
2
|
-
import type { CollectionSchema } from "../types/custom/CollectionSchema";
|
|
3
|
-
import type { MapSchema } from "../types/custom/MapSchema";
|
|
4
|
-
import type { SetSchema } from "../types/custom/SetSchema";
|
|
5
|
-
import type { ArraySchema } from "../types/custom/ArraySchema";
|
|
6
|
-
import type { Ref } from "../encoder/ChangeTree";
|
|
1
|
+
import type { Schema } from "../Schema.js";
|
|
2
|
+
import type { CollectionSchema } from "../types/custom/CollectionSchema.js";
|
|
3
|
+
import type { MapSchema } from "../types/custom/MapSchema.js";
|
|
4
|
+
import type { SetSchema } from "../types/custom/SetSchema.js";
|
|
5
|
+
import type { ArraySchema } from "../types/custom/ArraySchema.js";
|
|
6
|
+
import type { Ref } from "../encoder/ChangeTree.js";
|
|
7
7
|
|
|
8
8
|
export class EncodeSchemaError extends Error {}
|
|
9
9
|
|
package/src/encoding/decode.ts
CHANGED
package/src/encoding/encode.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export { Schema } from "./Schema";
|
|
2
|
-
export type { DataChange } from "./decoder/DecodeOperation";
|
|
3
|
-
export type { ToJSON } from "./types/HelperTypes";
|
|
1
|
+
export { Schema } from "./Schema.js";
|
|
2
|
+
export type { DataChange } from "./decoder/DecodeOperation.js";
|
|
3
|
+
export type { ToJSON } from "./types/HelperTypes.js";
|
|
4
4
|
|
|
5
|
-
import { MapSchema } from "./types/custom/MapSchema"
|
|
5
|
+
import { MapSchema } from "./types/custom/MapSchema.js"
|
|
6
6
|
export { MapSchema };
|
|
7
7
|
|
|
8
|
-
import { ArraySchema } from "./types/custom/ArraySchema";
|
|
8
|
+
import { ArraySchema } from "./types/custom/ArraySchema.js";
|
|
9
9
|
export { ArraySchema };
|
|
10
10
|
|
|
11
|
-
import { CollectionSchema } from "./types/custom/CollectionSchema";
|
|
11
|
+
import { CollectionSchema } from "./types/custom/CollectionSchema.js";
|
|
12
12
|
export { CollectionSchema };
|
|
13
13
|
|
|
14
|
-
import { SetSchema } from "./types/custom/SetSchema";
|
|
14
|
+
import { SetSchema } from "./types/custom/SetSchema.js";
|
|
15
15
|
export { SetSchema };
|
|
16
16
|
|
|
17
|
-
import { registerType, defineCustomTypes } from "./types/registry";
|
|
17
|
+
import { registerType, defineCustomTypes } from "./types/registry.js";
|
|
18
18
|
export { registerType, defineCustomTypes };
|
|
19
19
|
|
|
20
20
|
registerType("map", { constructor: MapSchema });
|
|
@@ -23,22 +23,22 @@ registerType("set", { constructor: SetSchema });
|
|
|
23
23
|
registerType("collection", { constructor: CollectionSchema, });
|
|
24
24
|
|
|
25
25
|
// Utils
|
|
26
|
-
export { dumpChanges } from "./utils";
|
|
26
|
+
export { dumpChanges } from "./utils.js";
|
|
27
27
|
|
|
28
28
|
// Encoder / Decoder
|
|
29
|
-
export { $track, $encoder, $decoder, $filter, $getByIndex, $deleteByIndex, $changes, $childType, $refId } from "./types/symbols";
|
|
30
|
-
export { encode } from "./encoding/encode";
|
|
31
|
-
export { decode, type Iterator } from "./encoding/decode";
|
|
29
|
+
export { $track, $encoder, $decoder, $filter, $getByIndex, $deleteByIndex, $changes, $childType, $refId } from "./types/symbols.js";
|
|
30
|
+
export { encode } from "./encoding/encode.js";
|
|
31
|
+
export { decode, type Iterator } from "./encoding/decode.js";
|
|
32
32
|
|
|
33
33
|
// Reflection
|
|
34
34
|
export {
|
|
35
35
|
Reflection,
|
|
36
36
|
ReflectionType,
|
|
37
37
|
ReflectionField,
|
|
38
|
-
} from "./Reflection";
|
|
38
|
+
} from "./Reflection.js";
|
|
39
39
|
|
|
40
40
|
// Annotations, Metadata and TypeContext
|
|
41
|
-
export { Metadata } from "./Metadata";
|
|
41
|
+
export { Metadata } from "./Metadata.js";
|
|
42
42
|
|
|
43
43
|
// Schema definition types
|
|
44
44
|
export {
|
|
@@ -55,23 +55,23 @@ export {
|
|
|
55
55
|
type SchemaWithExtendsConstructor,
|
|
56
56
|
type SchemaWithExtends,
|
|
57
57
|
type SchemaType,
|
|
58
|
-
} from "./annotations";
|
|
58
|
+
} from "./annotations.js";
|
|
59
59
|
|
|
60
|
-
export { TypeContext } from "./types/TypeContext";
|
|
60
|
+
export { TypeContext } from "./types/TypeContext.js";
|
|
61
61
|
|
|
62
62
|
// Helper types for type inference
|
|
63
|
-
export type { InferValueType, InferSchemaInstanceType, AssignableProps } from "./types/HelperTypes";
|
|
63
|
+
export type { InferValueType, InferSchemaInstanceType, AssignableProps } from "./types/HelperTypes.js";
|
|
64
64
|
|
|
65
|
-
export { getDecoderStateCallbacks, type CallbackProxy, type SchemaCallback, type CollectionCallback, type SchemaCallbackProxy } from "./decoder/strategy/getDecoderStateCallbacks";
|
|
66
|
-
export { Callbacks, StateCallbackStrategy } from "./decoder/strategy/Callbacks";
|
|
67
|
-
export { getRawChangesCallback } from "./decoder/strategy/RawChanges";
|
|
65
|
+
export { getDecoderStateCallbacks, type CallbackProxy, type SchemaCallback, type CollectionCallback, type SchemaCallbackProxy } from "./decoder/strategy/getDecoderStateCallbacks.js";
|
|
66
|
+
export { Callbacks, StateCallbackStrategy } from "./decoder/strategy/Callbacks.js";
|
|
67
|
+
export { getRawChangesCallback } from "./decoder/strategy/RawChanges.js";
|
|
68
68
|
|
|
69
|
-
export { Encoder } from "./encoder/Encoder";
|
|
70
|
-
export { encodeSchemaOperation, encodeArray, encodeKeyValueOperation } from "./encoder/EncodeOperation";
|
|
71
|
-
export { ChangeTree, type Ref, type IRef, type ChangeSetName, type ChangeSet} from "./encoder/ChangeTree";
|
|
72
|
-
export { StateView } from "./encoder/StateView";
|
|
69
|
+
export { Encoder } from "./encoder/Encoder.js";
|
|
70
|
+
export { encodeSchemaOperation, encodeArray, encodeKeyValueOperation } from "./encoder/EncodeOperation.js";
|
|
71
|
+
export { ChangeTree, type Ref, type IRef, type ChangeSetName, type ChangeSet} from "./encoder/ChangeTree.js";
|
|
72
|
+
export { StateView } from "./encoder/StateView.js";
|
|
73
73
|
|
|
74
|
-
export { Decoder } from "./decoder/Decoder";
|
|
75
|
-
export { decodeSchemaOperation, decodeKeyValueOperation } from "./decoder/DecodeOperation";
|
|
74
|
+
export { Decoder } from "./decoder/Decoder.js";
|
|
75
|
+
export { decodeSchemaOperation, decodeKeyValueOperation } from "./decoder/DecodeOperation.js";
|
|
76
76
|
|
|
77
|
-
export { OPERATION } from "./encoding/spec";
|
|
77
|
+
export { OPERATION } from "./encoding/spec.js";
|
package/src/types/HelperTypes.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Definition, DefinitionType, PrimitiveType, RawPrimitiveType } 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, RawPrimitiveType } 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
|
|
|
8
8
|
export type Constructor<T = {}> = new (...args: any[]) => T;
|
|
9
9
|
|
package/src/types/TypeContext.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Metadata } from "../Metadata";
|
|
2
|
-
import { Schema } from "../Schema";
|
|
3
|
-
import { $viewFieldIndexes } from "./symbols";
|
|
1
|
+
import { Metadata } from "../Metadata.js";
|
|
2
|
+
import { Schema } from "../Schema.js";
|
|
3
|
+
import { $viewFieldIndexes } from "./symbols.js";
|
|
4
4
|
|
|
5
5
|
export class TypeContext {
|
|
6
6
|
types: { [id: number]: typeof Schema; } = {};
|
|
@@ -1,14 +1,14 @@
|
|
|
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, setOperationAtIndex } from "../../encoder/ChangeTree";
|
|
4
|
-
import { OPERATION } from "../../encoding/spec";
|
|
5
|
-
import { registerType } from "../registry";
|
|
6
|
-
import { Collection } from "../HelperTypes";
|
|
7
|
-
|
|
8
|
-
import { encodeArray } from "../../encoder/EncodeOperation";
|
|
9
|
-
import { decodeArray } from "../../decoder/DecodeOperation";
|
|
10
|
-
import type { StateView } from "../../encoder/StateView";
|
|
11
|
-
import { assertInstanceType } from "../../encoding/assert";
|
|
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, setOperationAtIndex } from "../../encoder/ChangeTree.js";
|
|
4
|
+
import { OPERATION } from "../../encoding/spec.js";
|
|
5
|
+
import { registerType } from "../registry.js";
|
|
6
|
+
import { Collection } from "../HelperTypes.js";
|
|
7
|
+
|
|
8
|
+
import { encodeArray } from "../../encoder/EncodeOperation.js";
|
|
9
|
+
import { decodeArray } from "../../decoder/DecodeOperation.js";
|
|
10
|
+
import type { StateView } from "../../encoder/StateView.js";
|
|
11
|
+
import { assertInstanceType } from "../../encoding/assert.js";
|
|
12
12
|
|
|
13
13
|
const DEFAULT_SORT = (a: any, b: any) => {
|
|
14
14
|
const A = a.toString();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd, $refId } from "../symbols";
|
|
2
|
-
import { ChangeTree, type IRef } from "../../encoder/ChangeTree";
|
|
3
|
-
import { OPERATION } from "../../encoding/spec";
|
|
4
|
-
import { registerType } from "../registry";
|
|
5
|
-
import { Collection } from "../HelperTypes";
|
|
6
|
-
import { decodeKeyValueOperation } from "../../decoder/DecodeOperation";
|
|
7
|
-
import { encodeKeyValueOperation } from "../../encoder/EncodeOperation";
|
|
8
|
-
import type { StateView } from "../../encoder/StateView";
|
|
9
|
-
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 { OPERATION } from "../../encoding/spec.js";
|
|
4
|
+
import { registerType } from "../registry.js";
|
|
5
|
+
import { Collection } from "../HelperTypes.js";
|
|
6
|
+
import { decodeKeyValueOperation } from "../../decoder/DecodeOperation.js";
|
|
7
|
+
import { encodeKeyValueOperation } from "../../encoder/EncodeOperation.js";
|
|
8
|
+
import type { StateView } from "../../encoder/StateView.js";
|
|
9
|
+
import type { Schema } from "../../Schema.js";
|
|
10
10
|
|
|
11
11
|
type K = number; // TODO: allow to specify K generic on MapSchema.
|
|
12
12
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $numFields, $refId } from "../symbols";
|
|
2
|
-
import { ChangeTree, IRef } from "../../encoder/ChangeTree";
|
|
3
|
-
import { OPERATION } from "../../encoding/spec";
|
|
4
|
-
import { registerType } from "../registry";
|
|
5
|
-
import { Collection } from "../HelperTypes";
|
|
6
|
-
import { decodeKeyValueOperation } from "../../decoder/DecodeOperation";
|
|
7
|
-
import { encodeKeyValueOperation } from "../../encoder/EncodeOperation";
|
|
8
|
-
import type { StateView } from "../../encoder/StateView";
|
|
9
|
-
import type { Schema } from "../../Schema";
|
|
10
|
-
import { assertInstanceType } from "../../encoding/assert";
|
|
1
|
+
import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $numFields, $refId } from "../symbols.js";
|
|
2
|
+
import { ChangeTree, IRef } from "../../encoder/ChangeTree.js";
|
|
3
|
+
import { OPERATION } from "../../encoding/spec.js";
|
|
4
|
+
import { registerType } from "../registry.js";
|
|
5
|
+
import { Collection } from "../HelperTypes.js";
|
|
6
|
+
import { decodeKeyValueOperation } from "../../decoder/DecodeOperation.js";
|
|
7
|
+
import { encodeKeyValueOperation } from "../../encoder/EncodeOperation.js";
|
|
8
|
+
import type { StateView } from "../../encoder/StateView.js";
|
|
9
|
+
import type { Schema } from "../../Schema.js";
|
|
10
|
+
import { assertInstanceType } from "../../encoding/assert.js";
|
|
11
11
|
|
|
12
12
|
export class MapSchema<V=any, K extends string = string> implements Map<K, V>, Collection<K, V, [K, V]>, IRef {
|
|
13
13
|
[$changes]: ChangeTree;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { OPERATION } from "../../encoding/spec";
|
|
2
|
-
import { registerType } from "../registry";
|
|
3
|
-
import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd, $refId } from "../symbols";
|
|
4
|
-
import { Collection } from "../HelperTypes";
|
|
5
|
-
import { ChangeTree, type IRef } from "../../encoder/ChangeTree";
|
|
6
|
-
import { encodeKeyValueOperation } from "../../encoder/EncodeOperation";
|
|
7
|
-
import { decodeKeyValueOperation } from "../../decoder/DecodeOperation";
|
|
8
|
-
import type { StateView } from "../../encoder/StateView";
|
|
9
|
-
import type { Schema } from "../../Schema";
|
|
1
|
+
import { OPERATION } from "../../encoding/spec.js";
|
|
2
|
+
import { registerType } from "../registry.js";
|
|
3
|
+
import { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $onEncodeEnd, $refId } from "../symbols.js";
|
|
4
|
+
import { Collection } from "../HelperTypes.js";
|
|
5
|
+
import { ChangeTree, type IRef } from "../../encoder/ChangeTree.js";
|
|
6
|
+
import { encodeKeyValueOperation } from "../../encoder/EncodeOperation.js";
|
|
7
|
+
import { decodeKeyValueOperation } from "../../decoder/DecodeOperation.js";
|
|
8
|
+
import type { StateView } from "../../encoder/StateView.js";
|
|
9
|
+
import type { Schema } from "../../Schema.js";
|
|
10
10
|
|
|
11
11
|
export class SetSchema<V=any> implements Collection<number, V>, IRef {
|
|
12
12
|
[$changes]: ChangeTree;
|
package/src/types/registry.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DefinitionType, type } from "../annotations";
|
|
2
|
-
import { BufferLike, encode } from "../encoding/encode";
|
|
3
|
-
import { decode, Iterator } from "../encoding/decode";
|
|
1
|
+
import { DefinitionType, type } from "../annotations.js";
|
|
2
|
+
import { BufferLike, encode } from "../encoding/encode.js";
|
|
3
|
+
import { decode, Iterator } from "../encoding/decode.js";
|
|
4
4
|
|
|
5
5
|
export interface TypeDefinition {
|
|
6
6
|
constructor?: any,
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Schema } from "./Schema";
|
|
2
|
-
import { OPERATION } from "./encoding/spec";
|
|
3
|
-
import { $changes, $refId } from "./types/symbols";
|
|
1
|
+
import type { Schema } from "./Schema.js";
|
|
2
|
+
import { OPERATION } from "./encoding/spec.js";
|
|
3
|
+
import { $changes, $refId } from "./types/symbols.js";
|
|
4
4
|
|
|
5
5
|
interface ChangeDump {
|
|
6
6
|
ops: {
|
package/src/v3_bench.ts
CHANGED