@bikky/replication 1.0.1
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/Constants/Errors.d.ts +27 -0
- package/Constants/Errors.js +75 -0
- package/Constants/Logging.d.ts +17 -0
- package/Constants/Logging.js +97 -0
- package/Constants/ReplicableRegistry.d.ts +37 -0
- package/Constants/ReplicableRegistry.js +234 -0
- package/Constants/SerialisationTypes.d.ts +82 -0
- package/Constants/SerialisationTypes.js +160 -0
- package/Constants/SourceMaps.d.ts +10 -0
- package/Constants/SourceMaps.js +12 -0
- package/Constants/TraversalStep.d.ts +5 -0
- package/Constants/TraversalStep.js +2 -0
- package/Constants/Versions.d.ts +15 -0
- package/Constants/Versions.js +63 -0
- package/Expressions/Compiler/BuiltinGrammar.d.ts +234 -0
- package/Expressions/Compiler/BuiltinGrammar.js +446 -0
- package/Expressions/Compiler/ExpressionGrammar.d.ts +89 -0
- package/Expressions/Compiler/ExpressionGrammar.js +70 -0
- package/Expressions/Compiler/Parser.d.ts +56 -0
- package/Expressions/Compiler/Parser.js +314 -0
- package/Expressions/Compiler/Tokenizer.d.ts +52 -0
- package/Expressions/Compiler/Tokenizer.js +222 -0
- package/Expressions/Compiler/__tests__/Replicable.Expressions.Parser.test.d.ts +1 -0
- package/Expressions/Compiler/__tests__/Replicable.Expressions.Parser.test.js +516 -0
- package/Expressions/Compiler/__tests__/Replicable.Expressions.Tokenizer.test.d.ts +1 -0
- package/Expressions/Compiler/__tests__/Replicable.Expressions.Tokenizer.test.js +68 -0
- package/Expressions/CreateEvaluator.d.ts +4 -0
- package/Expressions/CreateEvaluator.js +85 -0
- package/Expressions/EvaluatorChain.d.ts +19 -0
- package/Expressions/EvaluatorChain.js +137 -0
- package/Expressions/EvaluatorSteps.d.ts +19 -0
- package/Expressions/EvaluatorSteps.js +12 -0
- package/Expressions/EvaluatorString.d.ts +21 -0
- package/Expressions/EvaluatorString.js +26 -0
- package/Expressions/Expression.d.ts +36 -0
- package/Expressions/Expression.js +147 -0
- package/Expressions/Traverser.d.ts +28 -0
- package/Expressions/Traverser.js +348 -0
- package/Expressions/TypeRegistry/Accessors.d.ts +26 -0
- package/Expressions/TypeRegistry/Accessors.js +58 -0
- package/Expressions/TypeRegistry/ChainCollections.d.ts +51 -0
- package/Expressions/TypeRegistry/ChainCollections.js +134 -0
- package/Expressions/TypeRegistry/ChainTypes.d.ts +23 -0
- package/Expressions/TypeRegistry/ChainTypes.js +46 -0
- package/Expressions/TypeRegistry/CustomAPI.d.ts +36 -0
- package/Expressions/TypeRegistry/CustomAPI.js +181 -0
- package/Expressions/TypeRegistry/Primitive.d.ts +19 -0
- package/Expressions/TypeRegistry/Primitive.js +47 -0
- package/Expressions/TypeRegistry/Registry.d.ts +27 -0
- package/Expressions/TypeRegistry/Registry.js +270 -0
- package/Expressions/TypeRegistry/ReplAPI.d.ts +41 -0
- package/Expressions/TypeRegistry/ReplAPI.js +220 -0
- package/Expressions/TypeRegistry/Scope.d.ts +24 -0
- package/Expressions/TypeRegistry/Scope.js +44 -0
- package/Expressions/TypeRegistry/Types.d.ts +23 -0
- package/Expressions/TypeRegistry/Types.js +1 -0
- package/Expressions/TypeRegistry/__tests__/Replicable.Expressions.Accessors.test.d.ts +1 -0
- package/Expressions/TypeRegistry/__tests__/Replicable.Expressions.Accessors.test.js +31 -0
- package/Expressions/__tests__/ExpressionExamples.d.ts +28 -0
- package/Expressions/__tests__/ExpressionExamples.js +50 -0
- package/Expressions/__tests__/Replicable.Expressions.Expressions.test.d.ts +1 -0
- package/Expressions/__tests__/Replicable.Expressions.Expressions.test.js +166 -0
- package/IDPool.d.ts +18 -0
- package/IDPool.data.d.ts +17 -0
- package/IDPool.js +139 -0
- package/License.txt +1 -0
- package/Main.d.ts +13 -0
- package/Main.js +13 -0
- package/Networking.d.ts +60 -0
- package/Networking.js +626 -0
- package/Replicatable.d.ts +66 -0
- package/Replicatable.js +123 -0
- package/Tracking/Buffable.d.ts +68 -0
- package/Tracking/Buffable.js +194 -0
- package/Tracking/Class.d.ts +97 -0
- package/Tracking/Class.js +221 -0
- package/Tracking/Functions.d.ts +14 -0
- package/Tracking/Functions.js +27 -0
- package/Tracking/GlobalGroup.d.ts +5 -0
- package/Tracking/GlobalGroup.js +39 -0
- package/Tracking/Property.d.ts +95 -0
- package/Tracking/Property.js +125 -0
- package/Tracking/Types.d.ts +33 -0
- package/Tracking/Types.js +1 -0
- package/Tracking/__tests__/Replicable.Tracking.Decorator.test.d.ts +1 -0
- package/Tracking/__tests__/Replicable.Tracking.Decorator.test.js +151 -0
- package/Tracking/__tests__/Replicable.Tracking.Deserialisation.test.d.ts +1 -0
- package/Tracking/__tests__/Replicable.Tracking.Deserialisation.test.js +253 -0
- package/Tracking/__tests__/Replicable.Tracking.MixinSchemaGeneration.test.d.ts +1 -0
- package/Tracking/__tests__/Replicable.Tracking.MixinSchemaGeneration.test.js +135 -0
- package/Tracking/__tests__/Replicable.Tracking.Struct.test.d.ts +1 -0
- package/Tracking/__tests__/Replicable.Tracking.Struct.test.js +66 -0
- package/Tracking/__tests__/Replicable.Tracking.Type.test.d.ts +1 -0
- package/Tracking/__tests__/Replicable.Tracking.Type.test.js +67 -0
- package/Transformers/Configurer.d.ts +39 -0
- package/Transformers/Configurer.js +415 -0
- package/Transformers/Constructor.d.ts +12 -0
- package/Transformers/Constructor.js +44 -0
- package/Transformers/Definitions.d.ts +102 -0
- package/Transformers/Definitions.js +626 -0
- package/Transformers/Loader.d.ts +45 -0
- package/Transformers/Loader.js +350 -0
- package/Transformers/Progress.d.ts +32 -0
- package/Transformers/Progress.js +429 -0
- package/Transformers/Reference.d.ts +37 -0
- package/Transformers/Reference.js +212 -0
- package/Transformers/SchemaGenerator.d.ts +102 -0
- package/Transformers/SchemaGenerator.js +564 -0
- package/Transformers/Serialiser.d.ts +31 -0
- package/Transformers/Serialiser.js +366 -0
- package/Transformers/Utils.d.ts +33 -0
- package/Transformers/Utils.js +287 -0
- package/Transformers/__tests__/Examples.d.ts +168 -0
- package/Transformers/__tests__/Examples.js +263 -0
- package/Transformers/__tests__/Replicable.Transformers.Definitions.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.Definitions.test.js +457 -0
- package/Transformers/__tests__/Replicable.Transformers.Loader.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.Loader.test.js +339 -0
- package/Transformers/__tests__/Replicable.Transformers.Progress.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.Progress.test.js +256 -0
- package/Transformers/__tests__/Replicable.Transformers.Reference.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.Reference.test.js +167 -0
- package/Transformers/__tests__/Replicable.Transformers.SchemaGenerator.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.SchemaGenerator.test.js +400 -0
- package/Transformers/__tests__/Replicable.Transformers.SchemaGeneratorOutput.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.SchemaGeneratorOutput.test.js +441 -0
- package/Transformers/__tests__/Replicable.Transformers.Serialiser.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.Serialiser.test.js +320 -0
- package/Transformers/__tests__/Replicable.Transformers.Utils.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.Utils.test.js +534 -0
- package/__tests__/Replicable.Expressions.test.d.ts +1 -0
- package/__tests__/Replicable.Expressions.test.js +166 -0
- package/__tests__/Replicable.IDPool.test.d.ts +1 -0
- package/__tests__/Replicable.IDPool.test.js +11 -0
- package/__tests__/Replicable.ReplicableRegistry.test.d.ts +1 -0
- package/__tests__/Replicable.ReplicableRegistry.test.js +154 -0
- package/__tests__/Replicable.Serialisation.test.d.ts +1 -0
- package/__tests__/Replicable.Serialisation.test.js +283 -0
- package/package.json +14 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PropertyTypes } from "../Constants/SerialisationTypes.js";
|
|
2
|
+
import { SourceMap } from "../Constants/SourceMaps.js";
|
|
3
|
+
import { ReplicableClass } from "../Tracking/Class.js";
|
|
4
|
+
import { PropertyConfiguration } from "../Tracking/Property.js";
|
|
5
|
+
/**
|
|
6
|
+
* Keeps track of references that need to be changed on load.
|
|
7
|
+
* TODO: This may not be necessary anymore with Authority having a remapper system.
|
|
8
|
+
*/
|
|
9
|
+
export declare namespace Serialiser {
|
|
10
|
+
interface SerialisationInformation {
|
|
11
|
+
ownerRepl: ReplicableClass;
|
|
12
|
+
owner?: any;
|
|
13
|
+
source: SourceMap;
|
|
14
|
+
}
|
|
15
|
+
function SerialiseSingle(info: SerialisationInformation, conf: PropertyConfiguration, val: any, mods: PropertyTypes): [string, ...any[]];
|
|
16
|
+
function DeserialiseSingle(info: SerialisationInformation, conf: PropertyConfiguration, target: any, val: any, mod: PropertyTypes): any;
|
|
17
|
+
function SerialiseProp(info: SerialisationInformation, conf: PropertyConfiguration, val: any): any;
|
|
18
|
+
function DeserialiseProp(info: SerialisationInformation, conf: PropertyConfiguration, target: any, val: [name: string, data: any]): any;
|
|
19
|
+
function SerialiseRepl(type: ReplicableClass, source: SourceMap, object: any): [string, any];
|
|
20
|
+
function DeserialiseRepl(type: ReplicableClass, source: SourceMap, target: {
|
|
21
|
+
[key: string | symbol]: any;
|
|
22
|
+
}, serialised: [string, {
|
|
23
|
+
[key: string]: any[];
|
|
24
|
+
}], skipCustomDeserialiser?: boolean): {
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
[key: symbol]: any;
|
|
27
|
+
};
|
|
28
|
+
function IsSerialisable(object: any): boolean;
|
|
29
|
+
function Serialise<T>(object: T): [string, any];
|
|
30
|
+
function Deserialise<T>(object: T, data: [string, any]): T;
|
|
31
|
+
}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { ClassCategory, describeObject, isPrimitiveType, isPrimitiveValue, PropertyTypes, TypeSymbol, ValueIsPrimitiveType } from "../Constants/SerialisationTypes.js";
|
|
2
|
+
import { Expression } from "../Expressions/Expression.js";
|
|
3
|
+
import { ReplicableRegistry } from "../Constants/ReplicableRegistry.js";
|
|
4
|
+
import { Pointer, Referencer } from "./Reference.js";
|
|
5
|
+
import { __PrivateConstructorSetup, Constructor } from "./Constructor.js";
|
|
6
|
+
import { Versions } from "../Constants/Versions.js";
|
|
7
|
+
import { Loader } from "./Loader.js";
|
|
8
|
+
/**
|
|
9
|
+
* Keeps track of references that need to be changed on load.
|
|
10
|
+
* TODO: This may not be necessary anymore with Authority having a remapper system.
|
|
11
|
+
*/
|
|
12
|
+
export var Serialiser;
|
|
13
|
+
(function (Serialiser) {
|
|
14
|
+
var IsPropertyExpression = Loader.IsPropertyExpression;
|
|
15
|
+
var __GetReplicableForDataName = ReplicableRegistry.__GetReplicableForDataName;
|
|
16
|
+
function SerialiseSingle(info, conf, val, mods) {
|
|
17
|
+
for (let typeInfo of conf.serialisation.types) {
|
|
18
|
+
if (!PropertyTypes.isType(typeInfo.modifiers, mods)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (isPrimitiveValue(val)) {
|
|
22
|
+
for (let type of typeInfo.types) {
|
|
23
|
+
if (isPrimitiveType(type)) {
|
|
24
|
+
if (!ValueIsPrimitiveType(type, val)) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
return ["Primitive", val];
|
|
28
|
+
}
|
|
29
|
+
if (isPrimitiveValue(val) && ClassCategory.isType(type.category, ClassCategory.Custom)) {
|
|
30
|
+
return Referencer.Reference(val, type);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (PropertyTypes.isType(typeInfo.modifiers, PropertyTypes.ForceInline)) {
|
|
36
|
+
let rawVal = val;
|
|
37
|
+
if (val instanceof Pointer) {
|
|
38
|
+
rawVal = val.valOrNull;
|
|
39
|
+
}
|
|
40
|
+
if (rawVal === null) {
|
|
41
|
+
return ["Primitive", null];
|
|
42
|
+
}
|
|
43
|
+
if (TypeSymbol in rawVal) {
|
|
44
|
+
return Serialiser.Serialise(rawVal);
|
|
45
|
+
}
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
else if (PropertyTypes.isType(typeInfo.modifiers, PropertyTypes.Serialised)) {
|
|
49
|
+
if (Array.isArray(val) && val.length === 2 && ReplicableRegistry.HasType(val[0])) {
|
|
50
|
+
return val;
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
else if (PropertyTypes.isType(typeInfo.modifiers, PropertyTypes.Definition)) {
|
|
55
|
+
if (val.__proto__ === Object.prototype && "Class" in val) {
|
|
56
|
+
return [val.Class, val];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
for (let unknownType of typeInfo.types) {
|
|
61
|
+
if (isPrimitiveType(unknownType)) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
//We handled primitives earlier.
|
|
65
|
+
let type = unknownType;
|
|
66
|
+
if (ClassCategory.isType(type.category, ClassCategory.Inlined)) {
|
|
67
|
+
if (val.valOrNull == null)
|
|
68
|
+
return ["Primitive", null];
|
|
69
|
+
return Serialiser.Serialise(val.val);
|
|
70
|
+
}
|
|
71
|
+
else if (ClassCategory.isType(type.category, ClassCategory.Pointer)) {
|
|
72
|
+
if (!(val instanceof Pointer)) {
|
|
73
|
+
throw new Error(`Error serialising value! Expected ${info.ownerRepl.opts.dataTypeName}.${conf.name} ${describeObject(val)} to be a pointer!`);
|
|
74
|
+
}
|
|
75
|
+
if (val.ref === null || typeof val.ref === "undefined") {
|
|
76
|
+
return ["Primitive", null];
|
|
77
|
+
}
|
|
78
|
+
return [...val.ref];
|
|
79
|
+
}
|
|
80
|
+
else if (ClassCategory.isType(type.category, ClassCategory.Custom)) {
|
|
81
|
+
return Referencer.Reference(val, type);
|
|
82
|
+
}
|
|
83
|
+
else if (ClassCategory.isType(type.category, ClassCategory.Struct)) {
|
|
84
|
+
return Serialiser.Serialise(val);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`${info.ownerRepl.opts.dataTypeName}.${conf.name} is not a valid type for serialisation.`);
|
|
90
|
+
}
|
|
91
|
+
Serialiser.SerialiseSingle = SerialiseSingle;
|
|
92
|
+
function DeserialiseSingle(info, conf, target, val, mod) {
|
|
93
|
+
for (let typeInfo of conf.serialisation.types) {
|
|
94
|
+
if (!PropertyTypes.isType(typeInfo.modifiers, mod)) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
for (let type of typeInfo.types) {
|
|
98
|
+
if (val[0] === "Primitive") {
|
|
99
|
+
if (!isPrimitiveType(type)) {
|
|
100
|
+
if (typeof val[1] === "undefined" || val[1] == null && ClassCategory.isType(type.category, ClassCategory.Pointer)) {
|
|
101
|
+
return new Pointer(null);
|
|
102
|
+
}
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
//JSON.serialise turns undefined into null.
|
|
106
|
+
if (type === undefined && val[1] === null) {
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
if (!ValueIsPrimitiveType(type, val[1])) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
return val[1];
|
|
113
|
+
}
|
|
114
|
+
if (isPrimitiveType(type)) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
let replType = ReplicableRegistry.__GetReplicableForDataName(val[0]);
|
|
118
|
+
if (replType != type && !type.isChildTypeOfThisType(replType)) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (!PropertyTypes.isType(typeInfo.modifiers, PropertyTypes.ForceInline)) {
|
|
122
|
+
if (PropertyTypes.isType(typeInfo.modifiers, PropertyTypes.Serialised)) {
|
|
123
|
+
return val;
|
|
124
|
+
}
|
|
125
|
+
else if (PropertyTypes.isType(typeInfo.modifiers, PropertyTypes.Definition)) {
|
|
126
|
+
return val[1];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (!type.isChildTypeOfThisType(replType)) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (ClassCategory.isType(type.category, ClassCategory.Inlined) || PropertyTypes.isType(typeInfo.modifiers, PropertyTypes.ForceInline)) {
|
|
133
|
+
if (target && target instanceof Pointer && target.valOrNull) {
|
|
134
|
+
return new Pointer(Serialiser.Deserialise(target.val, val));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
return new Pointer(Constructor.Construct(replType, info.source, info.owner, val));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (ClassCategory.isType(type.category, ClassCategory.Pointer)) {
|
|
141
|
+
return new Pointer(Referencer.Dereference(val));
|
|
142
|
+
}
|
|
143
|
+
else if (ClassCategory.isType(type.category, ClassCategory.Custom)) {
|
|
144
|
+
return Referencer.Dereference(val, type);
|
|
145
|
+
}
|
|
146
|
+
else if (ClassCategory.isType(type.category, ClassCategory.Struct)) {
|
|
147
|
+
if (target) {
|
|
148
|
+
return Serialiser.Deserialise(target, val);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
//Since type is a struct, we can just construct a new entry without worries.
|
|
152
|
+
return Constructor.Construct(replType, info.source, info.owner, val);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
throw new Error(`${info.ownerRepl.opts.dataTypeName}.${conf.name} has an invalid value in it's serialised data.`);
|
|
158
|
+
}
|
|
159
|
+
Serialiser.DeserialiseSingle = DeserialiseSingle;
|
|
160
|
+
function SerialiseProp(info, conf, val) {
|
|
161
|
+
if (conf.expressionForProperty && val instanceof Expression) {
|
|
162
|
+
return ["Expression", val.expression.rawText];
|
|
163
|
+
}
|
|
164
|
+
if (PropertyTypes.isType(conf.serialisation.possibleModifiers, PropertyTypes.Dictionary)
|
|
165
|
+
&& typeof val === "object" && val !== null && val.__proto__ === Object.prototype && !val[TypeSymbol]) {
|
|
166
|
+
let result = ["Dict", {}];
|
|
167
|
+
for (let [k, v] of Object.entries(val)) {
|
|
168
|
+
result[1][k] = Serialiser.SerialiseSingle(info, conf, v, PropertyTypes.Dictionary);
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
else if (PropertyTypes.isType(conf.serialisation.possibleModifiers, PropertyTypes.Map)
|
|
173
|
+
&& val instanceof Map) {
|
|
174
|
+
let result = ["Map", {}];
|
|
175
|
+
for (let [k, v] of val.entries()) {
|
|
176
|
+
result[1][k] = Serialiser.SerialiseSingle(info, conf, v, PropertyTypes.Map);
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
else if (PropertyTypes.isType(conf.serialisation.possibleModifiers, PropertyTypes.Array)
|
|
181
|
+
&& Array.isArray(val)) {
|
|
182
|
+
let result = ["Array", []];
|
|
183
|
+
for (let v of val) {
|
|
184
|
+
result[1].push(Serialiser.SerialiseSingle(info, conf, v, PropertyTypes.Array));
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
else if (PropertyTypes.isType(conf.serialisation.possibleModifiers, PropertyTypes.Array2)
|
|
189
|
+
&& Array.isArray(val)) {
|
|
190
|
+
let result = ["Array2", []];
|
|
191
|
+
for (let v of val) {
|
|
192
|
+
let row = [];
|
|
193
|
+
for (let vv of v) {
|
|
194
|
+
row.push(Serialiser.SerialiseSingle(info, conf, vv, PropertyTypes.Array2));
|
|
195
|
+
}
|
|
196
|
+
result[1].push(row);
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
else if (PropertyTypes.isType(conf.serialisation.possibleModifiers, PropertyTypes.Solo)) {
|
|
201
|
+
return Serialiser.SerialiseSingle(info, conf, val, PropertyTypes.Solo);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
Serialiser.SerialiseProp = SerialiseProp;
|
|
205
|
+
function DeserialiseProp(info, conf, target, val) {
|
|
206
|
+
if (val[0] === "Expression") {
|
|
207
|
+
throw new Error(`Deserialising expressions is not implemented currently.`);
|
|
208
|
+
}
|
|
209
|
+
if (val[0] === "Dict") {
|
|
210
|
+
if (!PropertyTypes.isType(conf.serialisation.possibleModifiers, PropertyTypes.Dictionary)) {
|
|
211
|
+
throw new Error(`Property does not allow for dictionary values, but has been serialised as one.`);
|
|
212
|
+
}
|
|
213
|
+
if (!target || (target.__proto__ != Object.prototype))
|
|
214
|
+
target = {};
|
|
215
|
+
for (let [k, v] of Object.entries(val[1])) {
|
|
216
|
+
target[k] = Serialiser.DeserialiseSingle(info, conf, target[k], v, PropertyTypes.Dictionary);
|
|
217
|
+
}
|
|
218
|
+
return target;
|
|
219
|
+
}
|
|
220
|
+
if (val[0] === "Map") {
|
|
221
|
+
if (!PropertyTypes.isType(conf.serialisation.possibleModifiers, PropertyTypes.Map)) {
|
|
222
|
+
throw new Error(`Property does not allow for map values, but has been serialised as one.`);
|
|
223
|
+
}
|
|
224
|
+
if (!target || !(target instanceof Map))
|
|
225
|
+
target = new Map();
|
|
226
|
+
for (let [k, v] of Object.entries(val[1])) {
|
|
227
|
+
target.set(k, Serialiser.DeserialiseSingle(info, conf, target.get(k), v, PropertyTypes.Map));
|
|
228
|
+
}
|
|
229
|
+
return target;
|
|
230
|
+
}
|
|
231
|
+
if (val[0] === "Array") {
|
|
232
|
+
if (!PropertyTypes.isType(conf.serialisation.possibleModifiers, PropertyTypes.Array)) {
|
|
233
|
+
throw new Error(`Property does not allow for array values, but has been serialised as one.`);
|
|
234
|
+
}
|
|
235
|
+
if (!target || !Array.isArray(target))
|
|
236
|
+
target = [];
|
|
237
|
+
for (let [i, v] of val[1].entries()) {
|
|
238
|
+
target[i] = Serialiser.DeserialiseSingle(info, conf, target[i], v, PropertyTypes.Array);
|
|
239
|
+
}
|
|
240
|
+
return target;
|
|
241
|
+
}
|
|
242
|
+
if (val[0] === "Array2") {
|
|
243
|
+
if (!PropertyTypes.isType(conf.serialisation.possibleModifiers, PropertyTypes.Array2)) {
|
|
244
|
+
throw new Error(`Property does not allow for double array values, but has been serialised as one.`);
|
|
245
|
+
}
|
|
246
|
+
if (!target || !Array.isArray(target))
|
|
247
|
+
target = [];
|
|
248
|
+
for (let [i, r] of val[1].entries()) {
|
|
249
|
+
if (!target[i] || !Array.isArray(target[i]))
|
|
250
|
+
target[i] = [];
|
|
251
|
+
for (let [ii, v] of r.entries()) {
|
|
252
|
+
target[i][ii] = Serialiser.DeserialiseSingle(info, conf, target[i][ii], v, PropertyTypes.Array2);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return target;
|
|
256
|
+
}
|
|
257
|
+
return Serialiser.DeserialiseSingle(info, conf, target, val, PropertyTypes.Solo);
|
|
258
|
+
}
|
|
259
|
+
Serialiser.DeserialiseProp = DeserialiseProp;
|
|
260
|
+
function SerialiseRepl(type, source, object) {
|
|
261
|
+
if ("Serialise" in type.classConstructor) {
|
|
262
|
+
return [type.opts.dataTypeName, type.classConstructor.Serialise(object)];
|
|
263
|
+
}
|
|
264
|
+
let serialised = {};
|
|
265
|
+
serialised.version = Versions.MAX;
|
|
266
|
+
let vers = type.finalised_properties.get(Versions.MAX);
|
|
267
|
+
let info = {
|
|
268
|
+
ownerRepl: type,
|
|
269
|
+
source: source,
|
|
270
|
+
owner: object
|
|
271
|
+
};
|
|
272
|
+
for (let name of type.finalised_propertyNames) {
|
|
273
|
+
let def = vers[name];
|
|
274
|
+
if ("removed" in def || "doesntExist" in def)
|
|
275
|
+
continue;
|
|
276
|
+
if (!def.serialisation.present)
|
|
277
|
+
continue;
|
|
278
|
+
serialised[name] = Serialiser.SerialiseProp(info, def, object[name]);
|
|
279
|
+
}
|
|
280
|
+
return [type.opts.dataTypeName, serialised];
|
|
281
|
+
}
|
|
282
|
+
Serialiser.SerialiseRepl = SerialiseRepl;
|
|
283
|
+
function DeserialiseRepl(type, source, target, serialised, skipCustomDeserialiser = false) {
|
|
284
|
+
if ("Deserialise" in type.classConstructor && !skipCustomDeserialiser) {
|
|
285
|
+
//Mark initialised afterwards just in case Deserialise wants to use Load.
|
|
286
|
+
target = type.classConstructor.Deserialise(serialised[1], target);
|
|
287
|
+
Loader.MarkInitialised(target);
|
|
288
|
+
return target;
|
|
289
|
+
}
|
|
290
|
+
Loader.MarkInitialised(target);
|
|
291
|
+
let sObject = serialised[1];
|
|
292
|
+
let setting = {
|
|
293
|
+
source, owner: target
|
|
294
|
+
};
|
|
295
|
+
let vers = type.finalised_properties.get(Versions.MAX);
|
|
296
|
+
let info = {
|
|
297
|
+
ownerRepl: type,
|
|
298
|
+
source: setting.source,
|
|
299
|
+
owner: setting.owner
|
|
300
|
+
};
|
|
301
|
+
for (let name of type.finalised_propertyNames) {
|
|
302
|
+
let def = vers[name];
|
|
303
|
+
if ("removed" in def || "doesntExist" in def) {
|
|
304
|
+
if (name in sObject) {
|
|
305
|
+
console.warn(`Property ${type.opts.typescriptTypeName}.${name} has been removed and cannot be loaded.`);
|
|
306
|
+
}
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (def.serialisation.present != true)
|
|
310
|
+
continue;
|
|
311
|
+
let propType = sObject[name][0], propValue = sObject[name][1];
|
|
312
|
+
if (propType === "Expression" && def.expressionForProperty) {
|
|
313
|
+
if (IsPropertyExpression(target, name)) {
|
|
314
|
+
if (Loader.GetExprText(target, name) === propValue) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
Loader.ClearPropertyExpression(target, name);
|
|
318
|
+
}
|
|
319
|
+
let expr = new Expression(propValue, def.expressionForProperty[Versions.MAX]);
|
|
320
|
+
Loader.SetPropertyToExpression(target, name, expr);
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if (!(def.name in sObject)) {
|
|
324
|
+
throw new Error(`Property ${type.opts.typescriptTypeName}.${name} is not present in the serialised data.`);
|
|
325
|
+
}
|
|
326
|
+
if (IsPropertyExpression(target, name)) {
|
|
327
|
+
//TODO: Override local expression with the value from the serialised one (if present - otherwise leave unchanged).
|
|
328
|
+
continue;
|
|
329
|
+
// Loader.ClearPropertyExpression(target, name);
|
|
330
|
+
}
|
|
331
|
+
target[name] = DeserialiseProp(info, def, target[name], sObject[name]);
|
|
332
|
+
}
|
|
333
|
+
return target;
|
|
334
|
+
}
|
|
335
|
+
Serialiser.DeserialiseRepl = DeserialiseRepl;
|
|
336
|
+
function IsSerialisable(object) {
|
|
337
|
+
return !isPrimitiveValue(object) && !!(object[TypeSymbol]);
|
|
338
|
+
}
|
|
339
|
+
Serialiser.IsSerialisable = IsSerialisable;
|
|
340
|
+
function Serialise(object) {
|
|
341
|
+
let typeDef = object[TypeSymbol];
|
|
342
|
+
if (!typeDef) {
|
|
343
|
+
throw new Error(`Tried to serialise non-replicable type! ${describeObject(object)}`);
|
|
344
|
+
}
|
|
345
|
+
let source = { SourceFile: "Serialise Function", Version: Versions.MAX };
|
|
346
|
+
return SerialiseRepl(typeDef, source, object);
|
|
347
|
+
}
|
|
348
|
+
Serialiser.Serialise = Serialise;
|
|
349
|
+
function Deserialise(object, data) {
|
|
350
|
+
if (data[0] === "Primitive") {
|
|
351
|
+
return data[1];
|
|
352
|
+
}
|
|
353
|
+
if (data[0] === "Expression" || data[0] === "Dict" || data[0] === "Map" || data[0] === "Array" || data[0] === "Array2") {
|
|
354
|
+
throw new Error(`Cannot deserialise data of type ${data[0]}.`);
|
|
355
|
+
}
|
|
356
|
+
let sTypeDef = __GetReplicableForDataName(data[0]);
|
|
357
|
+
let typeDef = object[TypeSymbol];
|
|
358
|
+
if (sTypeDef != typeDef) {
|
|
359
|
+
throw new Error(`Cannot deserialise data of ${data[0]} into ${typeDef.classConstructor.name}.`);
|
|
360
|
+
}
|
|
361
|
+
let source = { SourceFile: "Deserialise Function", Version: Versions.MAX };
|
|
362
|
+
return DeserialiseRepl(typeDef, source, object, data);
|
|
363
|
+
}
|
|
364
|
+
Serialiser.Deserialise = Deserialise;
|
|
365
|
+
})(Serialiser || (Serialiser = {}));
|
|
366
|
+
__PrivateConstructorSetup.RegisterDeserialiser(Serialiser.Deserialise);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PropertyTypes } from "../Constants/SerialisationTypes.js";
|
|
2
|
+
import { Referencer } from "./Reference.js";
|
|
3
|
+
import type { PropertyDefinition, ReplicableClass } from "../Tracking/Class.js";
|
|
4
|
+
import { Expression } from "../Expressions/Expression.js";
|
|
5
|
+
import { EvaluationChain } from "../Expressions/EvaluatorChain.js";
|
|
6
|
+
import { EvaluationString } from "../Expressions/EvaluatorString.js";
|
|
7
|
+
import { Versions } from "../Constants/Versions.js";
|
|
8
|
+
import { ExpressionConfiguration } from "../Expressions/EvaluatorSteps.js";
|
|
9
|
+
import { PropertyConfiguration } from "../Tracking/Property.js";
|
|
10
|
+
export declare namespace Utils {
|
|
11
|
+
namespace PrintUtils {
|
|
12
|
+
/**
|
|
13
|
+
* Turns a given config into a modifier string ignoring the types, for easier comparison and error reporting.
|
|
14
|
+
* @param config The configuration to get the visual aid for.
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
function ConfigVisualModifierAid(config: ExpressionConfiguration): string;
|
|
18
|
+
function DefVisualModifierAid(def: PropertyDefinition): string;
|
|
19
|
+
function CategoryVisualModifierAid(category: PropertyTypes): string;
|
|
20
|
+
function ReplPrimOrRawToName(val: any): string;
|
|
21
|
+
function ValVisualAidBestGuess(val: any): string;
|
|
22
|
+
}
|
|
23
|
+
namespace ExpressionUtils {
|
|
24
|
+
function MakePropExpressionConfig(version: Versions | string, def: PropertyDefinition, startType?: any): ExpressionConfiguration | undefined;
|
|
25
|
+
function DoesExpressionMatchPropType(expr: Expression | EvaluationChain | EvaluationString, propType: PropertyConfiguration): boolean;
|
|
26
|
+
}
|
|
27
|
+
namespace CompareUtils {
|
|
28
|
+
function CompareValWithSerialisedVal(val: any, serialised: any, debuginfo: string): boolean;
|
|
29
|
+
function CompareRepl(type: ReplicableClass, object: any, serialised: any): boolean;
|
|
30
|
+
function Compare<T>(a: T, b: [string, any]): boolean;
|
|
31
|
+
function CompareReferences(a: Referencer.Reference, b: Referencer.Reference): boolean;
|
|
32
|
+
}
|
|
33
|
+
}
|