@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.
Files changed (140) hide show
  1. package/Constants/Errors.d.ts +27 -0
  2. package/Constants/Errors.js +75 -0
  3. package/Constants/Logging.d.ts +17 -0
  4. package/Constants/Logging.js +97 -0
  5. package/Constants/ReplicableRegistry.d.ts +37 -0
  6. package/Constants/ReplicableRegistry.js +234 -0
  7. package/Constants/SerialisationTypes.d.ts +82 -0
  8. package/Constants/SerialisationTypes.js +160 -0
  9. package/Constants/SourceMaps.d.ts +10 -0
  10. package/Constants/SourceMaps.js +12 -0
  11. package/Constants/TraversalStep.d.ts +5 -0
  12. package/Constants/TraversalStep.js +2 -0
  13. package/Constants/Versions.d.ts +15 -0
  14. package/Constants/Versions.js +63 -0
  15. package/Expressions/Compiler/BuiltinGrammar.d.ts +234 -0
  16. package/Expressions/Compiler/BuiltinGrammar.js +446 -0
  17. package/Expressions/Compiler/ExpressionGrammar.d.ts +89 -0
  18. package/Expressions/Compiler/ExpressionGrammar.js +70 -0
  19. package/Expressions/Compiler/Parser.d.ts +56 -0
  20. package/Expressions/Compiler/Parser.js +314 -0
  21. package/Expressions/Compiler/Tokenizer.d.ts +52 -0
  22. package/Expressions/Compiler/Tokenizer.js +222 -0
  23. package/Expressions/Compiler/__tests__/Replicable.Expressions.Parser.test.d.ts +1 -0
  24. package/Expressions/Compiler/__tests__/Replicable.Expressions.Parser.test.js +516 -0
  25. package/Expressions/Compiler/__tests__/Replicable.Expressions.Tokenizer.test.d.ts +1 -0
  26. package/Expressions/Compiler/__tests__/Replicable.Expressions.Tokenizer.test.js +68 -0
  27. package/Expressions/CreateEvaluator.d.ts +4 -0
  28. package/Expressions/CreateEvaluator.js +85 -0
  29. package/Expressions/EvaluatorChain.d.ts +19 -0
  30. package/Expressions/EvaluatorChain.js +137 -0
  31. package/Expressions/EvaluatorSteps.d.ts +19 -0
  32. package/Expressions/EvaluatorSteps.js +12 -0
  33. package/Expressions/EvaluatorString.d.ts +21 -0
  34. package/Expressions/EvaluatorString.js +26 -0
  35. package/Expressions/Expression.d.ts +36 -0
  36. package/Expressions/Expression.js +147 -0
  37. package/Expressions/Traverser.d.ts +28 -0
  38. package/Expressions/Traverser.js +348 -0
  39. package/Expressions/TypeRegistry/Accessors.d.ts +26 -0
  40. package/Expressions/TypeRegistry/Accessors.js +58 -0
  41. package/Expressions/TypeRegistry/ChainCollections.d.ts +51 -0
  42. package/Expressions/TypeRegistry/ChainCollections.js +134 -0
  43. package/Expressions/TypeRegistry/ChainTypes.d.ts +23 -0
  44. package/Expressions/TypeRegistry/ChainTypes.js +46 -0
  45. package/Expressions/TypeRegistry/CustomAPI.d.ts +36 -0
  46. package/Expressions/TypeRegistry/CustomAPI.js +181 -0
  47. package/Expressions/TypeRegistry/Primitive.d.ts +19 -0
  48. package/Expressions/TypeRegistry/Primitive.js +47 -0
  49. package/Expressions/TypeRegistry/Registry.d.ts +27 -0
  50. package/Expressions/TypeRegistry/Registry.js +270 -0
  51. package/Expressions/TypeRegistry/ReplAPI.d.ts +41 -0
  52. package/Expressions/TypeRegistry/ReplAPI.js +220 -0
  53. package/Expressions/TypeRegistry/Scope.d.ts +24 -0
  54. package/Expressions/TypeRegistry/Scope.js +44 -0
  55. package/Expressions/TypeRegistry/Types.d.ts +23 -0
  56. package/Expressions/TypeRegistry/Types.js +1 -0
  57. package/Expressions/TypeRegistry/__tests__/Replicable.Expressions.Accessors.test.d.ts +1 -0
  58. package/Expressions/TypeRegistry/__tests__/Replicable.Expressions.Accessors.test.js +31 -0
  59. package/Expressions/__tests__/ExpressionExamples.d.ts +28 -0
  60. package/Expressions/__tests__/ExpressionExamples.js +50 -0
  61. package/Expressions/__tests__/Replicable.Expressions.Expressions.test.d.ts +1 -0
  62. package/Expressions/__tests__/Replicable.Expressions.Expressions.test.js +166 -0
  63. package/IDPool.d.ts +18 -0
  64. package/IDPool.data.d.ts +17 -0
  65. package/IDPool.js +139 -0
  66. package/License.txt +1 -0
  67. package/Main.d.ts +13 -0
  68. package/Main.js +13 -0
  69. package/Networking.d.ts +60 -0
  70. package/Networking.js +626 -0
  71. package/Replicatable.d.ts +66 -0
  72. package/Replicatable.js +123 -0
  73. package/Tracking/Buffable.d.ts +68 -0
  74. package/Tracking/Buffable.js +194 -0
  75. package/Tracking/Class.d.ts +97 -0
  76. package/Tracking/Class.js +221 -0
  77. package/Tracking/Functions.d.ts +14 -0
  78. package/Tracking/Functions.js +27 -0
  79. package/Tracking/GlobalGroup.d.ts +5 -0
  80. package/Tracking/GlobalGroup.js +39 -0
  81. package/Tracking/Property.d.ts +95 -0
  82. package/Tracking/Property.js +125 -0
  83. package/Tracking/Types.d.ts +33 -0
  84. package/Tracking/Types.js +1 -0
  85. package/Tracking/__tests__/Replicable.Tracking.Decorator.test.d.ts +1 -0
  86. package/Tracking/__tests__/Replicable.Tracking.Decorator.test.js +151 -0
  87. package/Tracking/__tests__/Replicable.Tracking.Deserialisation.test.d.ts +1 -0
  88. package/Tracking/__tests__/Replicable.Tracking.Deserialisation.test.js +253 -0
  89. package/Tracking/__tests__/Replicable.Tracking.MixinSchemaGeneration.test.d.ts +1 -0
  90. package/Tracking/__tests__/Replicable.Tracking.MixinSchemaGeneration.test.js +135 -0
  91. package/Tracking/__tests__/Replicable.Tracking.Struct.test.d.ts +1 -0
  92. package/Tracking/__tests__/Replicable.Tracking.Struct.test.js +66 -0
  93. package/Tracking/__tests__/Replicable.Tracking.Type.test.d.ts +1 -0
  94. package/Tracking/__tests__/Replicable.Tracking.Type.test.js +67 -0
  95. package/Transformers/Configurer.d.ts +39 -0
  96. package/Transformers/Configurer.js +415 -0
  97. package/Transformers/Constructor.d.ts +12 -0
  98. package/Transformers/Constructor.js +44 -0
  99. package/Transformers/Definitions.d.ts +102 -0
  100. package/Transformers/Definitions.js +626 -0
  101. package/Transformers/Loader.d.ts +45 -0
  102. package/Transformers/Loader.js +350 -0
  103. package/Transformers/Progress.d.ts +32 -0
  104. package/Transformers/Progress.js +429 -0
  105. package/Transformers/Reference.d.ts +37 -0
  106. package/Transformers/Reference.js +212 -0
  107. package/Transformers/SchemaGenerator.d.ts +102 -0
  108. package/Transformers/SchemaGenerator.js +564 -0
  109. package/Transformers/Serialiser.d.ts +31 -0
  110. package/Transformers/Serialiser.js +366 -0
  111. package/Transformers/Utils.d.ts +33 -0
  112. package/Transformers/Utils.js +287 -0
  113. package/Transformers/__tests__/Examples.d.ts +168 -0
  114. package/Transformers/__tests__/Examples.js +263 -0
  115. package/Transformers/__tests__/Replicable.Transformers.Definitions.test.d.ts +1 -0
  116. package/Transformers/__tests__/Replicable.Transformers.Definitions.test.js +457 -0
  117. package/Transformers/__tests__/Replicable.Transformers.Loader.test.d.ts +1 -0
  118. package/Transformers/__tests__/Replicable.Transformers.Loader.test.js +339 -0
  119. package/Transformers/__tests__/Replicable.Transformers.Progress.test.d.ts +1 -0
  120. package/Transformers/__tests__/Replicable.Transformers.Progress.test.js +256 -0
  121. package/Transformers/__tests__/Replicable.Transformers.Reference.test.d.ts +1 -0
  122. package/Transformers/__tests__/Replicable.Transformers.Reference.test.js +167 -0
  123. package/Transformers/__tests__/Replicable.Transformers.SchemaGenerator.test.d.ts +1 -0
  124. package/Transformers/__tests__/Replicable.Transformers.SchemaGenerator.test.js +400 -0
  125. package/Transformers/__tests__/Replicable.Transformers.SchemaGeneratorOutput.test.d.ts +1 -0
  126. package/Transformers/__tests__/Replicable.Transformers.SchemaGeneratorOutput.test.js +441 -0
  127. package/Transformers/__tests__/Replicable.Transformers.Serialiser.test.d.ts +1 -0
  128. package/Transformers/__tests__/Replicable.Transformers.Serialiser.test.js +320 -0
  129. package/Transformers/__tests__/Replicable.Transformers.Utils.test.d.ts +1 -0
  130. package/Transformers/__tests__/Replicable.Transformers.Utils.test.js +534 -0
  131. package/__tests__/Replicable.Expressions.test.d.ts +1 -0
  132. package/__tests__/Replicable.Expressions.test.js +166 -0
  133. package/__tests__/Replicable.IDPool.test.d.ts +1 -0
  134. package/__tests__/Replicable.IDPool.test.js +11 -0
  135. package/__tests__/Replicable.ReplicableRegistry.test.d.ts +1 -0
  136. package/__tests__/Replicable.ReplicableRegistry.test.js +154 -0
  137. package/__tests__/Replicable.Serialisation.test.d.ts +1 -0
  138. package/__tests__/Replicable.Serialisation.test.js +283 -0
  139. package/package.json +14 -0
  140. package/tsconfig.json +19 -0
