@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,166 @@
|
|
|
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 { BikPath } from "@bikky/path";
|
|
8
|
+
import { expect, test } from "vitest";
|
|
9
|
+
import { Expression } from "../Expressions/Expression.js";
|
|
10
|
+
import { Property, Struct, Versions } from "../Main.js";
|
|
11
|
+
import { ExpressionScopes } from "../Expressions/TypeRegistry/Registry.js";
|
|
12
|
+
import { Progress } from "../Transformers/Progress.js";
|
|
13
|
+
test("Test create expression to access property on replicable", () => {
|
|
14
|
+
Progress.ClearCaches();
|
|
15
|
+
let BaseTest = class BaseTest {
|
|
16
|
+
};
|
|
17
|
+
__decorate([
|
|
18
|
+
Property(Versions.v1_0_0, Number)
|
|
19
|
+
], BaseTest.prototype, "test", void 0);
|
|
20
|
+
BaseTest = __decorate([
|
|
21
|
+
Struct(Versions.v1_0_0)
|
|
22
|
+
], BaseTest);
|
|
23
|
+
Progress.FinishedAllLoading();
|
|
24
|
+
ExpressionScopes.addLocalVariable(BaseTest.name, "thisEntity", [BaseTest]);
|
|
25
|
+
let result = Expression.Parse("@{thisEntity.Test}", BikPath.getCurrentFilepath(), {
|
|
26
|
+
duringLoad: false,
|
|
27
|
+
cacheable: true,
|
|
28
|
+
version: Versions.v1_0_0,
|
|
29
|
+
startType: BaseTest.name,
|
|
30
|
+
outputTypes: [Number],
|
|
31
|
+
});
|
|
32
|
+
expect(result).not.toBeUndefined();
|
|
33
|
+
});
|
|
34
|
+
test("Get property on replicable via expression.", () => {
|
|
35
|
+
Progress.ClearCaches();
|
|
36
|
+
let BaseTestX = class BaseTestX {
|
|
37
|
+
};
|
|
38
|
+
__decorate([
|
|
39
|
+
Property(Versions.v1_0_0, Number)
|
|
40
|
+
], BaseTestX.prototype, "test", void 0);
|
|
41
|
+
BaseTestX = __decorate([
|
|
42
|
+
Struct(Versions.v1_0_0)
|
|
43
|
+
], BaseTestX);
|
|
44
|
+
Progress.FinishedAllLoading();
|
|
45
|
+
ExpressionScopes.addLocalVariable(BaseTestX.name, "thisEntity", [BaseTestX]);
|
|
46
|
+
let result = Expression.Parse("@{thisEntity.Test}", BikPath.getCurrentFilepath(), {
|
|
47
|
+
duringLoad: false,
|
|
48
|
+
cacheable: true,
|
|
49
|
+
version: Versions.v1_0_0,
|
|
50
|
+
startType: BaseTestX.name,
|
|
51
|
+
outputTypes: [Number],
|
|
52
|
+
});
|
|
53
|
+
expect(result).not.toBeUndefined();
|
|
54
|
+
let obj = new BaseTestX();
|
|
55
|
+
obj.test = 4;
|
|
56
|
+
let outcome = result.get({
|
|
57
|
+
version: Versions.v1_0_0,
|
|
58
|
+
data: false,
|
|
59
|
+
local: {
|
|
60
|
+
thisEntity: obj
|
|
61
|
+
},
|
|
62
|
+
self: obj,
|
|
63
|
+
global: {}
|
|
64
|
+
});
|
|
65
|
+
expect(outcome).toBe(4);
|
|
66
|
+
});
|
|
67
|
+
test("Test calling base property on child class", () => {
|
|
68
|
+
Progress.ClearCaches();
|
|
69
|
+
let BaseTest = class BaseTest {
|
|
70
|
+
};
|
|
71
|
+
__decorate([
|
|
72
|
+
Property(Versions.v1_0_0, Number)
|
|
73
|
+
], BaseTest.prototype, "test", void 0);
|
|
74
|
+
BaseTest = __decorate([
|
|
75
|
+
Struct(Versions.v1_0_0)
|
|
76
|
+
], BaseTest);
|
|
77
|
+
let TestTwo = class TestTwo extends BaseTest {
|
|
78
|
+
};
|
|
79
|
+
__decorate([
|
|
80
|
+
Property(Versions.v1_0_0, Number)
|
|
81
|
+
], TestTwo.prototype, "second", void 0);
|
|
82
|
+
TestTwo = __decorate([
|
|
83
|
+
Struct(Versions.v1_0_0)
|
|
84
|
+
], TestTwo);
|
|
85
|
+
Progress.FinishedAllLoading();
|
|
86
|
+
ExpressionScopes.addLocalVariable(BaseTest.name, "thisEntity", [BaseTest]);
|
|
87
|
+
let result = Expression.Parse("@{thisEntity.Test}", BikPath.getCurrentFilepath(), {
|
|
88
|
+
duringLoad: false,
|
|
89
|
+
cacheable: true,
|
|
90
|
+
version: Versions.v1_0_0,
|
|
91
|
+
startType: BaseTest.name,
|
|
92
|
+
outputTypes: [Number],
|
|
93
|
+
});
|
|
94
|
+
expect(result).not.toBeUndefined();
|
|
95
|
+
});
|
|
96
|
+
test("Test casting to child class", () => {
|
|
97
|
+
Progress.ClearCaches();
|
|
98
|
+
let BaseTest = class BaseTest {
|
|
99
|
+
};
|
|
100
|
+
__decorate([
|
|
101
|
+
Property(Versions.v1_0_0, Number)
|
|
102
|
+
], BaseTest.prototype, "test", void 0);
|
|
103
|
+
BaseTest = __decorate([
|
|
104
|
+
Struct(Versions.v1_0_0)
|
|
105
|
+
], BaseTest);
|
|
106
|
+
let TestTwo = class TestTwo extends BaseTest {
|
|
107
|
+
};
|
|
108
|
+
__decorate([
|
|
109
|
+
Property(Versions.v1_0_0, Number)
|
|
110
|
+
], TestTwo.prototype, "second", void 0);
|
|
111
|
+
TestTwo = __decorate([
|
|
112
|
+
Struct(Versions.v1_0_0)
|
|
113
|
+
], TestTwo);
|
|
114
|
+
Progress.FinishedAllLoading();
|
|
115
|
+
ExpressionScopes.addLocalVariable(BaseTest.name, "thisEntity", [BaseTest]);
|
|
116
|
+
let result = Expression.Parse("@{thisEntity:TestTwo.Test}", BikPath.getCurrentFilepath(), {
|
|
117
|
+
duringLoad: false,
|
|
118
|
+
cacheable: true,
|
|
119
|
+
version: Versions.v1_0_0,
|
|
120
|
+
startType: BaseTest.name,
|
|
121
|
+
outputTypes: [Number],
|
|
122
|
+
});
|
|
123
|
+
expect(result).not.toBeUndefined();
|
|
124
|
+
});
|
|
125
|
+
test("Test getting value on child class", () => {
|
|
126
|
+
Progress.ClearCaches();
|
|
127
|
+
let BaseTestY = class BaseTestY {
|
|
128
|
+
};
|
|
129
|
+
__decorate([
|
|
130
|
+
Property(Versions.v1_0_0, Number)
|
|
131
|
+
], BaseTestY.prototype, "test", void 0);
|
|
132
|
+
BaseTestY = __decorate([
|
|
133
|
+
Struct(Versions.v1_0_0)
|
|
134
|
+
], BaseTestY);
|
|
135
|
+
let TestTwo = class TestTwo extends BaseTestY {
|
|
136
|
+
};
|
|
137
|
+
__decorate([
|
|
138
|
+
Property(Versions.v1_0_0, Number)
|
|
139
|
+
], TestTwo.prototype, "second", void 0);
|
|
140
|
+
TestTwo = __decorate([
|
|
141
|
+
Struct(Versions.v1_0_0)
|
|
142
|
+
], TestTwo);
|
|
143
|
+
Progress.FinishedAllLoading();
|
|
144
|
+
ExpressionScopes.addLocalVariable(BaseTestY.name, "thisEntity", [BaseTestY]);
|
|
145
|
+
let result = Expression.Parse("@{thisEntity:TestTwo.Second}", BikPath.getCurrentFilepath(), {
|
|
146
|
+
duringLoad: false,
|
|
147
|
+
cacheable: true,
|
|
148
|
+
version: Versions.v1_0_0,
|
|
149
|
+
startType: BaseTestY.name,
|
|
150
|
+
outputTypes: [Number],
|
|
151
|
+
});
|
|
152
|
+
expect(result).not.toBeUndefined();
|
|
153
|
+
let obj = new TestTwo();
|
|
154
|
+
obj.test = 4;
|
|
155
|
+
obj.second = 3;
|
|
156
|
+
let outcome = result.get({
|
|
157
|
+
version: Versions.v1_0_0,
|
|
158
|
+
data: false,
|
|
159
|
+
local: {
|
|
160
|
+
thisEntity: obj
|
|
161
|
+
},
|
|
162
|
+
self: obj,
|
|
163
|
+
global: {}
|
|
164
|
+
});
|
|
165
|
+
expect(outcome).toBe(3);
|
|
166
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { Progress } from "../Transformers/Progress.js";
|
|
3
|
+
describe("IDPool", () => {
|
|
4
|
+
test("Registering ID Pool", async () => {
|
|
5
|
+
const { ReplicableRegistry } = await import("../Constants/ReplicableRegistry.js");
|
|
6
|
+
await import("../IDPool.js");
|
|
7
|
+
await ReplicableRegistry.Initialise();
|
|
8
|
+
Progress.AwaitReplicableFor("UUID");
|
|
9
|
+
expect(ReplicableRegistry.__GetReplicablesFor("UUID")).not.toBeUndefined();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
//<reference path="@bikky/compiler/Libraries/GlobalTypes.d.ts">
|
|
2
|
+
import { WaitableMap } from "@bikky/smart-collections";
|
|
3
|
+
import { beforeAll, expect, test } from "vitest";
|
|
4
|
+
import { ReplicableRegistry } from "../Constants/ReplicableRegistry.js";
|
|
5
|
+
import { AddVersion, Versions } from "../Constants/Versions.js";
|
|
6
|
+
import { Struct, Type } from "../Tracking/Class.js";
|
|
7
|
+
import { Property } from "../Tracking/Property.js";
|
|
8
|
+
import { Progress } from "../Transformers/Progress.js";
|
|
9
|
+
import { Configurer } from "../Transformers/Configurer.js";
|
|
10
|
+
import { fn } from "@vitest/spy";
|
|
11
|
+
let version = "version";
|
|
12
|
+
beforeAll(() => {
|
|
13
|
+
AddVersion(version, Versions.v1_0_0);
|
|
14
|
+
});
|
|
15
|
+
//TODO: Test multiple aliases for the same type (was broken by overwriting old results with new results when returned from Progress).
|
|
16
|
+
test("Struct is created.", () => {
|
|
17
|
+
Progress.ClearCaches();
|
|
18
|
+
class TestStruct {
|
|
19
|
+
}
|
|
20
|
+
let edited = Struct(version)(TestStruct);
|
|
21
|
+
Progress.FinishedAllLoading();
|
|
22
|
+
expect(edited).not.toBeUndefined();
|
|
23
|
+
let def = ReplicableRegistry.__GetReplicablesFor(edited)[0];
|
|
24
|
+
expect(def).not.toBeUndefined();
|
|
25
|
+
expect(def.opts.dataTypeName).toBe("TestStruct");
|
|
26
|
+
expect(def.classConstructor).toBe(edited);
|
|
27
|
+
});
|
|
28
|
+
// test("Struct is registered in registry and can be awaited by name.", async () => {
|
|
29
|
+
// let promise = ReplicableRegistry.__awaitReplicableFor("TestStruct");
|
|
30
|
+
// class TestStruct {}
|
|
31
|
+
// let edited = Struct(version)(TestStruct);
|
|
32
|
+
// await promise;
|
|
33
|
+
// expect(true).toBe(true);
|
|
34
|
+
// });
|
|
35
|
+
test("Objects can be matched keys in waitmap", async () => {
|
|
36
|
+
const waitMap = new WaitableMap();
|
|
37
|
+
class TestStruct {
|
|
38
|
+
}
|
|
39
|
+
let promise = waitMap.get(TestStruct);
|
|
40
|
+
waitMap.resolve(TestStruct, 4);
|
|
41
|
+
await promise;
|
|
42
|
+
});
|
|
43
|
+
test("Edited classes can be matched keys in waitmap", async () => {
|
|
44
|
+
const waitMap = new WaitableMap();
|
|
45
|
+
class TestStruct {
|
|
46
|
+
}
|
|
47
|
+
let promise = waitMap.get(TestStruct);
|
|
48
|
+
let edited = Struct(version)(TestStruct);
|
|
49
|
+
waitMap.resolve(edited, 4);
|
|
50
|
+
await promise;
|
|
51
|
+
});
|
|
52
|
+
test("Can register a replicable", async () => {
|
|
53
|
+
let old = Configurer.CacheClassProperties;
|
|
54
|
+
let watch = Configurer.CacheClassProperties = fn();
|
|
55
|
+
Progress.ClearCaches();
|
|
56
|
+
const testObj = {
|
|
57
|
+
classConstructor: { name: "Test" },
|
|
58
|
+
opts: { dataTypeName: "test", typescriptTypeName: "TSTest" },
|
|
59
|
+
isPrimitive() {
|
|
60
|
+
return false;
|
|
61
|
+
},
|
|
62
|
+
onComplete() { }
|
|
63
|
+
};
|
|
64
|
+
Progress.FinishReplicableType(testObj);
|
|
65
|
+
let promise1 = (Progress.AwaitReplicableFor(testObj.classConstructor));
|
|
66
|
+
let promise2 = (Progress.AwaitReplicableFor(testObj.opts.dataTypeName));
|
|
67
|
+
let promise3 = (Progress.AwaitReplicableFor(testObj.opts.typescriptTypeName));
|
|
68
|
+
Progress.FinishedAllLoading();
|
|
69
|
+
let result = ReplicableRegistry.__GetReplicablesFor(testObj.classConstructor)[0];
|
|
70
|
+
expect(result, "Get replicable from class.").toBe(testObj);
|
|
71
|
+
result = ReplicableRegistry.__GetReplicablesFor(testObj.opts.dataTypeName)[0];
|
|
72
|
+
expect(result, "Get replicable from data name.").toBe(testObj);
|
|
73
|
+
result = ReplicableRegistry.__GetReplicablesFor(testObj.opts.typescriptTypeName)[0];
|
|
74
|
+
expect(result, "Get replicable from class name.").toBe(testObj);
|
|
75
|
+
let promise1result = await promise1;
|
|
76
|
+
expect(promise1result[0], "Get replicable from class async before load.").toBe(testObj);
|
|
77
|
+
let promise2result = await promise2;
|
|
78
|
+
expect(promise2result[0], "Get replicable from data name async before load.").toBe(testObj);
|
|
79
|
+
let promise3result = await promise3;
|
|
80
|
+
expect(promise3result[0], "Get replicable from class name async before load.").toBe(testObj);
|
|
81
|
+
let afterPromise = (await Progress.AwaitReplicableFor(testObj.classConstructor));
|
|
82
|
+
expect(afterPromise ? afterPromise[0] : undefined, "Get replicable from class async after load.").toBe(testObj);
|
|
83
|
+
afterPromise = (await Progress.AwaitReplicableFor(testObj.opts.dataTypeName));
|
|
84
|
+
expect(afterPromise ? afterPromise[0] : undefined, "Get replicable from data name async after load.").toBe(testObj);
|
|
85
|
+
afterPromise = (await Progress.AwaitReplicableFor(testObj.opts.typescriptTypeName));
|
|
86
|
+
expect(afterPromise ? afterPromise[0] : undefined, "Get replicable from class name async after load.").toBe(testObj);
|
|
87
|
+
Configurer.CacheClassProperties = old;
|
|
88
|
+
});
|
|
89
|
+
test("Struct is registered in registry and can be awaited by returned class.", async () => {
|
|
90
|
+
Progress.ClearCaches();
|
|
91
|
+
class TestStruct {
|
|
92
|
+
}
|
|
93
|
+
let edited = Struct(version)(TestStruct);
|
|
94
|
+
setTimeout(Progress.FinishedAllLoading, 1);
|
|
95
|
+
let promise = Progress.AwaitReplicableFor(edited);
|
|
96
|
+
await promise;
|
|
97
|
+
expect(true).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
test("Struct is registered in registry and can be awaited by original class.", async () => {
|
|
100
|
+
Progress.ClearCaches();
|
|
101
|
+
class TestStruct {
|
|
102
|
+
}
|
|
103
|
+
let promise = Progress.AwaitReplicableFor(TestStruct);
|
|
104
|
+
let edited = Struct(version)(TestStruct);
|
|
105
|
+
Progress.FinishedAllLoading();
|
|
106
|
+
await promise;
|
|
107
|
+
expect(true).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
test("Property.setParent adds itself to type.", async () => {
|
|
110
|
+
Progress.ClearCaches();
|
|
111
|
+
class TestStruct {
|
|
112
|
+
}
|
|
113
|
+
let edited = Struct(version)(TestStruct);
|
|
114
|
+
setTimeout(Progress.FinishedAllLoading, 1);
|
|
115
|
+
expect(edited).not.toBeUndefined();
|
|
116
|
+
let def = (await Progress.AwaitReplicableFor(TestStruct))[0];
|
|
117
|
+
expect([...Object.values(def.properties.all(version))]).toHaveLength(0);
|
|
118
|
+
def.addProperty(version, "prop", { type: [{ type: [String] }] });
|
|
119
|
+
expect([...Object.values(def.properties.all(version))]).toHaveLength(1);
|
|
120
|
+
});
|
|
121
|
+
test("Adding @Property to @Struct adds the property to the type's list of properties.", async () => {
|
|
122
|
+
Progress.ClearCaches();
|
|
123
|
+
class TestStruct {
|
|
124
|
+
}
|
|
125
|
+
let edited = Struct(version)(TestStruct);
|
|
126
|
+
setTimeout(Progress.FinishedAllLoading, 1);
|
|
127
|
+
expect(edited).not.toBeUndefined();
|
|
128
|
+
expect(edited).toBe(TestStruct);
|
|
129
|
+
let result = Property(version, String)(TestStruct.prototype, "prop");
|
|
130
|
+
let def = (await Progress.AwaitReplicableFor(TestStruct))[0];
|
|
131
|
+
await new Promise((res) => setTimeout(res, 10));
|
|
132
|
+
expect([...Object.values(def.finalised_properties.get(version))]).toHaveLength(1);
|
|
133
|
+
});
|
|
134
|
+
test("Type is created.", () => {
|
|
135
|
+
Progress.ClearCaches();
|
|
136
|
+
let TestType = class TestClass {
|
|
137
|
+
};
|
|
138
|
+
TestType.Reference = function (value) {
|
|
139
|
+
return ["First"];
|
|
140
|
+
};
|
|
141
|
+
TestType.Dereference = function (value) {
|
|
142
|
+
return null;
|
|
143
|
+
};
|
|
144
|
+
// TestType.IsType = function(value: any): value is TestObject {
|
|
145
|
+
// return value instanceof TestType;
|
|
146
|
+
// }
|
|
147
|
+
let edited = Type(version)(TestType);
|
|
148
|
+
Progress.FinishedAllLoading();
|
|
149
|
+
expect(edited).not.toBeUndefined();
|
|
150
|
+
let def = ReplicableRegistry.__GetReplicablesFor(edited)[0];
|
|
151
|
+
expect(def).not.toBeUndefined();
|
|
152
|
+
expect(def.opts.dataTypeName).toBe("TestClass");
|
|
153
|
+
expect(def.classConstructor).toBe(edited);
|
|
154
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,283 @@
|
|
|
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 { MixableClass } from "@bikky/compiler/Libraries/MixinCode.mjs";
|
|
8
|
+
import { beforeAll, expect, test } from "vitest";
|
|
9
|
+
import { AddVersion, Versions } from "../Constants/Versions.js";
|
|
10
|
+
import { Replicable } from "../Replicatable.js";
|
|
11
|
+
import { Struct } from "../Tracking/Class.js";
|
|
12
|
+
import { Property } from "../Tracking/Property.js";
|
|
13
|
+
import { Progress } from "../Transformers/Progress.js";
|
|
14
|
+
let version = "version";
|
|
15
|
+
beforeAll(() => {
|
|
16
|
+
AddVersion(version, Versions.v1_0_0);
|
|
17
|
+
});
|
|
18
|
+
test("Serialise Class", () => {
|
|
19
|
+
Progress.ClearCaches();
|
|
20
|
+
let Serialise_Test_1 = class Serialise_Test_1 {
|
|
21
|
+
};
|
|
22
|
+
Serialise_Test_1 = __decorate([
|
|
23
|
+
Struct(version)
|
|
24
|
+
], Serialise_Test_1);
|
|
25
|
+
Progress.FinishedAllLoading();
|
|
26
|
+
let testObject = new Serialise_Test_1();
|
|
27
|
+
let serialised = Replicable.Serialise(testObject);
|
|
28
|
+
expect(serialised).toStrictEqual([Serialise_Test_1.name, { version }]);
|
|
29
|
+
});
|
|
30
|
+
test("Serialise Class with String prop", () => {
|
|
31
|
+
Progress.ClearCaches();
|
|
32
|
+
let Serialise_Test_2 = class Serialise_Test_2 {
|
|
33
|
+
constructor() {
|
|
34
|
+
this.prop = "Hello";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
__decorate([
|
|
38
|
+
Property(version, String)
|
|
39
|
+
], Serialise_Test_2.prototype, "prop", void 0);
|
|
40
|
+
Serialise_Test_2 = __decorate([
|
|
41
|
+
Struct(version)
|
|
42
|
+
], Serialise_Test_2);
|
|
43
|
+
Progress.FinishedAllLoading();
|
|
44
|
+
let testObject = new Serialise_Test_2();
|
|
45
|
+
let serialised = Replicable.Serialise(testObject);
|
|
46
|
+
expect(serialised).toStrictEqual([Serialise_Test_2.name, { prop: ["Primitive", "Hello"], version }]);
|
|
47
|
+
});
|
|
48
|
+
test("Serialise Class with String | Number prop", () => {
|
|
49
|
+
Progress.ClearCaches();
|
|
50
|
+
let Serialise_Test_3 = class Serialise_Test_3 {
|
|
51
|
+
constructor() {
|
|
52
|
+
this.prop = "Hello";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
__decorate([
|
|
56
|
+
Property(version, [String, Number])
|
|
57
|
+
], Serialise_Test_3.prototype, "prop", void 0);
|
|
58
|
+
Serialise_Test_3 = __decorate([
|
|
59
|
+
Struct(version)
|
|
60
|
+
], Serialise_Test_3);
|
|
61
|
+
Progress.FinishedAllLoading();
|
|
62
|
+
let testObject = new Serialise_Test_3();
|
|
63
|
+
let serialised = Replicable.Serialise(testObject);
|
|
64
|
+
expect(serialised).toStrictEqual([Serialise_Test_3.name, { prop: ["Primitive", "Hello"], version }]);
|
|
65
|
+
});
|
|
66
|
+
test("Serialise Class with Dict prop", () => {
|
|
67
|
+
Progress.ClearCaches();
|
|
68
|
+
let Serialise_Test_3b = class Serialise_Test_3b {
|
|
69
|
+
constructor() {
|
|
70
|
+
this.prop = { hello: "world" };
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
__decorate([
|
|
74
|
+
Property(version, { type: String, dictKey: String })
|
|
75
|
+
], Serialise_Test_3b.prototype, "prop", void 0);
|
|
76
|
+
Serialise_Test_3b = __decorate([
|
|
77
|
+
Struct(version)
|
|
78
|
+
], Serialise_Test_3b);
|
|
79
|
+
Progress.FinishedAllLoading();
|
|
80
|
+
let testObject = new Serialise_Test_3b();
|
|
81
|
+
let serialised = Replicable.Serialise(testObject);
|
|
82
|
+
expect(serialised).toStrictEqual([Serialise_Test_3b.name, {
|
|
83
|
+
prop: ["Dict", { hello: ["Primitive", "world"] }],
|
|
84
|
+
version
|
|
85
|
+
}]);
|
|
86
|
+
});
|
|
87
|
+
test("Serialise Class with Map prop", () => {
|
|
88
|
+
Progress.ClearCaches();
|
|
89
|
+
let Serialise_Test_4 = class Serialise_Test_4 {
|
|
90
|
+
constructor() {
|
|
91
|
+
this.prop = new Map([["hello", "world"]]);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
__decorate([
|
|
95
|
+
Property(version, { type: String, mapKey: String })
|
|
96
|
+
], Serialise_Test_4.prototype, "prop", void 0);
|
|
97
|
+
Serialise_Test_4 = __decorate([
|
|
98
|
+
Struct(version)
|
|
99
|
+
], Serialise_Test_4);
|
|
100
|
+
Progress.FinishedAllLoading();
|
|
101
|
+
let testObject = new Serialise_Test_4();
|
|
102
|
+
let serialised = Replicable.Serialise(testObject);
|
|
103
|
+
expect(serialised).toStrictEqual([Serialise_Test_4.name, {
|
|
104
|
+
prop: ["Map", { hello: ["Primitive", "world"] }],
|
|
105
|
+
version
|
|
106
|
+
}]);
|
|
107
|
+
});
|
|
108
|
+
test("Serialise Class with Array prop", () => {
|
|
109
|
+
Progress.ClearCaches();
|
|
110
|
+
let Serialise_Test_5 = class Serialise_Test_5 {
|
|
111
|
+
constructor() {
|
|
112
|
+
this.prop = ["Hello", "World"];
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
__decorate([
|
|
116
|
+
Property(version, { type: String, array: true })
|
|
117
|
+
], Serialise_Test_5.prototype, "prop", void 0);
|
|
118
|
+
Serialise_Test_5 = __decorate([
|
|
119
|
+
Struct(version)
|
|
120
|
+
], Serialise_Test_5);
|
|
121
|
+
Progress.FinishedAllLoading();
|
|
122
|
+
let testObject = new Serialise_Test_5();
|
|
123
|
+
let serialised = Replicable.Serialise(testObject);
|
|
124
|
+
expect(serialised).toStrictEqual([Serialise_Test_5.name, {
|
|
125
|
+
prop: ["Array", [["Primitive", "Hello"], ["Primitive", "World"]]],
|
|
126
|
+
version
|
|
127
|
+
}]);
|
|
128
|
+
});
|
|
129
|
+
test("Serialise Class with two props", () => {
|
|
130
|
+
Progress.ClearCaches();
|
|
131
|
+
let Serialise_Test_6 = class Serialise_Test_6 {
|
|
132
|
+
constructor() {
|
|
133
|
+
this.propOne = "Hello";
|
|
134
|
+
this.propTwo = "World";
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
__decorate([
|
|
138
|
+
Property(version, String)
|
|
139
|
+
], Serialise_Test_6.prototype, "propOne", void 0);
|
|
140
|
+
__decorate([
|
|
141
|
+
Property(version, String)
|
|
142
|
+
], Serialise_Test_6.prototype, "propTwo", void 0);
|
|
143
|
+
Serialise_Test_6 = __decorate([
|
|
144
|
+
Struct(version)
|
|
145
|
+
], Serialise_Test_6);
|
|
146
|
+
Progress.FinishedAllLoading();
|
|
147
|
+
let testObject = new Serialise_Test_6();
|
|
148
|
+
let serialised = Replicable.Serialise(testObject);
|
|
149
|
+
expect(serialised).toStrictEqual([Serialise_Test_6.name, {
|
|
150
|
+
propOne: ["Primitive", "Hello"],
|
|
151
|
+
propTwo: ["Primitive", "World"],
|
|
152
|
+
version
|
|
153
|
+
}]);
|
|
154
|
+
});
|
|
155
|
+
test("Serialise Class with class prop", () => {
|
|
156
|
+
Progress.ClearCaches();
|
|
157
|
+
let Serialised_Subtest_6 = class Serialised_Subtest_6 {
|
|
158
|
+
constructor() {
|
|
159
|
+
this.propOne = "Hello";
|
|
160
|
+
this.propTwo = "World";
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
__decorate([
|
|
164
|
+
Property(version, String)
|
|
165
|
+
], Serialised_Subtest_6.prototype, "propOne", void 0);
|
|
166
|
+
__decorate([
|
|
167
|
+
Property(version, String)
|
|
168
|
+
], Serialised_Subtest_6.prototype, "propTwo", void 0);
|
|
169
|
+
Serialised_Subtest_6 = __decorate([
|
|
170
|
+
Struct(version)
|
|
171
|
+
], Serialised_Subtest_6);
|
|
172
|
+
let Serialise_Test_6 = class Serialise_Test_6 {
|
|
173
|
+
constructor() {
|
|
174
|
+
this.prop = new Serialised_Subtest_6();
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
__decorate([
|
|
178
|
+
Property(version, Serialised_Subtest_6)
|
|
179
|
+
], Serialise_Test_6.prototype, "prop", void 0);
|
|
180
|
+
Serialise_Test_6 = __decorate([
|
|
181
|
+
Struct(version)
|
|
182
|
+
], Serialise_Test_6);
|
|
183
|
+
Progress.FinishedAllLoading();
|
|
184
|
+
let testObject = new Serialise_Test_6();
|
|
185
|
+
let serialised = Replicable.Serialise(testObject);
|
|
186
|
+
expect(serialised).toStrictEqual([Serialise_Test_6.name,
|
|
187
|
+
{
|
|
188
|
+
prop: [Serialised_Subtest_6.name, {
|
|
189
|
+
propOne: ["Primitive", "Hello"],
|
|
190
|
+
propTwo: ["Primitive", "World"],
|
|
191
|
+
version
|
|
192
|
+
}],
|
|
193
|
+
version
|
|
194
|
+
}]);
|
|
195
|
+
});
|
|
196
|
+
test("Serialise Child class with parent and child props", () => {
|
|
197
|
+
Progress.ClearCaches();
|
|
198
|
+
let Serialised_ParentTest_7 = class Serialised_ParentTest_7 {
|
|
199
|
+
constructor() {
|
|
200
|
+
this.propOne = "Hello";
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
__decorate([
|
|
204
|
+
Property(version, String)
|
|
205
|
+
], Serialised_ParentTest_7.prototype, "propOne", void 0);
|
|
206
|
+
Serialised_ParentTest_7 = __decorate([
|
|
207
|
+
Struct(version)
|
|
208
|
+
], Serialised_ParentTest_7);
|
|
209
|
+
let Serialise_ChildTest_7 = class Serialise_ChildTest_7 extends Serialised_ParentTest_7 {
|
|
210
|
+
constructor() {
|
|
211
|
+
super(...arguments);
|
|
212
|
+
this.propTwo = "World";
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
__decorate([
|
|
216
|
+
Property(version, String)
|
|
217
|
+
], Serialise_ChildTest_7.prototype, "propTwo", void 0);
|
|
218
|
+
Serialise_ChildTest_7 = __decorate([
|
|
219
|
+
Struct(version)
|
|
220
|
+
], Serialise_ChildTest_7);
|
|
221
|
+
Progress.FinishedAllLoading();
|
|
222
|
+
let testObject = new Serialise_ChildTest_7();
|
|
223
|
+
let serObject = Replicable.Serialise(testObject);
|
|
224
|
+
expect(serObject).toStrictEqual([
|
|
225
|
+
Serialise_ChildTest_7.name,
|
|
226
|
+
{
|
|
227
|
+
propOne: ["Primitive", "Hello"],
|
|
228
|
+
propTwo: ["Primitive", "World"],
|
|
229
|
+
version
|
|
230
|
+
},
|
|
231
|
+
]);
|
|
232
|
+
});
|
|
233
|
+
test("Serialise Child mixin with parent and child prop", () => {
|
|
234
|
+
Progress.ClearCaches();
|
|
235
|
+
let Serialised_ParentTest_7 = class Serialised_ParentTest_7 {
|
|
236
|
+
constructor() {
|
|
237
|
+
this.propOne = "Hello";
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
__decorate([
|
|
241
|
+
Property(version, String)
|
|
242
|
+
], Serialised_ParentTest_7.prototype, "propOne", void 0);
|
|
243
|
+
Serialised_ParentTest_7 = __decorate([
|
|
244
|
+
Struct(version)
|
|
245
|
+
], Serialised_ParentTest_7);
|
|
246
|
+
let Serialise_ChildTest_7 = class Serialise_ChildTest_7 extends MixableClass(Serialised_ParentTest_7) {
|
|
247
|
+
constructor() {
|
|
248
|
+
super(...arguments);
|
|
249
|
+
this.propTwo = "World";
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
__decorate([
|
|
253
|
+
Property(version, String)
|
|
254
|
+
], Serialise_ChildTest_7.prototype, "propTwo", void 0);
|
|
255
|
+
Serialise_ChildTest_7 = __decorate([
|
|
256
|
+
Struct(version)
|
|
257
|
+
], Serialise_ChildTest_7);
|
|
258
|
+
const mixedClass = makeMixer(Serialise_ChildTest_7, Serialised_ParentTest_7)(Serialised_ParentTest_7);
|
|
259
|
+
let Serialise_FinalTest_7 = class Serialise_FinalTest_7 extends mixedClass {
|
|
260
|
+
constructor() {
|
|
261
|
+
super(...arguments);
|
|
262
|
+
this.propThree = "!";
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
__decorate([
|
|
266
|
+
Property(version, String)
|
|
267
|
+
], Serialise_FinalTest_7.prototype, "propThree", void 0);
|
|
268
|
+
Serialise_FinalTest_7 = __decorate([
|
|
269
|
+
Struct(version)
|
|
270
|
+
], Serialise_FinalTest_7);
|
|
271
|
+
Progress.FinishedAllLoading();
|
|
272
|
+
let testObject = new Serialise_FinalTest_7();
|
|
273
|
+
let serObject = Replicable.Serialise(testObject);
|
|
274
|
+
expect(serObject).toStrictEqual([
|
|
275
|
+
Serialise_FinalTest_7.name,
|
|
276
|
+
{
|
|
277
|
+
propOne: ["Primitive", "Hello"],
|
|
278
|
+
propTwo: ["Primitive", "World"],
|
|
279
|
+
propThree: ["Primitive", "!"],
|
|
280
|
+
version
|
|
281
|
+
},
|
|
282
|
+
]);
|
|
283
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bikky/replication",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A library for handling loading, saving, loading human readable content and transferring information over the network (from server to clients).",
|
|
5
|
+
"main": "Main.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "vitest"
|
|
8
|
+
},
|
|
9
|
+
"author": "Griffork",
|
|
10
|
+
"license": "SEE LICENSE IN license.txt",
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"typescript": "^5.8.2"
|
|
13
|
+
}
|
|
14
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compileOnSave": true,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"target": "es2017",
|
|
6
|
+
"lib": [ "ES2020", "ES2016.Array.Include", "dom" ],
|
|
7
|
+
"sourceMap": false,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"experimentalDecorators": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipDefaultLibCheck": true,
|
|
13
|
+
"moduleResolution": "Node",
|
|
14
|
+
"baseUrl": "./"
|
|
15
|
+
},
|
|
16
|
+
"exclude": [
|
|
17
|
+
"**/node_modules"
|
|
18
|
+
]
|
|
19
|
+
}
|