@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,534 @@
|
|
|
1
|
+
import { afterAll, beforeAll, describe, expect, test } from "vitest";
|
|
2
|
+
import { Expression, PropertyTypes, ValueIsPrimitiveType, Versions } from "../../Main.js";
|
|
3
|
+
import { ReplicableRegistry } from "../../Constants/ReplicableRegistry.js";
|
|
4
|
+
import { Utils } from "../Utils.js";
|
|
5
|
+
import { BikPath } from "@bikky/path";
|
|
6
|
+
import { ExpressionScopes } from "../../Expressions/TypeRegistry/Registry.js";
|
|
7
|
+
import { ModLoader } from "../../../ModLoader.js";
|
|
8
|
+
import { Pointer } from "../Reference.js";
|
|
9
|
+
import { TestPropertyDecorators } from "./Examples.js";
|
|
10
|
+
//TODO: Test whichever utils function returns if a property should be loaded or not returns true for computed + default.
|
|
11
|
+
describe("Replicable Utils", async () => {
|
|
12
|
+
const TransformersBasicClass = TestPropertyDecorators.TransformersBasicClass;
|
|
13
|
+
const TransformersTheLotClass = TestPropertyDecorators.TransformersTheLotClass;
|
|
14
|
+
const TransformersBasicStruct = TestPropertyDecorators.TransformersBasicStruct;
|
|
15
|
+
const TestRepl = ReplicableRegistry.__GetReplicableForDataName(TransformersTheLotClass.name);
|
|
16
|
+
const TestPtrRepl = ReplicableRegistry.__GetReplicableForDataName(TransformersBasicClass.name);
|
|
17
|
+
const TestStructRepl = ReplicableRegistry.__GetReplicableForDataName(TransformersBasicStruct.name);
|
|
18
|
+
describe("ValueIsPrimitiveType", async () => {
|
|
19
|
+
test("Should return true if string is String", async () => {
|
|
20
|
+
let result = ValueIsPrimitiveType(String, "test");
|
|
21
|
+
expect(result).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
test("Should return false if number is not String", async () => {
|
|
24
|
+
let result = ValueIsPrimitiveType(String, 1);
|
|
25
|
+
expect(result).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
test("Should return true if number is Number", async () => {
|
|
28
|
+
let result = ValueIsPrimitiveType(Number, 1);
|
|
29
|
+
expect(result).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
test("Should return false if string is not Number", async () => {
|
|
32
|
+
let result = ValueIsPrimitiveType(Number, "test");
|
|
33
|
+
expect(result).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
test("Should return true if boolean is Boolean", async () => {
|
|
36
|
+
let result = ValueIsPrimitiveType(Boolean, true);
|
|
37
|
+
expect(result).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
test("Should return false if string is not Boolean", async () => {
|
|
40
|
+
let result = ValueIsPrimitiveType(Boolean, "test");
|
|
41
|
+
expect(result).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
test("Should return true if undefined is undefined", async () => {
|
|
44
|
+
let result = ValueIsPrimitiveType(undefined, undefined);
|
|
45
|
+
expect(result).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
test("Should return false if string is not undefined", async () => {
|
|
48
|
+
let result = ValueIsPrimitiveType(undefined, "test");
|
|
49
|
+
expect(result).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
test("Should return true if null is null", async () => {
|
|
52
|
+
let result = ValueIsPrimitiveType(null, null);
|
|
53
|
+
expect(result).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
test("Should return false if string is not null", async () => {
|
|
56
|
+
let result = ValueIsPrimitiveType(null, "test");
|
|
57
|
+
expect(result).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe("ReplClass' PropertyDefinition", async () => {
|
|
61
|
+
const defaultExpressionConfig = {
|
|
62
|
+
cacheable: false,
|
|
63
|
+
duringLoad: false,
|
|
64
|
+
outputArray: 0,
|
|
65
|
+
outputMap: false,
|
|
66
|
+
outputDict: false,
|
|
67
|
+
outputTypes: [String],
|
|
68
|
+
startType: TransformersTheLotClass,
|
|
69
|
+
version: Versions.v1_0_0
|
|
70
|
+
};
|
|
71
|
+
test(" 1. Assignable types for String is correct.", async () => {
|
|
72
|
+
let def = TestRepl.getPropDefinition(Versions.v1_0_0, "val");
|
|
73
|
+
expect(def).toEqual({
|
|
74
|
+
name: "val",
|
|
75
|
+
load: {
|
|
76
|
+
default: undefined,
|
|
77
|
+
name: "Val",
|
|
78
|
+
possibleModifiers: PropertyTypes.Solo,
|
|
79
|
+
present: true,
|
|
80
|
+
skipLoad: false,
|
|
81
|
+
// Expression is default unless expression:false.
|
|
82
|
+
types: [{ types: [String], sortIndex: "string", modifiers: PropertyTypes.Solo | PropertyTypes.Expression }]
|
|
83
|
+
},
|
|
84
|
+
serialisation: {
|
|
85
|
+
present: true,
|
|
86
|
+
inline: undefined,
|
|
87
|
+
possibleModifiers: PropertyTypes.Solo,
|
|
88
|
+
types: [{ types: [String], sortIndex: "string", modifiers: PropertyTypes.Solo | PropertyTypes.Expression }]
|
|
89
|
+
},
|
|
90
|
+
expressionForKey: undefined,
|
|
91
|
+
expressionForProperty: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [String] }) },
|
|
92
|
+
expressionForValue: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [String] }) },
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
test(" 2. Assignable types for Number is correct.", async () => {
|
|
96
|
+
let def = TestRepl.getPropDefinition(Versions.v1_0_0, "val2");
|
|
97
|
+
expect(def).toEqual({
|
|
98
|
+
name: "val2",
|
|
99
|
+
load: {
|
|
100
|
+
default: undefined,
|
|
101
|
+
name: "Val2",
|
|
102
|
+
possibleModifiers: PropertyTypes.Solo,
|
|
103
|
+
present: "optional",
|
|
104
|
+
skipLoad: false,
|
|
105
|
+
types: [{ types: [Number], sortIndex: "number", modifiers: PropertyTypes.Solo | PropertyTypes.Expression }]
|
|
106
|
+
},
|
|
107
|
+
serialisation: {
|
|
108
|
+
present: true,
|
|
109
|
+
inline: undefined,
|
|
110
|
+
possibleModifiers: PropertyTypes.Solo,
|
|
111
|
+
types: [
|
|
112
|
+
{ types: [Number], sortIndex: "number", modifiers: PropertyTypes.Solo | PropertyTypes.Expression },
|
|
113
|
+
{ types: [undefined], sortIndex: "undefined", modifiers: PropertyTypes.Solo | PropertyTypes.Expression },
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
expressionForKey: undefined,
|
|
117
|
+
expressionForProperty: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [Number] }) },
|
|
118
|
+
expressionForValue: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [Number] }) },
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
test(" 3. Assignable types for Map is correct.", async () => {
|
|
122
|
+
let def = TestRepl.getPropDefinition(Versions.v1_0_0, "val3");
|
|
123
|
+
expect(def).toEqual({
|
|
124
|
+
name: "val3",
|
|
125
|
+
load: {
|
|
126
|
+
default: undefined,
|
|
127
|
+
name: "Val3",
|
|
128
|
+
possibleModifiers: PropertyTypes.Map,
|
|
129
|
+
present: "optional",
|
|
130
|
+
skipLoad: false,
|
|
131
|
+
types: [{ types: [Number], keyType: [String], sortIndex: "number", modifiers: PropertyTypes.Map | PropertyTypes.Expression }]
|
|
132
|
+
},
|
|
133
|
+
serialisation: {
|
|
134
|
+
inline: undefined,
|
|
135
|
+
possibleModifiers: PropertyTypes.Map | PropertyTypes.Solo, //solo for undefined
|
|
136
|
+
present: true,
|
|
137
|
+
types: [{ types: [Number], keyType: [String], sortIndex: "number", modifiers: PropertyTypes.Map | PropertyTypes.Expression },
|
|
138
|
+
{ types: [undefined], modifiers: PropertyTypes.Solo | PropertyTypes.Expression, sortIndex: "undefined" }]
|
|
139
|
+
},
|
|
140
|
+
expressionForKey: undefined,
|
|
141
|
+
expressionForProperty: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [Number], outputMap: true }) },
|
|
142
|
+
expressionForValue: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [Number] }) },
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
test(" 4. Assignable types for Dictionary is correct.", async () => {
|
|
146
|
+
let def = TestRepl.getPropDefinition(Versions.v1_0_0, "val4");
|
|
147
|
+
expect(def).toEqual({
|
|
148
|
+
name: "val4",
|
|
149
|
+
load: {
|
|
150
|
+
default: undefined,
|
|
151
|
+
name: "Val4",
|
|
152
|
+
possibleModifiers: PropertyTypes.Dictionary,
|
|
153
|
+
present: "optional",
|
|
154
|
+
skipLoad: false,
|
|
155
|
+
types: [{ types: [String], sortIndex: "string", keyType: [Number], restrictedTo: [1, 2, 3], modifiers: PropertyTypes.Dictionary | PropertyTypes.Expression }]
|
|
156
|
+
},
|
|
157
|
+
serialisation: {
|
|
158
|
+
inline: undefined,
|
|
159
|
+
possibleModifiers: PropertyTypes.Dictionary | PropertyTypes.Solo, //solo for undefined
|
|
160
|
+
present: true,
|
|
161
|
+
types: [{ types: [String], sortIndex: "string", keyType: [Number], restrictedTo: [1, 2, 3], modifiers: PropertyTypes.Dictionary | PropertyTypes.Expression },
|
|
162
|
+
{ types: [undefined], modifiers: PropertyTypes.Solo | PropertyTypes.Expression, sortIndex: "undefined" }]
|
|
163
|
+
},
|
|
164
|
+
expressionForKey: undefined,
|
|
165
|
+
expressionForProperty: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [String], outputDict: true }) },
|
|
166
|
+
expressionForValue: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [String] }) },
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
test(" 5. Assignable types for Array is correct.", async () => {
|
|
170
|
+
let def = TestRepl.getPropDefinition(Versions.v1_0_0, "val5");
|
|
171
|
+
expect(def).toEqual({
|
|
172
|
+
name: "val5",
|
|
173
|
+
load: {
|
|
174
|
+
default: undefined,
|
|
175
|
+
name: "Val5",
|
|
176
|
+
possibleModifiers: PropertyTypes.Array,
|
|
177
|
+
present: true,
|
|
178
|
+
skipLoad: false,
|
|
179
|
+
types: [{ types: [String], sortIndex: "string", modifiers: PropertyTypes.Array | PropertyTypes.Expression }]
|
|
180
|
+
},
|
|
181
|
+
serialisation: {
|
|
182
|
+
inline: undefined,
|
|
183
|
+
possibleModifiers: PropertyTypes.Array,
|
|
184
|
+
present: true,
|
|
185
|
+
types: [{ types: [String], sortIndex: "string", modifiers: PropertyTypes.Array | PropertyTypes.Expression }]
|
|
186
|
+
},
|
|
187
|
+
expressionForKey: undefined,
|
|
188
|
+
expressionForProperty: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [String], outputArray: 1 }) },
|
|
189
|
+
expressionForValue: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [String] }) },
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
test(" 6. Assignable types for Array2 is correct.", async () => {
|
|
193
|
+
let def = TestRepl.getPropDefinition(Versions.v1_0_0, "val6");
|
|
194
|
+
expect(def).toEqual({
|
|
195
|
+
name: "val6",
|
|
196
|
+
load: {
|
|
197
|
+
default: undefined,
|
|
198
|
+
name: "Val6",
|
|
199
|
+
possibleModifiers: PropertyTypes.Array2,
|
|
200
|
+
present: true,
|
|
201
|
+
skipLoad: false,
|
|
202
|
+
types: [{ types: [Number], sortIndex: "number", modifiers: PropertyTypes.Array2 | PropertyTypes.Expression }]
|
|
203
|
+
},
|
|
204
|
+
serialisation: {
|
|
205
|
+
inline: undefined,
|
|
206
|
+
possibleModifiers: PropertyTypes.Array2,
|
|
207
|
+
present: true,
|
|
208
|
+
types: [{ types: [Number], sortIndex: "number", modifiers: PropertyTypes.Array2 | PropertyTypes.Expression }]
|
|
209
|
+
},
|
|
210
|
+
expressionForKey: undefined,
|
|
211
|
+
expressionForProperty: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [Number], outputArray: 2 }) },
|
|
212
|
+
expressionForValue: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [Number] }) },
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
test(" 7. Assignable types for Struct is correct.", async () => {
|
|
216
|
+
let def = TestRepl.getPropDefinition(Versions.v1_0_0, "val7");
|
|
217
|
+
expect(def).toEqual({
|
|
218
|
+
name: "val7",
|
|
219
|
+
load: {
|
|
220
|
+
default: undefined,
|
|
221
|
+
name: "Val7",
|
|
222
|
+
possibleModifiers: PropertyTypes.Solo,
|
|
223
|
+
present: true,
|
|
224
|
+
skipLoad: false,
|
|
225
|
+
types: [{ types: [TestStructRepl], sortIndex: TestStructRepl.opts.typescriptTypeName, modifiers: PropertyTypes.Solo | PropertyTypes.Expression }]
|
|
226
|
+
},
|
|
227
|
+
serialisation: {
|
|
228
|
+
inline: undefined,
|
|
229
|
+
possibleModifiers: PropertyTypes.Solo,
|
|
230
|
+
present: true,
|
|
231
|
+
types: [{ types: [TestStructRepl], sortIndex: TestStructRepl.opts.typescriptTypeName, modifiers: PropertyTypes.Solo | PropertyTypes.Expression }]
|
|
232
|
+
},
|
|
233
|
+
expressionForKey: undefined,
|
|
234
|
+
expressionForProperty: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [TestStructRepl.opts.typescriptTypeName] }) },
|
|
235
|
+
expressionForValue: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [TestStructRepl.opts.typescriptTypeName] }) },
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
test(" 8. Assignable types for inlined class is correct.", async () => {
|
|
239
|
+
let def = TestRepl.getPropDefinition(Versions.v1_0_0, "val9");
|
|
240
|
+
expect(def).toEqual({
|
|
241
|
+
name: "val9",
|
|
242
|
+
load: {
|
|
243
|
+
default: undefined,
|
|
244
|
+
name: "Val9",
|
|
245
|
+
possibleModifiers: PropertyTypes.Solo,
|
|
246
|
+
present: true,
|
|
247
|
+
skipLoad: false,
|
|
248
|
+
types: [{ types: [TestPtrRepl], sortIndex: TestPtrRepl.opts.typescriptTypeName, modifiers: PropertyTypes.Solo | PropertyTypes.Expression }]
|
|
249
|
+
},
|
|
250
|
+
serialisation: {
|
|
251
|
+
inline: true,
|
|
252
|
+
possibleModifiers: PropertyTypes.Solo,
|
|
253
|
+
present: true,
|
|
254
|
+
types: [{ types: [TestPtrRepl], sortIndex: TestPtrRepl.opts.typescriptTypeName, modifiers: PropertyTypes.Solo | PropertyTypes.Expression | PropertyTypes.ForceInline }]
|
|
255
|
+
},
|
|
256
|
+
expressionForKey: undefined,
|
|
257
|
+
expressionForProperty: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [TestPtrRepl.opts.typescriptTypeName] }) },
|
|
258
|
+
expressionForValue: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [TestPtrRepl.opts.typescriptTypeName] }) },
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
test(" 9. Assignable types for not inlined class is correct.", async () => {
|
|
262
|
+
let def = TestRepl.getPropDefinition(Versions.v1_0_0, "val10");
|
|
263
|
+
expect(def).toEqual({
|
|
264
|
+
name: "val10",
|
|
265
|
+
load: {
|
|
266
|
+
default: undefined,
|
|
267
|
+
name: "Val10",
|
|
268
|
+
possibleModifiers: PropertyTypes.Solo,
|
|
269
|
+
present: true,
|
|
270
|
+
skipLoad: false,
|
|
271
|
+
types: [{ types: [TestPtrRepl], sortIndex: TestPtrRepl.opts.typescriptTypeName, modifiers: PropertyTypes.Solo | PropertyTypes.Expression }]
|
|
272
|
+
},
|
|
273
|
+
serialisation: {
|
|
274
|
+
inline: undefined,
|
|
275
|
+
possibleModifiers: PropertyTypes.Solo,
|
|
276
|
+
present: true,
|
|
277
|
+
types: [{ types: [TestPtrRepl], sortIndex: TestPtrRepl.opts.typescriptTypeName, modifiers: PropertyTypes.Solo | PropertyTypes.Expression }]
|
|
278
|
+
},
|
|
279
|
+
expressionForKey: undefined,
|
|
280
|
+
expressionForProperty: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [TestPtrRepl.opts.typescriptTypeName] }) },
|
|
281
|
+
expressionForValue: { [Versions.v1_0_0]: Object.assign(Object.assign({}, defaultExpressionConfig), { outputTypes: [TestPtrRepl.opts.typescriptTypeName] }) },
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
describe("GetPropExpressionConfig", async () => {
|
|
286
|
+
beforeAll(() => {
|
|
287
|
+
Expression.setCurrentStartScopeType(TransformersTheLotClass.name);
|
|
288
|
+
});
|
|
289
|
+
test.skip("Should return correct expression config for String.", async () => {
|
|
290
|
+
let def = TestRepl.getPropDefinition(Versions.v1_0_0, "val");
|
|
291
|
+
let result = Utils.ExpressionUtils.MakePropExpressionConfig(Versions.v1_0_0, def);
|
|
292
|
+
expect(result).toEqual({
|
|
293
|
+
cacheable: false,
|
|
294
|
+
duringLoad: false,
|
|
295
|
+
outputArray: 0,
|
|
296
|
+
outputMap: false,
|
|
297
|
+
outputDict: false,
|
|
298
|
+
outputTypes: [String],
|
|
299
|
+
startType: TransformersTheLotClass.name,
|
|
300
|
+
version: Versions.v1_0_0
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
test("Should return multiple types if provided multiple types", async () => {
|
|
304
|
+
let def = {
|
|
305
|
+
type: [{ type: [String, Number], array: true }],
|
|
306
|
+
property: "val",
|
|
307
|
+
version: Versions.v1_0_0,
|
|
308
|
+
dataName: "Val",
|
|
309
|
+
};
|
|
310
|
+
let result = Utils.ExpressionUtils.MakePropExpressionConfig(Versions.v1_0_0, def);
|
|
311
|
+
expect(result).toEqual({
|
|
312
|
+
cacheable: false,
|
|
313
|
+
duringLoad: false,
|
|
314
|
+
outputArray: 1,
|
|
315
|
+
outputMap: false,
|
|
316
|
+
outputDict: false,
|
|
317
|
+
outputTypes: [String, Number],
|
|
318
|
+
startType: TransformersTheLotClass.name,
|
|
319
|
+
version: Versions.v1_0_0
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
test("Should complain if given incompatible array types", async () => {
|
|
323
|
+
let def = {
|
|
324
|
+
type: [{ type: [String], array: true }, { type: [Number] }],
|
|
325
|
+
property: "val",
|
|
326
|
+
version: Versions.v1_0_0,
|
|
327
|
+
dataName: "Val",
|
|
328
|
+
};
|
|
329
|
+
expect(() => Utils.ExpressionUtils.MakePropExpressionConfig(Versions.v1_0_0, def))
|
|
330
|
+
.toThrow("Error, val has inconsistent type categories (array & not array, etc).\nExpressions don't support this currently.");
|
|
331
|
+
});
|
|
332
|
+
test("Should complain if given incompatible map types", async () => {
|
|
333
|
+
let def = {
|
|
334
|
+
type: [{ type: [String], mapKey: String }, { type: [Number] }],
|
|
335
|
+
property: "val",
|
|
336
|
+
version: Versions.v1_0_0,
|
|
337
|
+
dataName: "Val",
|
|
338
|
+
};
|
|
339
|
+
expect(() => Utils.ExpressionUtils.MakePropExpressionConfig(Versions.v1_0_0, def))
|
|
340
|
+
.toThrow("Error, val has inconsistent type categories (map & not map, etc).\nExpressions don't support this currently.");
|
|
341
|
+
});
|
|
342
|
+
test("Should return array type if given all array types", async () => {
|
|
343
|
+
let def = {
|
|
344
|
+
type: [{ type: [String], array: true }, { type: [Number], array: true }],
|
|
345
|
+
property: "val",
|
|
346
|
+
version: Versions.v1_0_0,
|
|
347
|
+
dataName: "Val",
|
|
348
|
+
};
|
|
349
|
+
let result = Utils.ExpressionUtils.MakePropExpressionConfig(Versions.v1_0_0, def);
|
|
350
|
+
expect(result).toEqual({
|
|
351
|
+
cacheable: false,
|
|
352
|
+
duringLoad: false,
|
|
353
|
+
outputArray: 1,
|
|
354
|
+
outputMap: false,
|
|
355
|
+
outputDict: false,
|
|
356
|
+
outputTypes: [String, Number],
|
|
357
|
+
startType: TransformersTheLotClass.name,
|
|
358
|
+
version: Versions.v1_0_0
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
test("Should return map type if given all map types", async () => {
|
|
362
|
+
let def = {
|
|
363
|
+
type: [{ type: [String], mapKey: String }, { type: [Number], mapKey: String }],
|
|
364
|
+
property: "val",
|
|
365
|
+
version: Versions.v1_0_0,
|
|
366
|
+
dataName: "Val",
|
|
367
|
+
};
|
|
368
|
+
let result = Utils.ExpressionUtils.MakePropExpressionConfig(Versions.v1_0_0, def);
|
|
369
|
+
expect(result).toEqual({
|
|
370
|
+
cacheable: false,
|
|
371
|
+
duringLoad: false,
|
|
372
|
+
outputArray: 0,
|
|
373
|
+
outputMap: true,
|
|
374
|
+
outputDict: false,
|
|
375
|
+
outputTypes: [String, Number],
|
|
376
|
+
startType: TransformersTheLotClass.name,
|
|
377
|
+
version: Versions.v1_0_0
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
test("Should be fine if given map types with different key types", async () => {
|
|
381
|
+
let def = {
|
|
382
|
+
type: [{ type: [String], mapKey: String }, { type: [Number], mapKey: Number }],
|
|
383
|
+
property: "val",
|
|
384
|
+
version: Versions.v1_0_0,
|
|
385
|
+
dataName: "Val",
|
|
386
|
+
};
|
|
387
|
+
let result = Utils.ExpressionUtils.MakePropExpressionConfig(Versions.v1_0_0, def);
|
|
388
|
+
expect(result).toEqual({
|
|
389
|
+
cacheable: false,
|
|
390
|
+
duringLoad: false,
|
|
391
|
+
outputArray: 0,
|
|
392
|
+
outputMap: true,
|
|
393
|
+
outputDict: false,
|
|
394
|
+
outputTypes: [String, Number],
|
|
395
|
+
startType: TransformersTheLotClass.name,
|
|
396
|
+
version: Versions.v1_0_0
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
afterAll(() => {
|
|
400
|
+
Expression.setCurrentStartScopeType(null);
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
describe.sequential("DoesExpressionMatchPropType", async () => {
|
|
404
|
+
ExpressionScopes.addLocalVariable(TransformersTheLotClass.name, "thisEntity", [TransformersTheLotClass]);
|
|
405
|
+
ExpressionScopes.setLocalScope(TransformersTheLotClass.name, { thisEntity: new TransformersTheLotClass() });
|
|
406
|
+
Expression.setCurrentStartScopeType(TransformersTheLotClass.name);
|
|
407
|
+
await ModLoader.DoLoad();
|
|
408
|
+
let def = TestRepl.getPropDefinition(Versions.v1_0_0, "val2");
|
|
409
|
+
let config = def.expressionForProperty[Versions.v1_0_0];
|
|
410
|
+
test.sequential("Prop config should be valid", () => {
|
|
411
|
+
expect(config).not.toBeUndefined();
|
|
412
|
+
});
|
|
413
|
+
let strEvul;
|
|
414
|
+
test.sequential("Expression evaluates correctly", () => {
|
|
415
|
+
strEvul = Expression.Parse("@{thisEntity.Val2}", BikPath.getCurrentFilepath(), config);
|
|
416
|
+
});
|
|
417
|
+
test.sequential("Should return true if expression matches prop type.", async () => {
|
|
418
|
+
let result = Utils.ExpressionUtils.DoesExpressionMatchPropType(strEvul, def);
|
|
419
|
+
expect(result).toBe(true);
|
|
420
|
+
});
|
|
421
|
+
test.sequential("Should return false if expression does not match prop type.", async () => {
|
|
422
|
+
let val1def = TestRepl.getPropDefinition(Versions.v1_0_0, "val");
|
|
423
|
+
let result = Utils.ExpressionUtils.DoesExpressionMatchPropType(strEvul, val1def);
|
|
424
|
+
expect(result).toBe(false);
|
|
425
|
+
});
|
|
426
|
+
test.sequential("Should return false if expression does not match prop type.", async () => {
|
|
427
|
+
let val2def = TestRepl.getPropDefinition(Versions.v1_0_0, "val2");
|
|
428
|
+
let evalStr = Expression.Parse("@{thisEntity.Val} is a string", BikPath.getCurrentFilepath(), Object.assign(Object.assign({}, config), { outputTypes: [String] }));
|
|
429
|
+
let result = Utils.ExpressionUtils.DoesExpressionMatchPropType(evalStr, val2def);
|
|
430
|
+
expect(result).toBe(false);
|
|
431
|
+
});
|
|
432
|
+
afterAll(() => {
|
|
433
|
+
Expression.setCurrentStartScopeType(null);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
describe("CompareProp", async () => {
|
|
437
|
+
test("Compare primitive values", async () => {
|
|
438
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal("test", "test", "val")).toBe(true);
|
|
439
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal("test", "test2", "val")).toBe(false);
|
|
440
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(0, 0, "val")).toBe(true);
|
|
441
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(false, false, "val")).toBe(true);
|
|
442
|
+
});
|
|
443
|
+
test("Compare arrays", async () => {
|
|
444
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(["test"], [["Primitive", "test"]], "val5")).toBe(true);
|
|
445
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(["test"], [["Primitive", "test2"]], "val5")).toBe(false);
|
|
446
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(["test", "two"], [["Primitive", "test"]], "val5")).toBe(false);
|
|
447
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(["test", "two"], [["Primitive", "test2"], ["Primitive", "two"]], "val5")).toBe(false);
|
|
448
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(["test", "two"], [["Primitive", "test"], ["Primitive", "two2"]], "val5")).toBe(false);
|
|
449
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(["test", "two"], [["Primitive", "test"], ["Primitive", "two"]], "val5")).toBe(true);
|
|
450
|
+
});
|
|
451
|
+
test("Compare maps", async () => {
|
|
452
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(new Map([["test", 1]]), { "test": ["Primitive", 1] }, "val3")).toBe(true);
|
|
453
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(new Map([["test", 1]]), { "test": ["Primitive", 2] }, "val3")).toBe(false);
|
|
454
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(new Map([["test", 1]]), { "test2": ["Primitive", 1] }, "val3")).toBe(false);
|
|
455
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(new Map([["test", 1], ["two", 2]]), { "test": ["Primitive", 1] }, "val3")).toBe(false);
|
|
456
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(new Map([["test", 1], ["two", 2]]), { "test": ["Primitive", 1], "two": ["Primitive", 2] }, "val3")).toBe(true);
|
|
457
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(new Map([["test", 1], ["two", 2]]), { "test": ["Primitive", 1], "two": ["Primitive", 1] }, "val3")).toBe(false);
|
|
458
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(new Map([["test", 1], ["two", 2]]), { "test": ["Primitive", 2], "two": ["Primitive", 1] }, "val3")).toBe(false);
|
|
459
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(new Map([["test", 1], ["two", 2]]), { "test": ["Primitive", 2], "two": ["Primitive", 2] }, "val3")).toBe(false);
|
|
460
|
+
});
|
|
461
|
+
test("Compare dicts", async () => {
|
|
462
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal({ "test": 1 }, { "test": ["Primitive", 1] }, "val3")).toBe(true);
|
|
463
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal({ "test": 1 }, { "test": ["Primitive", 2] }, "val3")).toBe(false);
|
|
464
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal({ "test": 1 }, { "test2": ["Primitive", 1] }, "val3")).toBe(false);
|
|
465
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal({ "test": 1, "two": 2 }, { "test": ["Primitive", 1] }, "val3")).toBe(false);
|
|
466
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal({ "test": 1, "two": 2 }, { "test": ["Primitive", 1], "two": ["Primitive", 2] }, "val3")).toBe(true);
|
|
467
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal({ "test": 1, "two": 2 }, { "test": ["Primitive", 1], "two": ["Primitive", 1] }, "val3")).toBe(false);
|
|
468
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal({ "test": 1, "two": 2 }, { "test": ["Primitive", 2], "two": ["Primitive", 1] }, "val3")).toBe(false);
|
|
469
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal({ "test": 1, "two": 2 }, { "test": ["Primitive", 2], "two": ["Primitive", 2] }, "val3")).toBe(false);
|
|
470
|
+
});
|
|
471
|
+
test("Compare expressions", async () => {
|
|
472
|
+
let expr = Expression.Parse("@{thisEntity.Val}", BikPath.getCurrentFilepath(), {
|
|
473
|
+
cacheable: false,
|
|
474
|
+
duringLoad: false,
|
|
475
|
+
outputArray: 0,
|
|
476
|
+
outputMap: false,
|
|
477
|
+
outputTypes: [String],
|
|
478
|
+
startType: TransformersTheLotClass.name,
|
|
479
|
+
version: Versions.v1_0_0
|
|
480
|
+
});
|
|
481
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(expr, "test", "val")).toBe(true);
|
|
482
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(expr, "test2", "val")).toBe(true);
|
|
483
|
+
});
|
|
484
|
+
test("Compare pointers", async () => {
|
|
485
|
+
let val = new TransformersBasicClass();
|
|
486
|
+
val.val = "test";
|
|
487
|
+
let ptr = new Pointer(val);
|
|
488
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(ptr, [TransformersBasicClass.name, "test"], "val9")).toBe(true);
|
|
489
|
+
expect(Utils.CompareUtils.CompareValWithSerialisedVal(ptr, ["UnknownClass", "test"], "val9")).toBe(false);
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
describe("CompareRepl and Compare", () => {
|
|
493
|
+
let testPtr = new TransformersBasicClass();
|
|
494
|
+
testPtr.val = "test";
|
|
495
|
+
let objToCompare = new TransformersTheLotClass();
|
|
496
|
+
Object.defineProperties(objToCompare, {
|
|
497
|
+
val: { value: "test" },
|
|
498
|
+
val2: { value: 1 },
|
|
499
|
+
val3: { value: new Map([["test", 1]]) },
|
|
500
|
+
val4: { value: { test: 1 } },
|
|
501
|
+
val5: { value: ["test"] },
|
|
502
|
+
val6: { value: [[1]] },
|
|
503
|
+
val7: { value: new TransformersTheLotClass() },
|
|
504
|
+
val8: { value: "test" },
|
|
505
|
+
val9: { value: new Pointer(testPtr) },
|
|
506
|
+
val10: { value: new Pointer(testPtr) },
|
|
507
|
+
val13: { value: [[1]] },
|
|
508
|
+
val14: { value: 1 }
|
|
509
|
+
});
|
|
510
|
+
let serialisedCorrect = {
|
|
511
|
+
val: ["Primitive", "test"],
|
|
512
|
+
val2: ["Primitive", 1],
|
|
513
|
+
val3: ["Map", { "test": ["Primitive", 1] }],
|
|
514
|
+
val4: ["Dict", { "test": ["Primitive", 1] }],
|
|
515
|
+
val5: ["Array", [["Primitive", "test"]]],
|
|
516
|
+
val6: ["Array", [["Array", [["Primitive", 1]]]]],
|
|
517
|
+
val7: [TransformersBasicStruct.name, { val: ["Primitive", "test"] }],
|
|
518
|
+
val8: ["Primitive", "test"],
|
|
519
|
+
val9: [TransformersBasicClass.name, { val: ["Primitive", "test"] }],
|
|
520
|
+
val10: [TransformersBasicClass.name, "test"],
|
|
521
|
+
val13: ["Array", [["Array", [["Primitive", 1]]]]],
|
|
522
|
+
val14: ["Primitive", 1]
|
|
523
|
+
};
|
|
524
|
+
test("CompareRepl: Should return true if all values are equal", async () => {
|
|
525
|
+
expect(Utils.CompareUtils.CompareRepl(TestRepl, objToCompare, serialisedCorrect)).toBe(true);
|
|
526
|
+
});
|
|
527
|
+
test("Compare: Should return true if all values are equal", async () => {
|
|
528
|
+
expect(Utils.CompareUtils.Compare(objToCompare, [TransformersTheLotClass.name, serialisedCorrect])).toBe(true);
|
|
529
|
+
});
|
|
530
|
+
test("Compare: Should return false if comparing into wrong value", async () => {
|
|
531
|
+
expect(Utils.CompareUtils.Compare(testPtr, [TransformersTheLotClass.name, serialisedCorrect])).toBe(false);
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|