@@ -0,0 +1,39 @@
1
+ import { Versions } from "../Constants/Versions.js";
2
+ import { PropertyLoadingTypeInfo, PropertySerialiseTypeInfo } from "../Tracking/Property.js";
3
+ import { PropertyTypes } from "../Constants/SerialisationTypes.js";
4
+ import { ExpressionConfiguration } from "../Expressions/EvaluatorSteps.js";
5
+ import { FunctionConfiguration, PropertyDefinition, PropertyDoesntExist, PropertyRemoved, ReplicableClass } from "../Tracking/Class.js";
6
+ /**
7
+ * Handles the setup of the replicable class based on the configuration provided via the source code's decorators.
8
+ * Does some pre-caching of versioning information and other metadata.
9
+ */
10
+ export declare namespace Configurer {
11
+ type PartialPropDefs = Map<Versions | string, {
12
+ [name: string]: PropertyDefinition | PropertyRemoved;
13
+ }>;
14
+ type PartialFooDefs = Map<Versions | string, {
15
+ [name: string]: FunctionConfiguration | PropertyRemoved;
16
+ }>;
17
+ type PropDefs = Map<Versions | string, {
18
+ [name: string]: PropertyDefinition | PropertyRemoved | PropertyDoesntExist;
19
+ }>;
20
+ type FooDefs = Map<Versions | string, {
21
+ [name: string]: FunctionConfiguration | PropertyRemoved | PropertyDoesntExist;
22
+ }>;
23
+ function RecursivelyCacheParentProperties(source: ReplicableClass, current: ReplicableClass, propDefs: PartialPropDefs, fooDefs: PartialFooDefs): void;
24
+ function CacheOwnProperties(repl: ReplicableClass, propDefs: PartialPropDefs, fooDefs: PartialFooDefs): void;
25
+ function PropagatePropertyCacheForwardInVersions(repl: ReplicableClass, propDefs: PartialPropDefs, fooDefs: PartialFooDefs, computedPropDefs: PropDefs, computedFooDefs: FooDefs): void;
26
+ function PropagateMissingPropertiesBackwardInVersions(repl: ReplicableClass, computedPropDefs: PropDefs, computedFooDefs: FooDefs): void;
27
+ function ComputePropertyDefinitionConfiguration(prop: PropertyDefinition): readonly [PropertyLoadingTypeInfo[], PropertyTypes, boolean];
28
+ function ComputePropertySerialisedConfiguration(prop: PropertyDefinition, loadPresence: boolean | "optional", propAllowsUndefined: boolean): readonly [PropertySerialiseTypeInfo[], PropertyTypes, boolean];
29
+ function ComputePropertyExpressionConfiguration(repl: ReplicableClass, prop: PropertyDefinition, loadModifiers: PropertyTypes, loadTypes: PropertyLoadingTypeInfo[]): readonly [{
30
+ "1.0.0": ExpressionConfiguration;
31
+ } | undefined, {
32
+ "1.0.0": ExpressionConfiguration;
33
+ } | undefined, {
34
+ "1.0.0": ExpressionConfiguration;
35
+ } | undefined];
36
+ function ComputePropertyConfigurationsInVersion(repl: ReplicableClass, version: Versions | string, computedPropDefs: PropDefs): void;
37
+ function ComputeFunctionExpressionConfiguration(repl: ReplicableClass, version: Versions | string, computedFooDefs: FooDefs): void;
38
+ function CacheClassProperties(repl: ReplicableClass): void;
39
+ }
@@ -0,0 +1,415 @@
1
+ import { GetAllVersions } from "../Constants/Versions.js";
2
+ import { generateDataName, GetTypeName, isPrimitiveType, primitiveTypeName, PropertyTypes } from "../Constants/SerialisationTypes.js";
3
+ import { ReplicableRegistry } from "../Constants/ReplicableRegistry.js";
4
+ import { Utils } from "./Utils.js";
5
+ import { Expression } from "../Expressions/Expression.js";
6
+ import { ReplicableClass } from "../Tracking/Class.js";
7
+ /**
8
+ * Handles the setup of the replicable class based on the configuration provided via the source code's decorators.
9
+ * Does some pre-caching of versioning information and other metadata.
10
+ */
11
+ export var Configurer;
12
+ (function (Configurer) {
13
+ function RecursivelyCacheParentProperties(source, current, propDefs, fooDefs) {
14
+ var _a, _b;
15
+ let versions = GetAllVersions();
16
+ for (let parent of current.parents) {
17
+ // For each parent we need to add all of their properties to our own.
18
+ RecursivelyCacheParentProperties(source, parent, propDefs, fooDefs);
19
+ // Then iterate through our own properties and override the existing ones with our own.
20
+ for (let version of versions) {
21
+ let props = parent.properties.all(version);
22
+ let newProps = (_a = propDefs.get(version)) !== null && _a !== void 0 ? _a : {};
23
+ for (let [property, def] of Object.entries(props)) {
24
+ if (!source.finalised_propertyNames.includes(property)) {
25
+ source.finalised_propertyNames.push(property);
26
+ }
27
+ newProps[property] = def;
28
+ }
29
+ propDefs.set(version, newProps);
30
+ let foos = parent.functions.all(version);
31
+ let newFoos = (_b = fooDefs.get(version)) !== null && _b !== void 0 ? _b : {};
32
+ for (let [foo, def] of Object.entries(foos)) {
33
+ if (!source.finalised_functionNames.includes(foo)) {
34
+ source.finalised_functionNames.push(foo);
35
+ }
36
+ newFoos[foo] = def;
37
+ }
38
+ fooDefs.set(version, newFoos);
39
+ }
40
+ }
41
+ }
42
+ Configurer.RecursivelyCacheParentProperties = RecursivelyCacheParentProperties;
43
+ function CacheOwnProperties(repl, propDefs, fooDefs) {
44
+ var _a, _b;
45
+ let versions = GetAllVersions();
46
+ for (let version of versions) {
47
+ let props = repl.properties.all(version);
48
+ let new_props = (_a = propDefs.get(version)) !== null && _a !== void 0 ? _a : {};
49
+ for (let [property, def] of Object.entries(props)) {
50
+ if (!repl.finalised_propertyNames.includes(property)) {
51
+ repl.finalised_propertyNames.push(property);
52
+ }
53
+ if (!repl.finalised_ownPropertyNames.includes(property)) {
54
+ repl.finalised_ownPropertyNames.push(property);
55
+ }
56
+ new_props[property] = def;
57
+ }
58
+ propDefs.set(version, new_props);
59
+ let foos = repl.functions.all(version);
60
+ let new_foos = (_b = fooDefs.get(version)) !== null && _b !== void 0 ? _b : {};
61
+ for (let [foo, def] of Object.entries(foos)) {
62
+ if (!repl.finalised_functionNames.includes(foo)) {
63
+ repl.finalised_functionNames.push(foo);
64
+ }
65
+ if (!repl.finalised_ownFunctionNames.includes(foo)) {
66
+ repl.finalised_ownFunctionNames.push(foo);
67
+ }
68
+ new_foos[foo] = def;
69
+ }
70
+ fooDefs.set(version, new_foos);
71
+ }
72
+ repl.finalised_propertyNames.sort();
73
+ repl.finalised_ownPropertyNames.sort();
74
+ repl.finalised_functionNames.sort();
75
+ repl.finalised_ownFunctionNames.sort();
76
+ }
77
+ Configurer.CacheOwnProperties = CacheOwnProperties;
78
+ function PropagatePropertyCacheForwardInVersions(repl, propDefs, fooDefs, computedPropDefs, computedFooDefs) {
79
+ let carriedProps = {};
80
+ let carriedFoos = {};
81
+ let versions = GetAllVersions();
82
+ // Go through the versions forwards and propagate properties into the later versions if they don't exist.
83
+ for (let version of versions) {
84
+ let definedProps = propDefs.get(version);
85
+ let computedProps = computedPropDefs.get(version);
86
+ if (!definedProps)
87
+ definedProps = {};
88
+ if (!computedProps)
89
+ computedPropDefs.set(version, computedProps = {});
90
+ for (let name of repl.finalised_propertyNames) {
91
+ let prop = definedProps[name];
92
+ // If the property doesn't exist and hasn't existed, make an empty entry.
93
+ if (!prop && !carriedProps[name]) {
94
+ computedProps[name] = { version, property: name, doesntExist: true };
95
+ }
96
+ // If the property doesn't exist but has existed, use the existing definition.
97
+ else if (!prop) {
98
+ computedProps[name] = carriedProps[name];
99
+ }
100
+ // If the proeprty does exist, then use that and update the carry.
101
+ else {
102
+ carriedProps[name] = prop;
103
+ computedProps[name] = prop;
104
+ }
105
+ }
106
+ //Functions.
107
+ let definedFoos = fooDefs.get(version);
108
+ let computedFoos = computedFooDefs.get(version);
109
+ if (!definedFoos)
110
+ definedFoos = {};
111
+ if (!computedFoos)
112
+ computedFooDefs.set(version, computedFoos = {});
113
+ for (let name of repl.finalised_functionNames) {
114
+ let foo = definedFoos[name];
115
+ if (!foo && !carriedFoos[name]) {
116
+ computedFoos[name] = { version, property: name, doesntExist: true };
117
+ }
118
+ else if (!foo) {
119
+ computedFoos[name] = carriedFoos[name];
120
+ }
121
+ else {
122
+ carriedFoos[name] = foo;
123
+ computedFoos[name] = foo;
124
+ }
125
+ }
126
+ }
127
+ }
128
+ Configurer.PropagatePropertyCacheForwardInVersions = PropagatePropertyCacheForwardInVersions;
129
+ function PropagateMissingPropertiesBackwardInVersions(repl, computedPropDefs, computedFooDefs) {
130
+ // Go backwards through the versions and remember all migrations or deletions. Then apply them
131
+ // to the earlier versions.
132
+ let carriedProps = {};
133
+ let carriedFoos = {};
134
+ let carriedPropNames = {};
135
+ let carriedFooNames = {};
136
+ let versions = GetAllVersions().toReversed();
137
+ for (let version of versions) {
138
+ let props = computedPropDefs.get(version);
139
+ for (let name of repl.finalised_propertyNames) {
140
+ let prop = props[name];
141
+ if ("doesntExist" in prop) {
142
+ continue;
143
+ }
144
+ if (carriedProps[name] && "removed" in carriedProps[name]) {
145
+ //TODO: Update to allow for double-migrations.
146
+ prop = props[name] = carriedProps[name];
147
+ }
148
+ if (carriedPropNames[prop.dataName]) {
149
+ prop = props[name] = Object.assign(Object.assign({}, prop), { property: carriedPropNames[prop.dataName] });
150
+ }
151
+ if ("removed" in prop) {
152
+ carriedProps[name] = prop;
153
+ }
154
+ else {
155
+ carriedPropNames[prop.dataName] = name;
156
+ }
157
+ }
158
+ //Functions
159
+ let foos = computedFooDefs.get(version);
160
+ for (let name of repl.finalised_functionNames) {
161
+ let foo = foos[name];
162
+ if ("doesntExist" in foo) {
163
+ continue;
164
+ }
165
+ if (carriedFoos[name] && "removed" in carriedFoos[name]) {
166
+ foo = foos[name] = carriedProps[name];
167
+ }
168
+ if (carriedFooNames[foo.dataName]) {
169
+ foo = foos[name] = Object.assign(Object.assign({}, foo), { property: carriedFooNames[foo.dataName] });
170
+ }
171
+ if ("removed" in foo) {
172
+ carriedFoos[name] = foo;
173
+ }
174
+ else {
175
+ carriedFooNames[foo.dataName] = name;
176
+ }
177
+ }
178
+ }
179
+ }
180
+ Configurer.PropagateMissingPropertiesBackwardInVersions = PropagateMissingPropertiesBackwardInVersions;
181
+ function ComputeDefinitionModifiers(prop, typeDef) {
182
+ let key = undefined;
183
+ let modifiers = PropertyTypes.AsIs;
184
+ if ("array" in typeDef && typeDef.array == 2) {
185
+ modifiers |= PropertyTypes.Array2;
186
+ }
187
+ else if ("array" in typeDef && typeDef.array) {
188
+ modifiers |= PropertyTypes.Array;
189
+ }
190
+ else if ("mapKey" in typeDef) {
191
+ modifiers |= PropertyTypes.Map;
192
+ key = typeDef.mapKey;
193
+ }
194
+ else if ("dictKey" in typeDef) {
195
+ modifiers |= PropertyTypes.Dictionary;
196
+ key = typeDef.dictKey;
197
+ }
198
+ else {
199
+ modifiers |= PropertyTypes.Solo;
200
+ }
201
+ if (typeDef.data) {
202
+ modifiers |= PropertyTypes.Definition;
203
+ }
204
+ if (typeDef.serialised) {
205
+ modifiers |= PropertyTypes.Serialised;
206
+ }
207
+ if (prop.expression !== false) {
208
+ modifiers |= PropertyTypes.Expression;
209
+ }
210
+ return [modifiers, key];
211
+ }
212
+ function ComputeSerialisationModifiers(prop, typeDef) {
213
+ let modifiers = PropertyTypes.AsIs;
214
+ let key = undefined;
215
+ if ("array" in typeDef && typeDef.array == 2) {
216
+ modifiers |= PropertyTypes.Array2;
217
+ }
218
+ else if ("array" in typeDef && typeDef.array) {
219
+ modifiers |= PropertyTypes.Array;
220
+ }
221
+ else if ("mapKey" in typeDef) {
222
+ modifiers |= PropertyTypes.Map;
223
+ key = typeDef.mapKey;
224
+ }
225
+ else if ("dictKey" in typeDef) {
226
+ modifiers |= PropertyTypes.Dictionary;
227
+ key = typeDef.dictKey;
228
+ }
229
+ else {
230
+ modifiers |= PropertyTypes.Solo;
231
+ }
232
+ if (typeDef.data) {
233
+ modifiers |= PropertyTypes.Definition;
234
+ }
235
+ if (typeDef.serialised) {
236
+ modifiers |= PropertyTypes.Serialised;
237
+ }
238
+ if (prop.expression !== false) {
239
+ modifiers |= PropertyTypes.Expression;
240
+ }
241
+ if (prop.inline) {
242
+ modifiers |= PropertyTypes.ForceInline;
243
+ }
244
+ return [modifiers, key];
245
+ }
246
+ function ComputePropertyDefinitionConfiguration(prop) {
247
+ var _a;
248
+ let loadTypes = [];
249
+ let loadModifiers = PropertyTypes.AsIs;
250
+ let propAllowsUndefined = false;
251
+ let dataTypes = (_a = prop.customDataType) !== null && _a !== void 0 ? _a : prop.type;
252
+ for (let i = 0; i < dataTypes.length; i++) {
253
+ let typeDef = dataTypes[i];
254
+ let [modifiers, key] = ComputeDefinitionModifiers(prop, typeDef);
255
+ loadModifiers |= PropertyTypes.ModOnly(modifiers);
256
+ let result;
257
+ if (typeDef.type.length === 1 && typeof typeDef.type[0] == "string" && !ReplicableRegistry.GetTypesForName(typeDef.type[0])) {
258
+ result = typeDef.type[0];
259
+ }
260
+ else {
261
+ result = [];
262
+ for (let repl of typeDef.type) {
263
+ if (loadModifiers === PropertyTypes.Solo && typeDef.type === undefined) {
264
+ propAllowsUndefined = true;
265
+ }
266
+ let types = isPrimitiveType(repl) ? [repl] : ReplicableRegistry.__GetReplicablesFor(repl);
267
+ result.push(...types);
268
+ }
269
+ result.sort((a, b) => {
270
+ return GetTypeName(a) > GetTypeName(b) ? 1 : -1;
271
+ });
272
+ }
273
+ let namesForValues = (Array.isArray(result)
274
+ ? result.map((e) => e instanceof ReplicableClass
275
+ ? e.opts.dataTypeName : primitiveTypeName(e)) : [result]).sort();
276
+ loadTypes.push(Object.assign(Object.assign({ types: result, sortIndex: namesForValues.join(", "), modifiers }, (key ? { keyType: Array.isArray(key) ? key : [key] } : {})), ("restrictedTo" in typeDef ? { restrictedTo: typeDef.restrictedTo } : {})));
277
+ }
278
+ return [loadTypes, loadModifiers, propAllowsUndefined];
279
+ }
280
+ Configurer.ComputePropertyDefinitionConfiguration = ComputePropertyDefinitionConfiguration;
281
+ function ComputePropertySerialisedConfiguration(prop, loadPresence, propAllowsUndefined) {
282
+ let serTypes = [];
283
+ let serModifiers = PropertyTypes.AsIs;
284
+ //If the property is optional, add undefined to the list of allowed serialised types.
285
+ if (loadPresence === "optional") {
286
+ serTypes.push({
287
+ types: [undefined],
288
+ sortIndex: "undefined",
289
+ modifiers: prop.expression != false ? PropertyTypes.Solo | PropertyTypes.Expression : PropertyTypes.Solo
290
+ });
291
+ serModifiers |= PropertyTypes.Solo;
292
+ }
293
+ for (let i = 0; i < prop.type.length; i++) {
294
+ let typeDef = prop.type[i];
295
+ let [modifiers, key] = ComputeSerialisationModifiers(prop, typeDef);
296
+ serModifiers |= PropertyTypes.ModOnly(modifiers);
297
+ let result = [];
298
+ for (let repl of typeDef.type) {
299
+ if (serModifiers === PropertyTypes.Solo && typeDef.type === undefined) {
300
+ propAllowsUndefined = true;
301
+ }
302
+ let types = isPrimitiveType(repl) ? [repl] : ReplicableRegistry.__GetReplicablesFor(repl);
303
+ result.push(...types);
304
+ }
305
+ result.sort((a, b) => {
306
+ return GetTypeName(a) > GetTypeName(b) ? 1 : -1;
307
+ });
308
+ let namesForValues = (result.map((e) => e instanceof ReplicableClass
309
+ ? e.opts.dataTypeName : primitiveTypeName(e))).sort();
310
+ serTypes.push(Object.assign(Object.assign({ types: result, sortIndex: namesForValues.join(", "), modifiers }, (key ? { keyType: Array.isArray(key) ? key : [key] } : {})), ("restrictedTo" in typeDef ? { restrictedTo: typeDef.restrictedTo } : {})));
311
+ }
312
+ return [serTypes, serModifiers, propAllowsUndefined];
313
+ }
314
+ Configurer.ComputePropertySerialisedConfiguration = ComputePropertySerialisedConfiguration;
315
+ function ComputePropertyExpressionConfiguration(repl, prop, loadModifiers, loadTypes) {
316
+ let exprPropertyConf = undefined;
317
+ let exprValueConf = undefined;
318
+ let exprKeyConf = undefined;
319
+ if (prop.expression !== false) {
320
+ let conf = {};
321
+ let conf2 = {};
322
+ let conf3 = {};
323
+ for (let version of GetAllVersions()) {
324
+ conf[version] = Utils.ExpressionUtils.MakePropExpressionConfig(version, prop, repl.classConstructor);
325
+ conf2[version] = Object.assign({}, conf[version]);
326
+ conf2[version].outputMap = false;
327
+ conf2[version].outputArray = 0;
328
+ conf2[version].outputDict = false;
329
+ conf3[version] = Object.assign(Object.assign({}, conf2[version]), { outputTypes: ["any"] });
330
+ }
331
+ exprPropertyConf = conf;
332
+ exprValueConf = conf2;
333
+ if (PropertyTypes.isType(loadModifiers, PropertyTypes.Map) && loadTypes.some((e) => { var _a; return (_a = e.keyType) === null || _a === void 0 ? void 0 : _a.includes(Expression); })) {
334
+ exprKeyConf = conf3;
335
+ }
336
+ }
337
+ return [exprPropertyConf, exprValueConf, exprKeyConf];
338
+ }
339
+ Configurer.ComputePropertyExpressionConfiguration = ComputePropertyExpressionConfiguration;
340
+ function ComputePropertyConfigurationsInVersion(repl, version, computedPropDefs) {
341
+ var _a;
342
+ let props = computedPropDefs.get(version);
343
+ let finalisedProps = {};
344
+ repl.finalised_properties.set(version, finalisedProps);
345
+ let propAllowsUndefined = false;
346
+ for (let name of repl.finalised_propertyNames) {
347
+ let prop = props[name];
348
+ if ("doesntExist" in prop || "removed" in prop) {
349
+ finalisedProps[name] = prop;
350
+ repl.rule.addProperty(version, prop);
351
+ continue;
352
+ }
353
+ let loadPresence = prop.optional || ("default" in prop) || propAllowsUndefined ? "optional" : prop.computed == "manualLoad" ? true : !prop.computed;
354
+ let [loadTypes, loadModifiers, defAllowsUndefined] = ComputePropertyDefinitionConfiguration(prop);
355
+ propAllowsUndefined || (propAllowsUndefined = defAllowsUndefined);
356
+ let [serTypes, serModifiers, serAllowsUndefined] = ComputePropertySerialisedConfiguration(prop, loadPresence, propAllowsUndefined);
357
+ propAllowsUndefined || (propAllowsUndefined = serAllowsUndefined);
358
+ let [exprPropertyConf, exprValueConf, exprKeyConf] = ComputePropertyExpressionConfiguration(repl, prop, loadModifiers, loadTypes);
359
+ let def = finalisedProps[name] = {
360
+ name: name,
361
+ load: {
362
+ //If property is computed, if it has a default value it's actually optional.
363
+ present: loadPresence,
364
+ skipLoad: prop.computed == "manualLoad",
365
+ name: (_a = prop.dataName) !== null && _a !== void 0 ? _a : generateDataName(name),
366
+ default: prop.default,
367
+ possibleModifiers: loadModifiers,
368
+ types: loadTypes.sort((a, b) => a.sortIndex > b.sortIndex ? 1 : -1)
369
+ },
370
+ serialisation: {
371
+ present: prop.manualRestore ? "writeOnly" : !prop.readonly,
372
+ inline: prop.inline,
373
+ types: serTypes.sort((a, b) => a.sortIndex > b.sortIndex ? 1 : -1),
374
+ possibleModifiers: serModifiers
375
+ },
376
+ expressionForProperty: exprPropertyConf,
377
+ expressionForValue: exprValueConf,
378
+ expressionForKey: exprKeyConf
379
+ };
380
+ repl.rule.addProperty(version, def);
381
+ //TODO: Run definitions check to see if default is a valid value for property.
382
+ }
383
+ }
384
+ Configurer.ComputePropertyConfigurationsInVersion = ComputePropertyConfigurationsInVersion;
385
+ function ComputeFunctionExpressionConfiguration(repl, version, computedFooDefs) {
386
+ let foos = computedFooDefs.get(version);
387
+ let finalisedFoos = {};
388
+ repl.finalised_functions.set(version, finalisedFoos);
389
+ for (let name of repl.finalised_functionNames) {
390
+ let foo = foos[name];
391
+ if ("doesntExist" in foo || "removed" in foo) {
392
+ continue;
393
+ }
394
+ repl.rule.addFunction(version, { name: foo.funcName, exprName: foo.dataName }, foo.outputType, foo.parameters);
395
+ }
396
+ }
397
+ Configurer.ComputeFunctionExpressionConfiguration = ComputeFunctionExpressionConfiguration;
398
+ function CacheClassProperties(repl) {
399
+ let propDefs = new Map();
400
+ let fooDefs = new Map();
401
+ // Grab all the properties from the parents and create a flat map for them.
402
+ RecursivelyCacheParentProperties(repl, repl, propDefs, fooDefs);
403
+ CacheOwnProperties(repl, propDefs, fooDefs);
404
+ let computedPropDefs = new Map();
405
+ let computedFooDefs = new Map();
406
+ PropagatePropertyCacheForwardInVersions(repl, propDefs, fooDefs, computedPropDefs, computedFooDefs);
407
+ PropagateMissingPropertiesBackwardInVersions(repl, computedPropDefs, computedFooDefs);
408
+ let versions = GetAllVersions();
409
+ for (let version of versions) {
410
+ ComputePropertyConfigurationsInVersion(repl, version, computedPropDefs);
411
+ ComputeFunctionExpressionConfiguration(repl, version, computedFooDefs);
412
+ }
413
+ }
414
+ Configurer.CacheClassProperties = CacheClassProperties;
415
+ })(Configurer || (Configurer = {}));
@@ -0,0 +1,12 @@
1
+ import { SourceMap } from "../Constants/SourceMaps.js";
2
+ import { ReplicableClass } from "../Tracking/Class.js";
3
+ import type { Loader } from "./Loader.js";
4
+ import type { Serialiser } from "./Serialiser.js";
5
+ export declare namespace __PrivateConstructorSetup {
6
+ function RegisterDeserialiser(deserialiser: typeof Serialiser.Deserialise): void;
7
+ function RegisterInitialiser(initialiser: typeof Loader.InitFromData): void;
8
+ function RegisterHasBeenInitialised(initCheck: typeof Loader.HasObjectBeenInitialised): void;
9
+ }
10
+ export declare namespace Constructor {
11
+ function Construct(type: ReplicableClass, source: SourceMap, owner?: any, args?: any): any;
12
+ }
@@ -0,0 +1,44 @@
1
+ import { describeObject } from "../Constants/SerialisationTypes.js";
2
+ let Deserialise;
3
+ let InitFromData;
4
+ let HasObjectBeenInitialised;
5
+ export var __PrivateConstructorSetup;
6
+ (function (__PrivateConstructorSetup) {
7
+ function RegisterDeserialiser(deserialiser) {
8
+ Deserialise = deserialiser;
9
+ }
10
+ __PrivateConstructorSetup.RegisterDeserialiser = RegisterDeserialiser;
11
+ function RegisterInitialiser(initialiser) {
12
+ InitFromData = initialiser;
13
+ }
14
+ __PrivateConstructorSetup.RegisterInitialiser = RegisterInitialiser;
15
+ function RegisterHasBeenInitialised(initCheck) {
16
+ HasObjectBeenInitialised = initCheck;
17
+ }
18
+ __PrivateConstructorSetup.RegisterHasBeenInitialised = RegisterHasBeenInitialised;
19
+ })(__PrivateConstructorSetup || (__PrivateConstructorSetup = {}));
20
+ export var Constructor;
21
+ (function (Constructor) {
22
+ function Construct(type, source, owner, args) {
23
+ let result;
24
+ if ("Create" in type.classConstructor) {
25
+ result = type.classConstructor.Create({ data: args, source, owner });
26
+ }
27
+ else if ("Reference" in type.classConstructor) {
28
+ throw new Error(`Cannot construct ${type.opts.typescriptTypeName} for ${describeObject(owner)} because ${type.opts.typescriptTypeName} doesn't specify a static Create function.`);
29
+ }
30
+ else {
31
+ result = new type.classConstructor({ data: args, source, owner });
32
+ }
33
+ if (!HasObjectBeenInitialised(result)) {
34
+ if (Array.isArray(args) && args[0] === type.opts.dataTypeName && args.length == 2) {
35
+ return Deserialise(result, args);
36
+ }
37
+ else {
38
+ return InitFromData(type, source, result, args);
39
+ }
40
+ }
41
+ return result;
42
+ }
43
+ Constructor.Construct = Construct;
44
+ })(Constructor || (Constructor = {}));
@@ -0,0 +1,102 @@
1
+ import { SourceMap } from "../Constants/SourceMaps.js";
2
+ import { Expression } from "../Expressions/Expression.js";
3
+ import { PropertyTypes } from "../Constants/SerialisationTypes.js";
4
+ import { ErrorStack } from "../Constants/Errors.js";
5
+ import { EvaluationChain } from "../Expressions/EvaluatorChain.js";
6
+ import { EvaluationString } from "../Expressions/EvaluatorString.js";
7
+ import { ExpressionConfiguration } from "../Expressions/EvaluatorSteps.js";
8
+ import { Versions } from "../Main.js";
9
+ import { ReplicableClass } from "../Tracking/Class.js";
10
+ import { PropertyConfiguration, PropertyLoadingTypeInfo } from "../Tracking/Property.js";
11
+ export declare namespace Definitions {
12
+ /**
13
+ * Determines if the expression results matches the modifiers for the given property definition.
14
+ * Modifiers include array, map, dictionary and optional.
15
+ * @param errorContext The context to add to the error message, should be ClassName.PropertyName.
16
+ * @param def The property definition to check against.
17
+ * @param val The value to check.
18
+ * @param errorStack The error stack to add errors to.
19
+ */
20
+ function DoExprOutputsMatchPropertyModifier(errorContext: string, def: ExpressionConfiguration, val: Expression | EvaluationChain | EvaluationString, errorStack: ErrorStack): boolean;
21
+ /**
22
+ * Determines if the expression results match the types for the given property definition, ignores modifiers
23
+ * like array, map and dictionary.
24
+ * @param errorContext The context to add to the error message, should be ClassName.PropertyName.
25
+ * @param def The property definition to check against.
26
+ * @param propVal The value to check.
27
+ * @param errorStack The error stack to add errors to.
28
+ * @constructor
29
+ */
30
+ function DoExprOutputsMatchPropertyType(errorContext: string, def: ExpressionConfiguration, propVal: Expression | EvaluationChain | EvaluationString, errorStack: ErrorStack): boolean;
31
+ /**
32
+ * Determines if value matches the modifiers for the given property definition.
33
+ * Modifiers include array, map, dictionary and optional.
34
+ * Also checks map index requirements.
35
+ * @param def The property definition to check against.
36
+ * @param val The value to check. DOES NOT SUPPORT EXPRESSIONS.
37
+ * @param errorStack The error stack to add errors to.
38
+ */
39
+ function DoesValMatchPropertyModifier(def: PropertyLoadingTypeInfo, val: any): boolean;
40
+ /**
41
+ * ASSUMES INPUTS ARE CORRECT - DOES NOT CHECK FOR ERRORS.
42
+ * Get all of the assigned property values, so that they can individually be checked against the type requirements
43
+ * of the definiton. Turns single values, double arrays, maps and dicts all into a single flat array of values.
44
+ * @param def The property definition to get the values for.
45
+ * @param val The value to get the values from.
46
+ */
47
+ function GetPropValuesFromData(def: PropertyConfiguration, val: any): [any[], PropertyTypes];
48
+ /**
49
+ * ASSUMES INPUTS ARE CORRECT - DOES NOT CHECK FOR ERRORS.
50
+ * Runs a function on every value, setting the value to the results of the function.
51
+ * @param def The property definition to get the values for.
52
+ * @param val The value to get the values from.
53
+ * @param cb The function to run on every value.
54
+ */
55
+ function MapEveryPropValue(def: PropertyConfiguration, val: any, cb: (val: any) => any): any;
56
+ /**
57
+ * Check if the given value is assignable to the given class.
58
+ * @param type The type to check against.
59
+ * @param val The value to check.
60
+ * @param errorStack The error stack to add errors to.
61
+ * @param skipCustomOverride allows us to skip the class specific "DataIsType" function and use the default checks
62
+ * instead. This should mostly be used by the class itself when checking its own properties.
63
+ */
64
+ function DoesDataClassMatchRepl(version: Versions | string, type: ReplicableClass, val: any, errorStack: ErrorStack, skipCustomOverride?: boolean): null | ReplicableClass;
65
+ /**
66
+ * Check if the given expression matches the property definition.
67
+ * @param errorContext The context to add to the error message, should be ClassName.PropertyName.
68
+ * @param conf The expression configuration to check against.
69
+ * @param propVal The value to check.
70
+ * @param errorStack The error stack to add errors to.
71
+ * @param instanceOnly If true, will check the expression to match a single value of the property,
72
+ * rather than an array or a map.
73
+ */
74
+ function DoesExpressionMatchProperty(errorContext: string, conf: ExpressionConfiguration | undefined, propVal: any, errorStack: ErrorStack, instanceOnly?: boolean): boolean;
75
+ /**
76
+ * Check if the given data is loadable for this ReplicableClass.
77
+ * @param type The type to check against.
78
+ * @param val The data to check.
79
+ * @param source The source file that the data comes from.
80
+ * @param errorStack The error stack to add errors to.
81
+ * @param skipCustomOverride If true, will skip the class' "DataIsType" function and use the default checks instead.
82
+ */
83
+ function IsLoadableDataForRepl(type: ReplicableClass, val: any, version: Versions | string, errorStack: ErrorStack, skipCustomOverride?: boolean): any;
84
+ /**
85
+ * Check if the given value is loadable for the given type.
86
+ * @param type The repl class or primitive type to check against.
87
+ * @param val The value to check.
88
+ * @param version The version to check against.
89
+ * @param errorStack The error stack to add errors to.
90
+ * @param skipCustomOverride If true, will skip the class' "DataIsType" function and use the default checks instead.
91
+ */
92
+ function IsLoadableDataForType(type: any, val: any, version: Versions | string, errorStack: ErrorStack, skipCustomOverride?: boolean): boolean;
93
+ /**
94
+ * Setup and cache parsed expressions so that they don't have to be re-parsed every time an object is created with
95
+ * type data.
96
+ * Perform property migration for removed properties.
97
+ * @param rawType The type to setup expressions for.
98
+ * @param data
99
+ * @param source
100
+ */
101
+ function PrePrepareData(rawType: any, data: any, source: SourceMap, expressionStartOverride?: string): any;
102
+ }