@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,339 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { afterAll, beforeAll, describe, expect, test } from "vitest";
|
|
8
|
+
import { Expression, Property, Struct, Versions } from "../../Main.js";
|
|
9
|
+
import { ReplicableRegistry } from "../../Constants/ReplicableRegistry.js";
|
|
10
|
+
import { Loader } from "../Loader.js";
|
|
11
|
+
import { BikPath } from "@bikky/path";
|
|
12
|
+
import { TestPropertyDecorators } from "./Examples.js";
|
|
13
|
+
import { Pointer } from "../Reference.js";
|
|
14
|
+
import { Constructor } from "../Constructor.js";
|
|
15
|
+
import { fn } from "@vitest/spy";
|
|
16
|
+
var TransformersBasicClass = TestPropertyDecorators.TransformersBasicClass;
|
|
17
|
+
var TransformersBasicStruct = TestPropertyDecorators.TransformersBasicStruct;
|
|
18
|
+
import { ExpressionScopes } from "../../Expressions/TypeRegistry/Registry.js";
|
|
19
|
+
var TransformersTheLotClass = TestPropertyDecorators.TransformersTheLotClass;
|
|
20
|
+
import { Definitions } from "../Definitions.js";
|
|
21
|
+
import { Progress } from "../Progress.js";
|
|
22
|
+
import { ErrorStack } from "../../Constants/Errors.js";
|
|
23
|
+
//TODO: Test that ErrorStack is being built the correct direction.
|
|
24
|
+
//TODO: Test that computed defaults are instantiated to the default value.
|
|
25
|
+
//TODO: Test that class' DataIsType is honoured for creation.
|
|
26
|
+
//TODO: Test that class' DataIsType is used as appropriate.
|
|
27
|
+
//TODO: Check that Create function is used as appropriate.
|
|
28
|
+
//TODO: Test that primitive types and custom objects and arrays can be used to instantiate (custom) classes.
|
|
29
|
+
//TODO: Test that instantiating a class with some already loaded properties works fine.
|
|
30
|
+
//TODO: Test that incoming data is valid before loading.
|
|
31
|
+
//TODO: Test expressions as map keys.
|
|
32
|
+
describe.sequential("Loader", async () => {
|
|
33
|
+
const TestRepl = ReplicableRegistry.__GetReplicableForDataName(TestPropertyDecorators.TransformersTheLotClass.name);
|
|
34
|
+
const Source = {
|
|
35
|
+
SourceFile: BikPath.getCurrentFilepath(),
|
|
36
|
+
Version: Versions.v1_0_0
|
|
37
|
+
};
|
|
38
|
+
ExpressionScopes.addLocalVariable("TransformersTheLotClass", "thisEntity", [TransformersTheLotClass]);
|
|
39
|
+
Expression.setCurrentStartScopeType("TransformersTheLotClass");
|
|
40
|
+
let example = TransformersTheLotClass.MakeExampleObj();
|
|
41
|
+
ExpressionScopes.setLocalScope("TransformersTheLotClass", { thisEntity: example });
|
|
42
|
+
let objData = { root: example, source: Source, rootRepl: TestRepl };
|
|
43
|
+
let def = TestRepl.getPropDefinition(Versions.v1_0_0, "val");
|
|
44
|
+
let propData = { name: "val", dataName: "Val", conf: def };
|
|
45
|
+
let evalChain = Expression.Parse("@{thisEntity.Val}", BikPath.getCurrentFilepath(), def.expressionForProperty[Source.Version]);
|
|
46
|
+
let expr = new Expression(evalChain);
|
|
47
|
+
let def2 = TestRepl.getPropDefinition(Versions.v1_0_0, "val2");
|
|
48
|
+
let prop2Data = { name: "val2", dataName: "Val2", conf: def2 };
|
|
49
|
+
let def3 = TestRepl.getPropDefinition(Versions.v1_0_0, "val3");
|
|
50
|
+
let prop3Data = { name: "val3", dataName: "Val3", conf: def3 };
|
|
51
|
+
let def4 = TestRepl.getPropDefinition(Versions.v1_0_0, "val4");
|
|
52
|
+
let prop4Data = { name: "val4", dataName: "Val4", conf: def4 };
|
|
53
|
+
let def5 = TestRepl.getPropDefinition(Versions.v1_0_0, "val5");
|
|
54
|
+
let prop5Data = { name: "val5", dataName: "Val5", conf: def5 };
|
|
55
|
+
let def6 = TestRepl.getPropDefinition(Versions.v1_0_0, "val6");
|
|
56
|
+
let prop6Data = { name: "val6", dataName: "Val6", conf: def6 };
|
|
57
|
+
let def7 = TestRepl.getPropDefinition(Versions.v1_0_0, "val7");
|
|
58
|
+
let prop7Data = { name: "val7", dataName: "Val7", conf: def7 };
|
|
59
|
+
let def8 = TestRepl.getPropDefinition(Versions.v1_0_0, "val8");
|
|
60
|
+
let prop8Data = { name: "val8", dataName: "Val8", conf: def8 };
|
|
61
|
+
let def9 = TestRepl.getPropDefinition(Versions.v1_0_0, "val9");
|
|
62
|
+
let prop9Data = { name: "val9", dataName: "Val9", conf: def9 };
|
|
63
|
+
let def10 = TestRepl.getPropDefinition(Versions.v1_0_0, "val10");
|
|
64
|
+
let prop10Data = { name: "val10", dataName: "Val10", conf: def10 };
|
|
65
|
+
let def11 = TestRepl.getPropDefinition(Versions.v1_0_0, "val11");
|
|
66
|
+
let prop11Data = { name: "val11", dataName: "Val11", conf: def11 };
|
|
67
|
+
let def13 = TestRepl.getPropDefinition(Versions.v1_0_0, "val13");
|
|
68
|
+
let prop13Data = { name: "val13", dataName: "Val13", conf: def13 };
|
|
69
|
+
let structObj = new TestPropertyDecorators.TransformersBasicStruct();
|
|
70
|
+
structObj.val = "test";
|
|
71
|
+
const StructRepl = ReplicableRegistry.__GetReplicableForDataName(TestPropertyDecorators.TransformersBasicStruct.name);
|
|
72
|
+
let classObj = new TestPropertyDecorators.TransformersBasicClass();
|
|
73
|
+
classObj.val = "test";
|
|
74
|
+
const ClassRepl = ReplicableRegistry.__GetReplicableForDataName(TestPropertyDecorators.TransformersBasicClass.name);
|
|
75
|
+
let ptr = new Pointer(classObj);
|
|
76
|
+
let errors = new ErrorStack(Source);
|
|
77
|
+
describe.sequential("1. LoadSingleValueAsType", () => {
|
|
78
|
+
let original = Constructor.Construct;
|
|
79
|
+
let constructResult = null;
|
|
80
|
+
let constructFoo = fn(() => constructResult);
|
|
81
|
+
beforeAll(() => {
|
|
82
|
+
Constructor.Construct = constructFoo;
|
|
83
|
+
});
|
|
84
|
+
test(" 1. Load a string property.", () => {
|
|
85
|
+
let typeDef = propData.conf.load.types[0];
|
|
86
|
+
expect(Loader.LoadSingleValueAsType(errors, objData, propData, typeDef, typeDef.types[0], JSON.parse(JSON.stringify(TestPropertyDecorators.TransformersTheLotData.Val))))
|
|
87
|
+
.toBe(TestPropertyDecorators.TransformersTheLotData.Val);
|
|
88
|
+
});
|
|
89
|
+
test(" 2. Load a number property.", () => {
|
|
90
|
+
let typeDef = prop2Data.conf.load.types[0];
|
|
91
|
+
expect(Loader.LoadSingleValueAsType(errors, objData, prop2Data, typeDef, typeDef.types[0], JSON.parse(JSON.stringify(TestPropertyDecorators.TransformersTheLotData.Val2))))
|
|
92
|
+
.toBe(TestPropertyDecorators.TransformersTheLotData.Val2);
|
|
93
|
+
});
|
|
94
|
+
//Expressions get aliased down to values in this function.
|
|
95
|
+
test(" 3. Load an expression chain.", () => {
|
|
96
|
+
let typeDef = propData.conf.load.types[0];
|
|
97
|
+
expect(Loader.LoadSingleValueAsType(errors, objData, propData, typeDef, typeDef.types[0], evalChain)).toBe("hello");
|
|
98
|
+
});
|
|
99
|
+
test(" 4. Load an expression.", () => {
|
|
100
|
+
let typeDef = propData.conf.load.types[0];
|
|
101
|
+
expect(Loader.LoadSingleValueAsType(errors, objData, propData, typeDef, typeDef.types[0], expr)).toBe("hello");
|
|
102
|
+
});
|
|
103
|
+
test(" 5. Load a struct property.", () => {
|
|
104
|
+
let typeDef = prop7Data.conf.load.types[0];
|
|
105
|
+
expect(Loader.LoadSingleValueAsType(errors, objData, prop7Data, typeDef, typeDef.types[0], structObj)).toStrictEqual(structObj);
|
|
106
|
+
});
|
|
107
|
+
test(" 6. Load a struct from data", () => {
|
|
108
|
+
constructFoo.mockClear();
|
|
109
|
+
constructResult = structObj;
|
|
110
|
+
let typeDef = prop7Data.conf.load.types[0];
|
|
111
|
+
expect(Loader.LoadSingleValueAsType(errors, objData, prop7Data, typeDef, typeDef.types[0], { Class: TransformersBasicStruct.name, Val: "test" }))
|
|
112
|
+
.toBe(structObj);
|
|
113
|
+
expect(constructFoo).toBeCalledTimes(1);
|
|
114
|
+
expect(constructFoo).toBeCalledWith(StructRepl, objData.source, objData.root, { Class: TransformersBasicStruct.name, Val: "test" });
|
|
115
|
+
constructFoo.mockClear();
|
|
116
|
+
});
|
|
117
|
+
test(" 7. Load a class property.", () => {
|
|
118
|
+
let typeDef = prop9Data.conf.load.types[0];
|
|
119
|
+
expect(Loader.LoadSingleValueAsType(errors, objData, prop9Data, typeDef, typeDef.types[0], classObj)).toStrictEqual(ptr);
|
|
120
|
+
});
|
|
121
|
+
test(" 8. Load a class from data", () => {
|
|
122
|
+
constructFoo.mockClear();
|
|
123
|
+
constructResult = classObj;
|
|
124
|
+
let typeDef = prop9Data.conf.load.types[0];
|
|
125
|
+
let val = { Class: TransformersBasicClass.name, Val: "test" };
|
|
126
|
+
expect(Loader.LoadSingleValueAsType(errors, objData, prop9Data, typeDef, typeDef.types[0], val)).toStrictEqual(ptr);
|
|
127
|
+
expect(constructFoo).toBeCalledTimes(1);
|
|
128
|
+
expect(constructFoo).toBeCalledWith(ClassRepl, objData.source, objData.root, val);
|
|
129
|
+
constructFoo.mockClear();
|
|
130
|
+
});
|
|
131
|
+
test(" 9. Load a pointer property.", () => {
|
|
132
|
+
let typeDef = prop10Data.conf.load.types[0];
|
|
133
|
+
expect(Loader.LoadSingleValueAsType(errors, objData, prop10Data, typeDef, typeDef.types[0], ptr)).toStrictEqual(ptr);
|
|
134
|
+
});
|
|
135
|
+
test("10. Load an inlined class property.", () => {
|
|
136
|
+
let typeDef = prop9Data.conf.load.types[0];
|
|
137
|
+
expect(Loader.LoadSingleValueAsType(errors, objData, prop9Data, typeDef, typeDef.types[0], classObj)).toStrictEqual(ptr);
|
|
138
|
+
});
|
|
139
|
+
test("11. Load an inlined class from data", () => {
|
|
140
|
+
constructFoo.mockClear();
|
|
141
|
+
constructResult = classObj;
|
|
142
|
+
let typeDef = prop9Data.conf.load.types[0];
|
|
143
|
+
expect(Loader.LoadSingleValueAsType(errors, objData, prop9Data, typeDef, typeDef.types[0], { Class: TransformersBasicClass.name, Val: "test" })).toStrictEqual(ptr);
|
|
144
|
+
expect(constructFoo).toBeCalledTimes(1);
|
|
145
|
+
expect(constructFoo).toBeCalledWith(ClassRepl, objData.source, objData.root, { Class: TransformersBasicClass.name, Val: "test" });
|
|
146
|
+
constructFoo.mockClear();
|
|
147
|
+
});
|
|
148
|
+
test("12. Load an inlined pointer property.", () => {
|
|
149
|
+
let typeDef = prop9Data.conf.load.types[0];
|
|
150
|
+
expect(Loader.LoadSingleValueAsType(errors, objData, prop9Data, typeDef, typeDef.types[0], ptr)).toStrictEqual(ptr);
|
|
151
|
+
});
|
|
152
|
+
afterAll(() => {
|
|
153
|
+
Constructor.Construct = original;
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
describe.sequential("2. LoadPropValuesFromData", async () => {
|
|
157
|
+
let errors = new ErrorStack(Source);
|
|
158
|
+
let comparison = null;
|
|
159
|
+
let old = Loader.PerValueCallback;
|
|
160
|
+
Loader.PerValueCallback = (val, id) => {
|
|
161
|
+
expect(val).toStrictEqual(comparison);
|
|
162
|
+
return [val, id];
|
|
163
|
+
};
|
|
164
|
+
afterAll(() => {
|
|
165
|
+
Loader.PerValueCallback = old;
|
|
166
|
+
});
|
|
167
|
+
test(" 1. Should return primitive value as-is", async () => {
|
|
168
|
+
comparison = "value";
|
|
169
|
+
expect(Loader.LoadPropValuesFromData("value", errors, objData, propData)).toBe("value");
|
|
170
|
+
comparison = 1;
|
|
171
|
+
expect(Loader.LoadPropValuesFromData(1, errors, objData, prop2Data)).toBe(1);
|
|
172
|
+
});
|
|
173
|
+
test(" 2. Load a map property.", () => {
|
|
174
|
+
let val3 = JSON.parse(JSON.stringify(TestPropertyDecorators.TransformersTheLotData.Val3));
|
|
175
|
+
comparison = 1;
|
|
176
|
+
expect(Loader.LoadPropValuesFromData(val3, errors, objData, prop3Data))
|
|
177
|
+
.toStrictEqual(new Map([["hello", 1]]));
|
|
178
|
+
expect(Loader.LoadPropValuesFromData(new Map([["hello", 1]]), errors, objData, prop3Data))
|
|
179
|
+
.toStrictEqual(new Map([["hello", 1]]));
|
|
180
|
+
});
|
|
181
|
+
test(" 3. Load a dict property with a number key type.", () => {
|
|
182
|
+
let val4 = JSON.parse(JSON.stringify(TestPropertyDecorators.TransformersTheLotData.Val4));
|
|
183
|
+
comparison = "world";
|
|
184
|
+
expect(Loader.LoadPropValuesFromData(val4, errors, objData, prop4Data))
|
|
185
|
+
.toStrictEqual({ 1: "world" });
|
|
186
|
+
});
|
|
187
|
+
test(" 4. Load an array property.", () => {
|
|
188
|
+
let val5 = JSON.parse(JSON.stringify(TestPropertyDecorators.TransformersTheLotData.Val5));
|
|
189
|
+
comparison = "hello";
|
|
190
|
+
expect(Loader.LoadPropValuesFromData(val5, errors, objData, prop5Data))
|
|
191
|
+
.toStrictEqual(["hello"]);
|
|
192
|
+
});
|
|
193
|
+
test(" 5. Load a 2D array property.", () => {
|
|
194
|
+
let val6 = JSON.parse(JSON.stringify(TestPropertyDecorators.TransformersTheLotData.Val6));
|
|
195
|
+
comparison = 1;
|
|
196
|
+
expect(Loader.LoadPropValuesFromData(val6, errors, objData, prop6Data))
|
|
197
|
+
.toStrictEqual([[1, 2]]);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
describe.sequential("3. Combined LoadSingleValueAsType and LoadPropValuesFromData", async () => {
|
|
201
|
+
let errors = new ErrorStack(Source);
|
|
202
|
+
test("Load a primitive property.", () => {
|
|
203
|
+
expect(Loader.LoadPropValuesFromData("value", errors, objData, propData)).toBe("value");
|
|
204
|
+
});
|
|
205
|
+
test("Load a map property.", () => {
|
|
206
|
+
expect(Loader.LoadPropValuesFromData(new Map([["hello", 1]]), errors, objData, prop3Data)).toStrictEqual(new Map([["hello", 1]]));
|
|
207
|
+
});
|
|
208
|
+
test("Load a dict into a map property.", () => {
|
|
209
|
+
expect(Loader.LoadPropValuesFromData({ hello: 1 }, errors, objData, prop3Data)).toStrictEqual(new Map([["hello", 1]]));
|
|
210
|
+
});
|
|
211
|
+
test("Load a dict property.", () => {
|
|
212
|
+
expect(Loader.LoadPropValuesFromData({ 1: "world" }, errors, objData, prop4Data)).toStrictEqual({ 1: "world" });
|
|
213
|
+
});
|
|
214
|
+
test("Load an array property.", () => {
|
|
215
|
+
expect(Loader.LoadPropValuesFromData(["hello"], errors, objData, prop5Data)).toStrictEqual(["hello"]);
|
|
216
|
+
});
|
|
217
|
+
test("Load a 2D array property.", () => {
|
|
218
|
+
expect(Loader.LoadPropValuesFromData([[1, 2]], errors, objData, prop6Data)).toStrictEqual([[1, 2]]);
|
|
219
|
+
});
|
|
220
|
+
test("Load a struct property.", () => {
|
|
221
|
+
expect(Loader.LoadPropValuesFromData(structObj, errors, objData, prop7Data)).toStrictEqual(structObj);
|
|
222
|
+
});
|
|
223
|
+
test("Load a class property.", () => {
|
|
224
|
+
expect(Loader.LoadPropValuesFromData(classObj, errors, objData, prop10Data)).toStrictEqual(ptr);
|
|
225
|
+
});
|
|
226
|
+
test("Load a pointer property.", () => {
|
|
227
|
+
expect(Loader.LoadPropValuesFromData(ptr, errors, objData, prop10Data)).toStrictEqual(ptr);
|
|
228
|
+
});
|
|
229
|
+
test("Load an inlined class property.", () => {
|
|
230
|
+
expect(Loader.LoadPropValuesFromData(classObj, errors, objData, prop9Data)).toStrictEqual(ptr);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
describe.sequential("4. CalcPropInitialValue", async () => {
|
|
234
|
+
let populatedClass = TransformersTheLotClass.MakeExampleObj();
|
|
235
|
+
let clearClass = new TransformersTheLotClass();
|
|
236
|
+
test("Expressions should be evaluated", async () => {
|
|
237
|
+
expect(Loader.CalcPropInitialValue(objData, "val", evalChain, populatedClass)).toStrictEqual(expr);
|
|
238
|
+
expect(Loader.CalcPropInitialValue(objData, "val", expr, populatedClass)).toBe(expr);
|
|
239
|
+
expect(() => Loader.CalcPropInitialValue(objData, "val13", expr, populatedClass)).toThrowError(`${TransformersTheLotClass.name}.val13 does not accept expressions.`);
|
|
240
|
+
});
|
|
241
|
+
test("Optional properties should be honoured", () => {
|
|
242
|
+
expect(Loader.CalcPropInitialValue(objData, "val3", undefined, clearClass)).toStrictEqual(undefined);
|
|
243
|
+
expect(() => Loader.CalcPropInitialValue(objData, "val", undefined, clearClass)).toThrowError("Object undefined is not a valid value for property TransformersTheLotClass.Val,");
|
|
244
|
+
});
|
|
245
|
+
test("Primitives should be returned as-is", async () => {
|
|
246
|
+
expect(Loader.CalcPropInitialValue(objData, "val", "value", populatedClass)).toBe("value");
|
|
247
|
+
expect(Loader.CalcPropInitialValue(objData, "val2", 1, populatedClass)).toBe(1);
|
|
248
|
+
});
|
|
249
|
+
test("Default assignments should be honoured", () => {
|
|
250
|
+
expect(Loader.CalcPropInitialValue(objData, "val3", undefined, populatedClass)).toStrictEqual(new Map([["hello", 1]]));
|
|
251
|
+
expect(Loader.CalcPropInitialValue(objData, "val4", undefined, populatedClass)).toStrictEqual({ 1: "world" });
|
|
252
|
+
expect(Loader.CalcPropInitialValue(objData, "val5", undefined, populatedClass)).toStrictEqual(["hello"]);
|
|
253
|
+
expect(Loader.CalcPropInitialValue(objData, "val6", undefined, populatedClass)).toStrictEqual([[1, 2]]);
|
|
254
|
+
});
|
|
255
|
+
Progress.ClearCaches();
|
|
256
|
+
let TransformerDefaults = class TransformerDefaults {
|
|
257
|
+
};
|
|
258
|
+
__decorate([
|
|
259
|
+
Property(Versions.v1_0_0, String, { default: "hello" })
|
|
260
|
+
], TransformerDefaults.prototype, "val", void 0);
|
|
261
|
+
__decorate([
|
|
262
|
+
Property(Versions.v1_0_0, Number, { default: 1 })
|
|
263
|
+
], TransformerDefaults.prototype, "val2", void 0);
|
|
264
|
+
__decorate([
|
|
265
|
+
Property(Versions.v1_0_0, { type: Number, mapKey: String }, { default: { hello: 1 } })
|
|
266
|
+
], TransformerDefaults.prototype, "val3", void 0);
|
|
267
|
+
__decorate([
|
|
268
|
+
Property(Versions.v1_0_0, { type: String, dictKey: Number, restrictedTo: [1, 2, 3] }, { default: { 1: "world" } })
|
|
269
|
+
], TransformerDefaults.prototype, "val4", void 0);
|
|
270
|
+
__decorate([
|
|
271
|
+
Property(Versions.v1_0_0, { type: String, array: true }, { default: ["hello"] })
|
|
272
|
+
], TransformerDefaults.prototype, "val5", void 0);
|
|
273
|
+
__decorate([
|
|
274
|
+
Property(Versions.v1_0_0, { type: Number, array: 2 }, { default: [[1, 2]] })
|
|
275
|
+
], TransformerDefaults.prototype, "val6", void 0);
|
|
276
|
+
TransformerDefaults = __decorate([
|
|
277
|
+
Struct(Versions.v1_0_0)
|
|
278
|
+
], TransformerDefaults);
|
|
279
|
+
Progress.FinishedAllLoading();
|
|
280
|
+
const DefaultRepl = ReplicableRegistry.__GetReplicableForDataName(TransformerDefaults.name);
|
|
281
|
+
test("Default property decorators values should be honoured", () => {
|
|
282
|
+
expect(Loader.CalcPropInitialValue(objData, "val", undefined, populatedClass)).toStrictEqual("hello");
|
|
283
|
+
expect(Loader.CalcPropInitialValue(objData, "val2", undefined, populatedClass)).toStrictEqual(5);
|
|
284
|
+
expect(Loader.CalcPropInitialValue(objData, "val3", undefined, populatedClass)).toStrictEqual(new Map([["hello", 1]]));
|
|
285
|
+
expect(Loader.CalcPropInitialValue(objData, "val4", undefined, populatedClass)).toStrictEqual({ 1: "world" });
|
|
286
|
+
expect(Loader.CalcPropInitialValue(objData, "val5", undefined, populatedClass)).toStrictEqual(["hello"]);
|
|
287
|
+
expect(Loader.CalcPropInitialValue(objData, "val6", undefined, populatedClass)).toStrictEqual([[1, 2]]);
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
describe.sequential("5. InitFromData", async () => {
|
|
291
|
+
let populatedClass = TransformersTheLotClass.MakeExampleObj();
|
|
292
|
+
let clearClass = new TransformersTheLotClass();
|
|
293
|
+
test("Should init data correctly", () => {
|
|
294
|
+
expect(Loader.InitFromData(TestRepl, Source, clearClass, JSON.parse(JSON.stringify(TestPropertyDecorators.TransformersTheLotData))))
|
|
295
|
+
.toStrictEqual(populatedClass);
|
|
296
|
+
});
|
|
297
|
+
ExpressionScopes.addLocalVariable("TransformersTheLotClass", "thisEntity", [TransformersTheLotClass]);
|
|
298
|
+
Expression.setCurrentStartScopeType("TransformersTheLotClass");
|
|
299
|
+
let example;
|
|
300
|
+
test.sequential("Should allow for init with live data", () => {
|
|
301
|
+
let liveData = Object.fromEntries(Object.entries(TestPropertyDecorators.TransformersTheLotData)
|
|
302
|
+
.map(([key, val]) => [key[0].toUpperCase() + key.slice(1), val]));
|
|
303
|
+
example = Loader.InitFromData(TestRepl, Source, new TransformersTheLotClass(), liveData);
|
|
304
|
+
expect(example).toStrictEqual(populatedClass);
|
|
305
|
+
});
|
|
306
|
+
test.sequential("Should init expressions correctly", () => {
|
|
307
|
+
ExpressionScopes.setLocalScope("TransformersTheLotClass", { thisEntity: example });
|
|
308
|
+
let def = JSON.parse(JSON.stringify(TestPropertyDecorators.TransformersTheLotExpression));
|
|
309
|
+
def = Definitions.PrePrepareData(TestRepl, def, Source);
|
|
310
|
+
let result;
|
|
311
|
+
expect(() => result = Loader.InitFromData(TestRepl, Source, new TransformersTheLotClass(), def)).not.toThrowError();
|
|
312
|
+
ExpressionScopes.setLocalScope("TransformersTheLotClass", { thisEntity: example });
|
|
313
|
+
expect(Object.getOwnPropertyDescriptor(result, "val")).not.toBeUndefined();
|
|
314
|
+
expect(result.val).toBe(example.val);
|
|
315
|
+
expect(Object.getOwnPropertyDescriptor(result, "val2")).not.toBeUndefined();
|
|
316
|
+
expect(result.val2).toBe(example.val2);
|
|
317
|
+
expect(Object.getOwnPropertyDescriptor(result, "val3")).not.toBeUndefined();
|
|
318
|
+
expect(result.val3).toStrictEqual(example.val3);
|
|
319
|
+
expect(Object.getOwnPropertyDescriptor(result, "val4")).not.toBeUndefined();
|
|
320
|
+
expect(result.val4).toStrictEqual(example.val4);
|
|
321
|
+
expect(Object.getOwnPropertyDescriptor(result, "val5")).not.toBeUndefined();
|
|
322
|
+
expect(result.val5).toStrictEqual(example.val5);
|
|
323
|
+
expect(Object.getOwnPropertyDescriptor(result, "val6")).not.toBeUndefined();
|
|
324
|
+
expect(result.val6).toStrictEqual(example.val6);
|
|
325
|
+
expect(Object.getOwnPropertyDescriptor(result, "val7")).not.toBeUndefined();
|
|
326
|
+
expect(result.val7).toBe(example.val7);
|
|
327
|
+
expect(Object.getOwnPropertyDescriptor(result, "val8")).not.toBeUndefined();
|
|
328
|
+
expect(result.val8).toBe(example.val8);
|
|
329
|
+
expect(Object.getOwnPropertyDescriptor(result, "val9")).not.toBeUndefined();
|
|
330
|
+
expect(result.val9).toBe(example.val9);
|
|
331
|
+
expect(Object.getOwnPropertyDescriptor(result, "val10")).not.toBeUndefined();
|
|
332
|
+
expect(result.val10).toBe(example.val10);
|
|
333
|
+
expect(Object.getOwnPropertyDescriptor(result, "val11")).not.toBeUndefined();
|
|
334
|
+
expect(result.val11).toBe(example.val11);
|
|
335
|
+
expect(Object.getOwnPropertyDescriptor(result, "val13")).not.toBeUndefined();
|
|
336
|
+
expect(result.val13).toStrictEqual(example.val13);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { afterAll, afterEach, describe, expect, test } from "vitest";
|
|
2
|
+
import { Progress } from "../Progress.js";
|
|
3
|
+
import { fn } from "@vitest/spy";
|
|
4
|
+
import { Versions } from "../../Constants/Versions.js";
|
|
5
|
+
import { FormatPropInput } from "../../Tracking/Property.js";
|
|
6
|
+
import { SmartArray } from "@bikky/smart-collections";
|
|
7
|
+
import { Configurer } from "../Configurer.js";
|
|
8
|
+
//TODO: Test registering a @DelayUntil class.
|
|
9
|
+
//TODO: Test registering a class that uses a @DelayUntil value.
|
|
10
|
+
//TODO: Test registering a class that uses an alias for a @DelayUntil value.
|
|
11
|
+
//TODO: Test a @DelayUntil class being registered as an alias before and after promise completion.
|
|
12
|
+
//TODO: Test an alias resolving to a @DelayUntil class.
|
|
13
|
+
//TODO: Test an expression using a @DelayUntil type (both navigating to and beyond a property with that type).
|
|
14
|
+
describe.sequential("Progress", () => {
|
|
15
|
+
let old = Configurer.CacheClassProperties;
|
|
16
|
+
let watch = Configurer.CacheClassProperties = fn();
|
|
17
|
+
afterAll(() => {
|
|
18
|
+
Configurer.CacheClassProperties = old;
|
|
19
|
+
});
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
watch.mockClear();
|
|
22
|
+
});
|
|
23
|
+
class FakeReplicableType {
|
|
24
|
+
constructor(base) {
|
|
25
|
+
this.opts = { dataTypeName: base.constructor.name };
|
|
26
|
+
this.addProperty = fn();
|
|
27
|
+
this.removeProperty = fn();
|
|
28
|
+
this.addFunction = fn();
|
|
29
|
+
this.onComplete = fn();
|
|
30
|
+
this.classConstructor = base;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function SetupClasses() {
|
|
34
|
+
class TestStruct {
|
|
35
|
+
}
|
|
36
|
+
class Test2Struct {
|
|
37
|
+
}
|
|
38
|
+
let repl = new FakeReplicableType(TestStruct);
|
|
39
|
+
let repl2 = new FakeReplicableType(Test2Struct);
|
|
40
|
+
return [TestStruct, Test2Struct, repl, repl2];
|
|
41
|
+
}
|
|
42
|
+
describe.sequential("1. FinishReplicableType", () => {
|
|
43
|
+
test.sequential("Register a type with no properties.", () => {
|
|
44
|
+
Progress.ClearCaches();
|
|
45
|
+
const [TestStruct, Test2Struct, repl, repl2] = SetupClasses();
|
|
46
|
+
Progress.FinishReplicableType(repl);
|
|
47
|
+
Progress.FinishedAllLoading();
|
|
48
|
+
expect(Configurer.CacheClassProperties).toBeCalledTimes(1);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe.sequential("2. RegisterPropertyLoad", () => {
|
|
52
|
+
test.sequential("1. Register a property on an existing type.", () => {
|
|
53
|
+
Progress.ClearCaches();
|
|
54
|
+
const [TestStruct, Test2Struct, repl, repl2] = SetupClasses();
|
|
55
|
+
Progress.FinishReplicableType(repl);
|
|
56
|
+
let compType = FormatPropInput(String);
|
|
57
|
+
Progress.RegisterPropertyLoad(TestStruct, [Versions.v1_0_0, "prop", { type: compType }]);
|
|
58
|
+
Progress.FinishedAllLoading();
|
|
59
|
+
expect(repl.addProperty).toBeCalledTimes(1);
|
|
60
|
+
expect(repl.removeProperty).toBeCalledTimes(0);
|
|
61
|
+
expect(repl.addFunction).toBeCalledTimes(0);
|
|
62
|
+
expect(repl.addProperty).toBeCalledWith(Versions.v1_0_0, "prop", { type: compType });
|
|
63
|
+
});
|
|
64
|
+
test.sequential("2. Register a property on a new type.", () => {
|
|
65
|
+
Progress.ClearCaches();
|
|
66
|
+
const [TestStruct, Test2Struct, repl, repl2] = SetupClasses();
|
|
67
|
+
Progress.FinishReplicableType(repl);
|
|
68
|
+
let compType = FormatPropInput(String);
|
|
69
|
+
Progress.RegisterPropertyLoad(Test2Struct, [Versions.v1_0_0, "prop2", { type: compType }]);
|
|
70
|
+
Progress.FinishReplicableType(repl2);
|
|
71
|
+
Progress.FinishedAllLoading();
|
|
72
|
+
expect(repl2.addProperty).toBeCalledTimes(1);
|
|
73
|
+
expect(repl2.removeProperty).toBeCalledTimes(0);
|
|
74
|
+
expect(repl2.addFunction).toBeCalledTimes(0);
|
|
75
|
+
});
|
|
76
|
+
test.sequential("3. Register a second property on an existing type.", () => {
|
|
77
|
+
Progress.ClearCaches();
|
|
78
|
+
const [TestStruct, Test2Struct, repl, repl2] = SetupClasses();
|
|
79
|
+
Progress.FinishReplicableType(repl);
|
|
80
|
+
let compType = FormatPropInput(Number);
|
|
81
|
+
Progress.RegisterPropertyLoad(TestStruct, [Versions.v1_0_0, "val", { type: compType }]);
|
|
82
|
+
Progress.FinishedAllLoading();
|
|
83
|
+
expect(repl.addProperty).toBeCalledTimes(1);
|
|
84
|
+
expect(repl.removeProperty).toBeCalledTimes(0);
|
|
85
|
+
expect(repl.addFunction).toBeCalledTimes(0);
|
|
86
|
+
expect(repl.addProperty).nthCalledWith(1, Versions.v1_0_0, "val", { type: compType });
|
|
87
|
+
});
|
|
88
|
+
test.sequential("4. Register a second property on a new type.", () => {
|
|
89
|
+
Progress.ClearCaches();
|
|
90
|
+
const [TestStruct, Test2Struct, repl, repl2] = SetupClasses();
|
|
91
|
+
Progress.FinishReplicableType(repl);
|
|
92
|
+
let compType = FormatPropInput(Number);
|
|
93
|
+
Progress.RegisterPropertyLoad(Test2Struct, [Versions.v1_0_0, "prop2", { type: compType }]);
|
|
94
|
+
Progress.RegisterPropertyLoad(Test2Struct, [Versions.v1_0_0, "val2", { type: compType }]);
|
|
95
|
+
Progress.FinishReplicableType(repl2);
|
|
96
|
+
Progress.FinishedAllLoading();
|
|
97
|
+
expect(repl2.addProperty).toBeCalledTimes(2);
|
|
98
|
+
expect(repl2.removeProperty).toBeCalledTimes(0);
|
|
99
|
+
expect(repl2.addFunction).toBeCalledTimes(0);
|
|
100
|
+
});
|
|
101
|
+
test.sequential("5. Register a class lookup property on an existing type.", () => {
|
|
102
|
+
Progress.ClearCaches();
|
|
103
|
+
const [TestStruct, Test2Struct, repl, repl2] = SetupClasses();
|
|
104
|
+
Progress.FinishReplicableType(repl);
|
|
105
|
+
let compType = FormatPropInput(Test2Struct);
|
|
106
|
+
Progress.RegisterPropertyLoad(TestStruct, [Versions.v1_0_0, "another", { type: compType }]);
|
|
107
|
+
Progress.FinishedAllLoading();
|
|
108
|
+
//Add was not called because Test2Struct is not finished.
|
|
109
|
+
expect(repl.addProperty).toBeCalledTimes(0);
|
|
110
|
+
expect(repl.removeProperty).toBeCalledTimes(0);
|
|
111
|
+
expect(repl.addFunction).toBeCalledTimes(0);
|
|
112
|
+
});
|
|
113
|
+
test.sequential("6. Register a self lookup property on an existing type.", () => {
|
|
114
|
+
Progress.ClearCaches();
|
|
115
|
+
const [TestStruct, Test2Struct, repl, repl2] = SetupClasses();
|
|
116
|
+
Progress.FinishReplicableType(repl);
|
|
117
|
+
let compType = FormatPropInput(TestStruct);
|
|
118
|
+
Progress.RegisterPropertyLoad(TestStruct, [Versions.v1_0_0, "self", { type: compType }]);
|
|
119
|
+
Progress.FinishedAllLoading();
|
|
120
|
+
expect(repl.addProperty).toBeCalledTimes(1);
|
|
121
|
+
expect(repl.removeProperty).toBeCalledTimes(0);
|
|
122
|
+
expect(repl.addFunction).toBeCalledTimes(0);
|
|
123
|
+
expect(repl.addProperty).nthCalledWith(1, Versions.v1_0_0, "self", { type: compType });
|
|
124
|
+
});
|
|
125
|
+
test.sequential("7. Register a class lookup property on a new type.", () => {
|
|
126
|
+
Progress.ClearCaches();
|
|
127
|
+
const [TestStruct, Test2Struct, repl, repl2] = SetupClasses();
|
|
128
|
+
Progress.FinishReplicableType(repl);
|
|
129
|
+
let compType = FormatPropInput(TestStruct);
|
|
130
|
+
Progress.RegisterPropertyLoad(Test2Struct, [Versions.v1_0_0, "prop2", { type: compType }]);
|
|
131
|
+
Progress.RegisterPropertyLoad(Test2Struct, [Versions.v1_0_0, "val2", { type: compType }]);
|
|
132
|
+
Progress.RegisterPropertyLoad(Test2Struct, [Versions.v1_0_0, "another2", { type: compType }]);
|
|
133
|
+
Progress.FinishReplicableType(repl2);
|
|
134
|
+
Progress.FinishedAllLoading();
|
|
135
|
+
expect(repl2.addProperty).toBeCalledTimes(3);
|
|
136
|
+
expect(repl2.removeProperty).toBeCalledTimes(0);
|
|
137
|
+
expect(repl2.addFunction).toBeCalledTimes(0);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe.sequential("3. RegisterFunctionAdd", () => {
|
|
141
|
+
test.sequential("1. Register a function on an existing type", () => {
|
|
142
|
+
Progress.ClearCaches();
|
|
143
|
+
const [TestStruct, Test2Struct, repl, repl2] = SetupClasses();
|
|
144
|
+
Progress.FinishReplicableType(repl);
|
|
145
|
+
let returnType = FormatPropInput(String);
|
|
146
|
+
let params = [FormatPropInput(String)];
|
|
147
|
+
Progress.RegisterFunctionAdd(TestStruct, [Versions.v1_0_0, "foo", returnType, params, {}]);
|
|
148
|
+
Progress.FinishedAllLoading();
|
|
149
|
+
expect(repl.addProperty).toBeCalledTimes(0);
|
|
150
|
+
expect(repl.removeProperty).toBeCalledTimes(0);
|
|
151
|
+
expect(repl.addFunction).toBeCalledTimes(1);
|
|
152
|
+
expect(repl.addFunction).toBeCalledWith(Versions.v1_0_0, "foo", returnType, params, {});
|
|
153
|
+
});
|
|
154
|
+
test.sequential("2. Register a function on a new type", () => {
|
|
155
|
+
Progress.ClearCaches();
|
|
156
|
+
const [TestStruct, Test2Struct, repl, repl2] = SetupClasses();
|
|
157
|
+
Progress.FinishReplicableType(repl);
|
|
158
|
+
let returnType = FormatPropInput(String);
|
|
159
|
+
let params = [FormatPropInput(String)];
|
|
160
|
+
Progress.RegisterFunctionAdd(Test2Struct, [Versions.v1_0_0, "foo2", returnType, params, {}]);
|
|
161
|
+
Progress.FinishReplicableType(repl2);
|
|
162
|
+
Progress.FinishedAllLoading();
|
|
163
|
+
expect(repl2.addProperty).toBeCalledTimes(0);
|
|
164
|
+
expect(repl2.removeProperty).toBeCalledTimes(0);
|
|
165
|
+
expect(repl2.addFunction).toBeCalledTimes(1);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
test.sequential("4. FinishReplicableType a type with properties pre-registered.", () => {
|
|
169
|
+
Progress.ClearCaches();
|
|
170
|
+
const [TestStruct, Test2Struct, repl, repl2] = SetupClasses();
|
|
171
|
+
Progress.FinishReplicableType(repl);
|
|
172
|
+
expect(repl2.addProperty).toBeCalledTimes(0);
|
|
173
|
+
expect(repl2.removeProperty).toBeCalledTimes(0);
|
|
174
|
+
expect(repl2.addFunction).toBeCalledTimes(0);
|
|
175
|
+
expect(Configurer.CacheClassProperties).toBeCalledTimes(0);
|
|
176
|
+
{
|
|
177
|
+
let compType = FormatPropInput(String);
|
|
178
|
+
Progress.RegisterPropertyLoad(Test2Struct, [Versions.v1_0_0, "prop2", { type: compType }]);
|
|
179
|
+
}
|
|
180
|
+
{
|
|
181
|
+
let compType = FormatPropInput(Number);
|
|
182
|
+
Progress.RegisterPropertyLoad(Test2Struct, [Versions.v1_0_0, "val2", { type: compType }]);
|
|
183
|
+
}
|
|
184
|
+
{
|
|
185
|
+
let compType = FormatPropInput(TestStruct);
|
|
186
|
+
Progress.RegisterPropertyLoad(Test2Struct, [Versions.v1_0_0, "another2", { type: compType }]);
|
|
187
|
+
}
|
|
188
|
+
{
|
|
189
|
+
let returnType = FormatPropInput(String);
|
|
190
|
+
let params = [FormatPropInput(String)];
|
|
191
|
+
Progress.RegisterFunctionAdd(Test2Struct, [Versions.v1_0_0, "foo2", returnType, params, {}]);
|
|
192
|
+
}
|
|
193
|
+
Progress.FinishReplicableType(repl2);
|
|
194
|
+
Progress.FinishedAllLoading();
|
|
195
|
+
expect(repl2.addProperty).toBeCalledTimes(3);
|
|
196
|
+
expect(repl2.removeProperty).toBeCalledTimes(0);
|
|
197
|
+
expect(repl2.addFunction).toBeCalledTimes(1);
|
|
198
|
+
expect(Configurer.CacheClassProperties).toBeCalledTimes(2);
|
|
199
|
+
let compType = FormatPropInput(String);
|
|
200
|
+
let numType = FormatPropInput(Number);
|
|
201
|
+
expect(repl2.addProperty).nthCalledWith(1, Versions.v1_0_0, "prop2", { type: compType });
|
|
202
|
+
expect(repl2.addProperty).nthCalledWith(2, Versions.v1_0_0, "val2", { type: numType });
|
|
203
|
+
let returnType = FormatPropInput(String);
|
|
204
|
+
let params = [FormatPropInput(String)];
|
|
205
|
+
expect(repl2.addFunction).toBeCalledWith(Versions.v1_0_0, "foo2", returnType, params, {});
|
|
206
|
+
});
|
|
207
|
+
test.sequential("5. Make a class that uses an alias", () => {
|
|
208
|
+
Progress.ClearCaches();
|
|
209
|
+
class TestStruct {
|
|
210
|
+
}
|
|
211
|
+
class TestStruct2 {
|
|
212
|
+
}
|
|
213
|
+
class TestStruct3 {
|
|
214
|
+
}
|
|
215
|
+
Progress.RegisterPropertyLoad(TestStruct, [Versions.v1_0_0, "test", { type: [{ type: ["MyAlias"] }] }]);
|
|
216
|
+
Progress.RegisterPropertyLoad(TestStruct2, [Versions.v1_0_0, "bleh", { type: [{ type: [String] }] }]);
|
|
217
|
+
Progress.RegisterPropertyLoad(TestStruct3, [Versions.v1_0_0, "world", { type: [{ type: [Number] }] }]);
|
|
218
|
+
let repl = new FakeReplicableType(TestStruct);
|
|
219
|
+
let repl2 = new FakeReplicableType(TestStruct2);
|
|
220
|
+
let repl3 = new FakeReplicableType(TestStruct3);
|
|
221
|
+
Progress.FinishReplicableType(repl);
|
|
222
|
+
Progress.FinishReplicableType(repl2);
|
|
223
|
+
Progress.FinishReplicableType(repl3);
|
|
224
|
+
Progress.RegisterAlias("MyAlias", TestStruct3);
|
|
225
|
+
Progress.RegisterAlias("MyAlias", TestStruct2);
|
|
226
|
+
Progress.FinishedAllLoading();
|
|
227
|
+
Progress.ClearCaches();
|
|
228
|
+
expect(repl.addProperty).toBeCalledTimes(1);
|
|
229
|
+
expect(repl.removeProperty).toBeCalledTimes(0);
|
|
230
|
+
expect(repl.addFunction).toBeCalledTimes(0);
|
|
231
|
+
expect(repl2.addProperty).toBeCalledTimes(1);
|
|
232
|
+
expect(repl2.removeProperty).toBeCalledTimes(0);
|
|
233
|
+
expect(repl2.addFunction).toBeCalledTimes(0);
|
|
234
|
+
expect(repl3.addProperty).toBeCalledTimes(1);
|
|
235
|
+
expect(repl3.removeProperty).toBeCalledTimes(0);
|
|
236
|
+
expect(repl3.addFunction).toBeCalledTimes(0);
|
|
237
|
+
});
|
|
238
|
+
test.sequential("6. Await a class' completion", async () => {
|
|
239
|
+
Progress.ClearCaches();
|
|
240
|
+
const [TestStruct, Test2Struct, repl, repl2] = SetupClasses();
|
|
241
|
+
Progress.RegisterPropertyLoad(Test2Struct, [Versions.v1_0_0, "bleh", { type: [{ type: [String] }] }]);
|
|
242
|
+
Progress.FinishReplicableType(repl);
|
|
243
|
+
Progress.FinishReplicableType(repl2);
|
|
244
|
+
let promise1 = Progress.AwaitReplicableFor(TestStruct);
|
|
245
|
+
let promise2 = Progress.AwaitReplicableFor(Test2Struct);
|
|
246
|
+
Progress.FinishedAllLoading();
|
|
247
|
+
expect(promise1.result).toStrictEqual(new SmartArray(repl));
|
|
248
|
+
expect(promise2.result).toStrictEqual(new SmartArray(repl2));
|
|
249
|
+
let foo = fn();
|
|
250
|
+
promise1.then(foo);
|
|
251
|
+
expect(foo).toBeCalledWith(new SmartArray(repl));
|
|
252
|
+
let foo2 = fn();
|
|
253
|
+
promise2.then(foo2);
|
|
254
|
+
expect(foo2).toBeCalledWith(new SmartArray(repl2));
|
|
255
|
+
});
|
|
256
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|