@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,348 @@
1
+ import { describeObject } from "../Constants/SerialisationTypes.js";
2
+ import { ExpressionAST } from "./Compiler/BuiltinGrammar.js";
3
+ import { isToken } from "./Compiler/Tokenizer.js";
4
+ import { EvaluationChain } from "./EvaluatorChain.js";
5
+ import { ExpressionSyntaxError } from "../Constants/Errors.js";
6
+ import { ChainType } from "./TypeRegistry/ChainTypes.js";
7
+ import "./TypeRegistry/Primitive.js";
8
+ import { ChainFunction, ChainProperty } from "./TypeRegistry/Accessors.js";
9
+ import { ExpressionScopes, ValidExpressionTypes } from "./TypeRegistry/Registry.js";
10
+ var GetTypeChain = ValidExpressionTypes.GetTypeChain;
11
+ import { Pointer } from "../Transformers/Reference.js";
12
+ export function OrderASTSequentially(ast) {
13
+ let order;
14
+ function RearrangeSubexpression(nodes) {
15
+ let params = [];
16
+ for (let arg of nodes) {
17
+ let oldOrder = order;
18
+ order = [];
19
+ RearrangeNodes(arg);
20
+ params.push(order);
21
+ order = oldOrder;
22
+ }
23
+ return params;
24
+ }
25
+ function RearrangeNodes(node) {
26
+ var _a;
27
+ if (isToken(node)) {
28
+ order.push({ type: "Token", node });
29
+ return;
30
+ }
31
+ //No support for loops yet.
32
+ if (ExpressionAST.IsLoopNode(node))
33
+ return;
34
+ if (ExpressionAST.IsControlFlowNode(node))
35
+ return;
36
+ if (ExpressionAST.IsCommentNode(node))
37
+ return;
38
+ if (ExpressionAST.IsPreprocessorCommandNode(node))
39
+ return;
40
+ if (ExpressionAST.IsStatementNode(node) || ExpressionAST.IsExpressionNode(node)) {
41
+ //Do we care? probably not.
42
+ // if (isToken(node.values.expression)) return;
43
+ RearrangeNodes(node.values.expression);
44
+ return;
45
+ }
46
+ if (ExpressionAST.IsArrayAccessSequenceNode(node)) {
47
+ RearrangeNodes(node.values.identifier);
48
+ for (let access of node.values.accessor) {
49
+ RearrangeNodes(access.values.index);
50
+ }
51
+ return;
52
+ }
53
+ //Ergh. Trying not to think about this one right now.
54
+ if (ExpressionAST.IsParenthetisedExpressionNode(node))
55
+ return;
56
+ if (ExpressionAST.IsBinaryExpressionNode(node)) {
57
+ RearrangeNodes(node.values.lhs);
58
+ order.push({
59
+ type: "Op",
60
+ node: node.values.operator,
61
+ params: RearrangeSubexpression([node.values.rhs])
62
+ });
63
+ return;
64
+ }
65
+ if (ExpressionAST.IsUnaryExpressionNode(node)) {
66
+ order.push({
67
+ type: "Op",
68
+ node: node.values.operator,
69
+ params: RearrangeSubexpression([node.values.value])
70
+ });
71
+ return;
72
+ }
73
+ if (ExpressionAST.IsAssignmentNode(node))
74
+ return;
75
+ if (ExpressionAST.IsStructNode(node))
76
+ return;
77
+ if (ExpressionAST.IsPropertySignatureNode(node))
78
+ return;
79
+ if (ExpressionAST.IsIdentifierDeclarationNode(node))
80
+ return;
81
+ if (ExpressionAST.IsFunctionDeclarationNode(node) || ExpressionAST.IsFunctionParameterNode(node))
82
+ return;
83
+ if (ExpressionAST.IsFunctionCallNode(node)) {
84
+ let temp = order;
85
+ order = [];
86
+ RearrangeNodes(node.values.name);
87
+ let function_name = order;
88
+ order = temp;
89
+ let last = function_name.pop();
90
+ if (!isToken(last.node)) {
91
+ throw new ExpressionSyntaxError(`Function call should always be preceeded by an identifier.`, last.node);
92
+ }
93
+ order.splice(order.length, 0, ...function_name, {
94
+ type: "Call",
95
+ node: last.node,
96
+ params: RearrangeSubexpression((_a = node.values.arguments) !== null && _a !== void 0 ? _a : [])
97
+ });
98
+ return;
99
+ }
100
+ if (ExpressionAST.IsCastNode(node) || ExpressionAST.IsForceCastNode(node)) {
101
+ RearrangeNodes(node.values.expression);
102
+ order.push({
103
+ type: ExpressionAST.IsForceCastNode(node) ? "ForceCast" : "Cast",
104
+ node: node.values.castType
105
+ });
106
+ return;
107
+ }
108
+ if (ExpressionAST.IsMemberAccessNode(node)) {
109
+ RearrangeNodes(node.values.context);
110
+ RearrangeNodes(node.values.memberName);
111
+ }
112
+ }
113
+ let orderedNodes = [];
114
+ for (let statement of ast.values.lines) {
115
+ order = [];
116
+ RearrangeNodes(statement);
117
+ orderedNodes.push(order);
118
+ }
119
+ return orderedNodes;
120
+ }
121
+ function ToChainType(type) {
122
+ if (type instanceof ChainType) {
123
+ return type;
124
+ }
125
+ return ValidExpressionTypes.GetTypeChain(type);
126
+ }
127
+ function TypesMatchRequirements(version, typesToCheck, requirements) {
128
+ let misMatches = [];
129
+ // Resolve aliases.
130
+ checkEachType: for (let checkType of typesToCheck) {
131
+ let checkChain = ToChainType(checkType);
132
+ if (!checkChain) {
133
+ throw new Error(`Error, unknown type ${describeObject(checkType)}. ${describeObject(checkType)} was used as a type to check against requirements.`);
134
+ }
135
+ let [types, style] = checkChain.getOutputTypes();
136
+ for (let requirement of requirements) {
137
+ if (checkChain == requirement) {
138
+ continue checkEachType;
139
+ }
140
+ if (types.some((e) => requirement.isAssignableCompile(version, e, style))) {
141
+ continue checkEachType;
142
+ }
143
+ }
144
+ misMatches.push(checkChain);
145
+ }
146
+ return misMatches;
147
+ }
148
+ function OrderNodesToTree(statement, config) {
149
+ let startType = config.startType;
150
+ let [globalChain, scopeChain] = ExpressionScopes.GetScopeChain(startType);
151
+ if (!scopeChain) {
152
+ throw new Error(`Error, tried to start expression from type `
153
+ + `${describeObject(config.startType)} but ${describeObject(config.startType)} doesn't exist in the parser's lexicon.`);
154
+ }
155
+ let lastContext = [scopeChain];
156
+ if (typeof lastContext[0] === "undefined") {
157
+ throw new Error(`Error, unknown enclosing type ${describeObject(startType)}.`
158
+ + ` ${describeObject(startType)} was used as the location from which to start `
159
+ + `resolving the expression, but ${describeObject(startType)} hasn't been added `
160
+ + `to the lexicon as an enclosing type.`);
161
+ }
162
+ let desiredOutputType = config.outputTypes.map((e) => {
163
+ let val = GetTypeChain(e);
164
+ if (!val) {
165
+ throw new Error(`Error, unknown type ${describeObject(e)}. ${describeObject(e)} was used as the`
166
+ + ` expected output type, but ${describeObject(e)} hasn't been added to the lexicon as a type.`);
167
+ }
168
+ if (config.outputDict) {
169
+ val = ValidExpressionTypes.GetDictType([val]);
170
+ }
171
+ if (config.outputMap) {
172
+ val = ValidExpressionTypes.GetMapType([val]);
173
+ }
174
+ if (config.outputArray == 1) {
175
+ val = ValidExpressionTypes.GetArrayType([val]);
176
+ }
177
+ if (config.outputArray == 2) {
178
+ val = ValidExpressionTypes.GetArrayType([ValidExpressionTypes.GetArrayType([val])]);
179
+ }
180
+ return val;
181
+ });
182
+ let isDataOnlyTime = config.duringLoad;
183
+ /// O O O
184
+ /// / | / | / \
185
+ /// - O X X O - O (output)
186
+ /// \ | \ | \ /
187
+ /// O O O
188
+ let finalTypes = new Set();
189
+ function FinishBranch(lastStep, types) {
190
+ //verify finished type.
191
+ let missMatches = TypesMatchRequirements(config.version, types, desiredOutputType);
192
+ if (missMatches.length !== 0) {
193
+ let outputName = types.length == 1 ? types[0].debugName : "(" + types.map((e) => e.debugName).join(" | ") + ")";
194
+ let missMatchesName = missMatches.length == 1 ? missMatches[0].debugName : "(" + missMatches.map((e) => e.debugName).join(" | ") + ")";
195
+ throw new Error(`Error, expression produced type ${outputName} but ${missMatchesName} isn't`
196
+ + ` assignable to desired types: ${desiredOutputType.map((e) => e.debugName).join(", ")}.`);
197
+ }
198
+ types.forEach((e) => finalTypes.add(e instanceof ChainType ? e : GetTypeChain(e)));
199
+ if (lastStep.expression instanceof ChainProperty) {
200
+ lastStep.set = lastStep.expression.settable;
201
+ }
202
+ }
203
+ function ParseRemainingAST(lastStep, type, statement, isBase = false) {
204
+ if (!(type instanceof ChainType)) {
205
+ type = GetTypeChain(type);
206
+ if (!type) {
207
+ throw new ExpressionSyntaxError(`Error, unknown type ${describeObject(type)}.`, statement[0].node);
208
+ }
209
+ }
210
+ let [prep, ...rest] = statement;
211
+ switch (prep.type) {
212
+ case "Token": {
213
+ //Step 1: Lookup the property on the current type.
214
+ let accessor;
215
+ if (config.duringLoad) {
216
+ accessor = type.getData(config.version, prep.node.data, prep.node, isBase ? [scopeChain, globalChain] : []);
217
+ }
218
+ else {
219
+ accessor = type.getLive(config.version, prep.node.data, prep.node, isBase ? [scopeChain, globalChain] : []);
220
+ }
221
+ if (accessor instanceof ChainFunction && accessor.parameters.length > 0) {
222
+ throw new ExpressionSyntaxError(`Error, tried to access property ${prep.node.data}`
223
+ + ` but ${prep.node.data} is a function on type ${type.debugName}.`, prep.node);
224
+ }
225
+ let step = {
226
+ node: type,
227
+ expression: accessor,
228
+ eval: accessor.evaluate
229
+ };
230
+ lastStep.next.push(step);
231
+ if (rest.length > 0) {
232
+ step.next = [];
233
+ for (let rType of accessor.resultTypes) {
234
+ ParseRemainingAST(step, rType, rest);
235
+ }
236
+ }
237
+ else {
238
+ FinishBranch(step, accessor.resultTypes);
239
+ }
240
+ break;
241
+ }
242
+ case "Call": {
243
+ if (config.duringLoad) {
244
+ throw new ExpressionSyntaxError(`Error, cannot call functions during load time.`, prep.node);
245
+ }
246
+ else {
247
+ //Get function.
248
+ let accessor = type.getLive(config.version, prep.node.data, prep.node, isBase ? [scopeChain, globalChain] : []);
249
+ if (!(accessor instanceof ChainFunction)) {
250
+ throw new ExpressionSyntaxError(`Error, ${prep.node.data} is not a function.`, prep.node);
251
+ }
252
+ //Get parameters.
253
+ let params = prep.params.map((e) => OrderNodesToTree(e, config));
254
+ //Verify parameters.
255
+ if (params.length < accessor.parameters.length) {
256
+ throw new ExpressionSyntaxError(`Error, expected ${accessor.parameters.length} arguments,`
257
+ + ` instead got ${params.length} arguments.`, prep.node);
258
+ }
259
+ for (let i = 0; i < accessor.parameters.length; i++) {
260
+ if (!TypesMatchRequirements(config.version, params[i].outputTypes, accessor.parameters[i])) {
261
+ throw new ExpressionSyntaxError(`Error, the ${i + 1}-nth parameter is of type ${params[i].outputTypes.map((e) => describeObject(e)).join(", ")}`
262
+ + ` but should be ${accessor.parameters[i].map((e) => describeObject(e)).join(", ")}.`, prep.node);
263
+ }
264
+ }
265
+ let step = {
266
+ node: type,
267
+ expression: accessor,
268
+ eval: (scope) => {
269
+ return accessor.evaluate(scope, ...params.map((e) => e.get(scope)));
270
+ }
271
+ };
272
+ lastStep.next.push(step);
273
+ if (rest.length > 0) {
274
+ step.next = [];
275
+ for (let rType of accessor.resultTypes) {
276
+ ParseRemainingAST(step, rType, rest);
277
+ }
278
+ }
279
+ else {
280
+ FinishBranch(step, accessor.resultTypes);
281
+ }
282
+ }
283
+ break;
284
+ }
285
+ case "Op": {
286
+ throw new ExpressionSyntaxError(`Error, cannot use operators during load time.`, prep.node);
287
+ }
288
+ case "Cast":
289
+ case "ForceCast": {
290
+ let newType = GetTypeChain(prep.node.data);
291
+ let possibleTypes = lastStep.expression.resultTypes;
292
+ let oneValidType = false;
293
+ //Cast requires a type matches at compile time. Force cast doesn't (that's what makes it 'force').
294
+ if (prep.type == "Cast") {
295
+ // Cast needs only one matching type.
296
+ for (let type of possibleTypes) {
297
+ let chain = ToChainType(type);
298
+ if (!chain) {
299
+ throw new ExpressionSyntaxError(`Error, unknown type ${describeObject(type)}.`, statement[0].node);
300
+ }
301
+ if (newType.isCastableCompile(config.version, chain)) {
302
+ oneValidType = true;
303
+ break;
304
+ }
305
+ }
306
+ if (!oneValidType) {
307
+ throw new ExpressionSyntaxError(`Error, cannot cast from ${lastStep.node.debugName} to ${newType.debugName}.`, prep.node);
308
+ }
309
+ }
310
+ let step = {
311
+ node: newType,
312
+ //a bit of a hack, but allows setting casted expression.
313
+ expression: lastStep.expression,
314
+ eval: (scope) => {
315
+ let rawVal = scope.self instanceof Pointer ? scope.self.valOrNull : scope.self;
316
+ if (!newType.isCastableLive(config.version, rawVal)) {
317
+ throw new Error(`Error, cannot cast from ${describeObject(rawVal)} to ${newType.debugName}.`);
318
+ }
319
+ return scope.self;
320
+ }
321
+ };
322
+ lastStep.next.push(step);
323
+ if (rest.length > 0) {
324
+ step.next = [];
325
+ ParseRemainingAST(step, newType, rest);
326
+ }
327
+ else {
328
+ FinishBranch(step, [newType]);
329
+ }
330
+ break;
331
+ }
332
+ }
333
+ }
334
+ let fakeStep = {
335
+ node: scopeChain,
336
+ next: []
337
+ };
338
+ ParseRemainingAST(fakeStep, scopeChain, statement, true);
339
+ let resultTypes = Array.from(finalTypes);
340
+ return new EvaluationChain(fakeStep.next[0], resultTypes, isDataOnlyTime, config);
341
+ }
342
+ export function OrderedNodeSequencesToTrees(orderedNodes, config) {
343
+ let allExpressions = [];
344
+ for (let statement of orderedNodes) {
345
+ allExpressions.push(OrderNodesToTree(statement, config));
346
+ }
347
+ return allExpressions;
348
+ }
@@ -0,0 +1,26 @@
1
+ import { TraversalScope } from "./Types.js";
2
+ import { ChainType } from "./ChainTypes.js";
3
+ export declare abstract class ChainAccessor {
4
+ propName: string;
5
+ evalScope: Exclude<keyof TraversalScope, "version" | "data">;
6
+ resultTypes: any[];
7
+ evaluate(scope: TraversalScope): any;
8
+ settable?(scope: TraversalScope, value: any): boolean;
9
+ constructor(propName: string, evalScope: ChainAccessor["evalScope"], resultTypes: any[]);
10
+ }
11
+ export declare class ChainFunction extends ChainAccessor {
12
+ parameters: any[][];
13
+ constructor(propName: string, evalScope: ChainFunction["evalScope"], resultTypes: ChainType[], parameters: ChainType[][]);
14
+ evaluate(scope: TraversalScope, ...args: any[]): any;
15
+ }
16
+ export declare class ChainProperty extends ChainAccessor {
17
+ settable(scope: TraversalScope, value: any): any;
18
+ }
19
+ export declare class ChainMap extends ChainAccessor {
20
+ evaluate(scope: TraversalScope): any;
21
+ settable(scope: TraversalScope, value: any): any;
22
+ }
23
+ export declare class ChainOverride extends ChainAccessor {
24
+ parameters: ChainType[][];
25
+ constructor(propName: string, evalScope: ChainFunction["evalScope"], resultTypes: any[], getter: (scope: TraversalScope) => any, setter?: (scope: TraversalScope, value: any) => any);
26
+ }
@@ -0,0 +1,58 @@
1
+ import { Pointer } from "../../Transformers/Reference.js";
2
+ export class ChainAccessor {
3
+ evaluate(scope) {
4
+ if (scope[this.evalScope] instanceof Pointer) {
5
+ return scope[this.evalScope].val[this.propName];
6
+ }
7
+ return scope[this.evalScope][this.propName];
8
+ }
9
+ constructor(propName, evalScope, resultTypes) {
10
+ this.resultTypes = [];
11
+ this.propName = propName;
12
+ this.evalScope = evalScope;
13
+ this.resultTypes = resultTypes;
14
+ this.evaluate = this.evaluate.bind(this);
15
+ if (this.settable)
16
+ this.settable = this.settable.bind(this);
17
+ }
18
+ }
19
+ export class ChainFunction extends ChainAccessor {
20
+ constructor(propName, evalScope, resultTypes, parameters) {
21
+ super(propName, evalScope, resultTypes);
22
+ this.parameters = [];
23
+ this.parameters = parameters;
24
+ }
25
+ evaluate(scope, ...args) {
26
+ if (scope[this.evalScope] instanceof Pointer) {
27
+ return scope[this.evalScope].val[this.propName](...args);
28
+ }
29
+ return scope[this.evalScope][this.propName](...args);
30
+ }
31
+ }
32
+ export class ChainProperty extends ChainAccessor {
33
+ settable(scope, value) {
34
+ if (scope[this.evalScope] instanceof Pointer) {
35
+ return scope[this.evalScope].val[this.propName] = value;
36
+ }
37
+ return scope[this.evalScope][this.propName] = value;
38
+ }
39
+ }
40
+ export class ChainMap extends ChainAccessor {
41
+ evaluate(scope) {
42
+ return scope[this.evalScope].get(this.propName);
43
+ }
44
+ settable(scope, value) {
45
+ scope[this.evalScope].set(this.propName, value);
46
+ return value;
47
+ }
48
+ }
49
+ export class ChainOverride extends ChainAccessor {
50
+ constructor(propName, evalScope, resultTypes, getter, setter) {
51
+ super(propName, evalScope, resultTypes);
52
+ this.parameters = [];
53
+ this.evaluate = getter;
54
+ if (setter) {
55
+ this.settable = setter;
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,51 @@
1
+ import { Versions } from "../../Constants/Versions.js";
2
+ import { ChainMap, ChainProperty } from "./Accessors.js";
3
+ import { ChainType } from "./ChainTypes.js";
4
+ import { ExpressionGrammar } from "../Compiler/ExpressionGrammar.js";
5
+ import Node = ExpressionGrammar.Node;
6
+ import { ErrorStack } from "../../Constants/Errors.js";
7
+ export declare class DictType extends ChainType {
8
+ types: ChainType[];
9
+ constructor(name: string, types: ChainType[]);
10
+ static generateName(outputTypes: ChainType[]): string;
11
+ getOwnOutputStyle(): ReturnType<ChainType["getOwnOutputStyle"]>;
12
+ getOwnOutputTypes(): any[];
13
+ isAssignableCompile(type: any): boolean;
14
+ isAssignableLive(version: Versions, value: any): boolean;
15
+ isAssignableData(version: Versions, value: any): boolean;
16
+ isCastableCompile(type: any): boolean;
17
+ isCastableLive(version: Versions, value: any): boolean;
18
+ isCastableData(version: Versions, value: any): boolean;
19
+ getLive(version: Versions, prop: string, node: Node, parents?: ChainType[]): ChainProperty;
20
+ getData(version: Versions, prop: string, node: Node, parents?: ChainType[]): ChainProperty;
21
+ }
22
+ export declare class MapType extends ChainType {
23
+ types: ChainType[];
24
+ constructor(name: string, types: ChainType[]);
25
+ static generateName(outputTypes: ChainType[]): string;
26
+ getOwnOutputTypes(): any[];
27
+ getOwnOutputStyle(): ReturnType<ChainType["getOwnOutputStyle"]>;
28
+ isAssignableCompile(type: any): boolean;
29
+ isCastableCompile(type: any): boolean;
30
+ isAssignableLive(version: Versions, value: any): value is Map<any, any>;
31
+ isAssignableData(version: Versions, value: any): boolean;
32
+ isCastableLive(version: Versions, value: any): value is Map<any, any>;
33
+ isCastableData(version: Versions, value: any): boolean;
34
+ getLive(version: Versions, prop: string, node: Node, parent?: ChainType[]): ChainMap;
35
+ getData(version: Versions, prop: string, node: Node, parent?: ChainType[]): ChainMap;
36
+ }
37
+ export declare class ArrayType extends ChainType {
38
+ types: ChainType[];
39
+ constructor(name: string, types: ChainType[]);
40
+ static generateName(outputTypes: ChainType[]): string;
41
+ getOwnOutputTypes(): any[];
42
+ getOwnOutputStyle(): ReturnType<ChainType["getOwnOutputStyle"]>;
43
+ isAssignableCompile(type: any): boolean;
44
+ isAssignableLive(version: Versions, value: any): boolean;
45
+ isAssignableData(version: Versions, value: any, stack: ErrorStack): boolean;
46
+ isCastableCompile(type: any): boolean;
47
+ isCastableLive(version: Versions, value: any): boolean;
48
+ isCastableData(version: Versions, value: any): boolean;
49
+ getLive(version: Versions, prop: string, node: Node, parents?: ChainType[]): ChainProperty;
50
+ getData(version: Versions, prop: string, node: Node, parents?: ChainType[]): ChainProperty;
51
+ }
@@ -0,0 +1,134 @@
1
+ import { ChainMap, ChainProperty } from "./Accessors.js";
2
+ import { ChainType } from "./ChainTypes.js";
3
+ import { isPrimitiveType, primitiveTypeName } from "../../Constants/SerialisationTypes.js";
4
+ export class DictType extends ChainType {
5
+ constructor(name, types) {
6
+ super(name);
7
+ this.types = [];
8
+ this.types = types;
9
+ }
10
+ static generateName(outputTypes) {
11
+ return "{[string]: " + outputTypes.map(x => x.debugName).join(" | ") + "}";
12
+ }
13
+ getOwnOutputStyle() {
14
+ return "Dict";
15
+ }
16
+ getOwnOutputTypes() {
17
+ return ChainType.ToRawTypes(this.types);
18
+ }
19
+ isAssignableCompile(type) {
20
+ return type === this.debugName;
21
+ }
22
+ isAssignableLive(version, value) {
23
+ return value instanceof Object && value.__proto__ === Object.prototype;
24
+ }
25
+ isAssignableData(version, value) {
26
+ return value instanceof Object && value.__proto__ === Object.prototype;
27
+ }
28
+ isCastableCompile(type) {
29
+ return type === this.debugName;
30
+ }
31
+ isCastableLive(version, value) {
32
+ return value instanceof Object && value.__proto__ === Object.prototype;
33
+ }
34
+ isCastableData(version, value) {
35
+ return value instanceof Object && value.__proto__ === Object.prototype;
36
+ }
37
+ getLive(version, prop, node, parents) {
38
+ return new ChainProperty(prop, "self", this.types);
39
+ }
40
+ getData(version, prop, node, parents) {
41
+ return new ChainProperty(prop, "self", this.types);
42
+ }
43
+ }
44
+ export class MapType extends ChainType {
45
+ constructor(name, types) {
46
+ super(name);
47
+ this.types = [];
48
+ this.types = types;
49
+ }
50
+ static generateName(outputTypes) {
51
+ return "Map<string," + outputTypes.map(x => x.debugName).join(" | ") + ">";
52
+ }
53
+ getOwnOutputTypes() {
54
+ return ChainType.ToRawTypes(this.types);
55
+ }
56
+ getOwnOutputStyle() {
57
+ return "Map";
58
+ }
59
+ isAssignableCompile(type) {
60
+ return type === this.debugName;
61
+ }
62
+ isCastableCompile(type) {
63
+ return type === this.debugName;
64
+ }
65
+ isAssignableLive(version, value) {
66
+ return value instanceof Map;
67
+ }
68
+ isAssignableData(version, value) {
69
+ return value instanceof Object && value.__proto__ === Object.prototype;
70
+ }
71
+ isCastableLive(version, value) {
72
+ return value instanceof Map;
73
+ }
74
+ isCastableData(version, value) {
75
+ return value instanceof Object && value.__proto__ === Object.prototype;
76
+ }
77
+ getLive(version, prop, node, parent) {
78
+ return new ChainMap(prop, "self", this.types);
79
+ }
80
+ getData(version, prop, node, parent) {
81
+ return new ChainMap(prop, "self", this.types);
82
+ }
83
+ }
84
+ export class ArrayType extends ChainType {
85
+ constructor(name, types) {
86
+ super(name);
87
+ this.types = [];
88
+ this.types = types;
89
+ }
90
+ static generateName(outputTypes) {
91
+ if (outputTypes.length == 1) {
92
+ if (isPrimitiveType(outputTypes[0])) {
93
+ return primitiveTypeName(outputTypes[0]) + "[]";
94
+ }
95
+ return outputTypes[0].debugName + "[]";
96
+ }
97
+ return "(" + outputTypes.map(x => {
98
+ if (isPrimitiveType(x)) {
99
+ return primitiveTypeName(x) + "[]";
100
+ }
101
+ return x.debugName;
102
+ }).join(" | ") + ")[]";
103
+ }
104
+ getOwnOutputTypes() {
105
+ return ChainType.ToRawTypes(this.types);
106
+ }
107
+ getOwnOutputStyle() {
108
+ return this.types[0] instanceof ArrayType ? "Array2" : "Array";
109
+ }
110
+ isAssignableCompile(type) {
111
+ return type === this.debugName;
112
+ }
113
+ isAssignableLive(version, value) {
114
+ return Array.isArray(value) && value.every(x => this.types.some(t => t.isAssignableLive(version, x)));
115
+ }
116
+ isAssignableData(version, value, stack) {
117
+ return Array.isArray(value) && value.every(x => this.types.some(t => t.isAssignableData(version, x, stack)));
118
+ }
119
+ isCastableCompile(type) {
120
+ return type === this.debugName;
121
+ }
122
+ isCastableLive(version, value) {
123
+ return value instanceof Object && value.__proto__ === Object.prototype;
124
+ }
125
+ isCastableData(version, value) {
126
+ return value instanceof Object && value.__proto__ === Object.prototype;
127
+ }
128
+ getLive(version, prop, node, parents) {
129
+ return new ChainProperty(prop, "self", this.types);
130
+ }
131
+ getData(version, prop, node, parents) {
132
+ return new ChainProperty(prop, "self", this.types);
133
+ }
134
+ }
@@ -0,0 +1,23 @@
1
+ import { ExpressionGrammar } from "../Compiler/ExpressionGrammar.js";
2
+ import { ErrorStack } from "../../Constants/Errors.js";
3
+ import Node = ExpressionGrammar.Node;
4
+ import { ChainAccessor } from "./Accessors.js";
5
+ import { Versions } from "../../Constants/Versions.js";
6
+ export declare abstract class ChainType {
7
+ debugName: string;
8
+ constructor(debugName: string);
9
+ abstract getOwnOutputTypes(): any[];
10
+ abstract getOwnOutputStyle(): "Single" | "Array" | "Array2" | "Map" | "Dict";
11
+ static ToRawTypes: (types: any[]) => any[];
12
+ getOutputTypes(): [any[], ReturnType<ChainType["getOwnOutputStyle"]>];
13
+ checkContextScopes(version: Versions, prop: string, node: ExpressionGrammar.Node, contexts?: ChainType[]): ChainAccessor | never;
14
+ checkContextsData(version: Versions, prop: string, node: ExpressionGrammar.Node, parents?: ChainType[]): ChainAccessor | never;
15
+ abstract isAssignableCompile(version: Versions, type: any, style: ReturnType<ChainType["getOwnOutputStyle"]>): boolean;
16
+ abstract isAssignableLive(version: Versions, value: any): boolean;
17
+ abstract isAssignableData(version: Versions, value: any, stack: ErrorStack): boolean;
18
+ abstract isCastableCompile(version: Versions, type: any): boolean;
19
+ abstract isCastableLive(version: Versions, value: any): boolean;
20
+ abstract isCastableData(version: Versions, value: any, stack: ErrorStack): boolean;
21
+ abstract getLive(version: Versions, prop: string, node: Node, parents?: ChainType[]): ChainAccessor;
22
+ abstract getData(version: Versions, prop: string, node: Node, parents?: ChainType[]): ChainAccessor;
23
+ }