@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,19 @@
1
+ import { ChainPath, TraversalScope } from "./TypeRegistry/Types.js";
2
+ import { ExpressionConfiguration, ExpressionType } from "./EvaluatorSteps.js";
3
+ import { ChainType } from "./TypeRegistry/ChainTypes.js";
4
+ import { Pointer } from "../Transformers/Reference.js";
5
+ export declare class EvaluationChain {
6
+ rawText?: string;
7
+ outputTypes: any[];
8
+ outputChains: ChainType[];
9
+ steps: ChainPath;
10
+ data: boolean;
11
+ config: Required<ExpressionConfiguration>;
12
+ wrapped: boolean;
13
+ result?: Pointer<any>;
14
+ type: ExpressionType;
15
+ constructor(steps: ChainPath, generatedTypes: ChainType[], data: boolean, config: Required<ExpressionConfiguration>);
16
+ navigate(scope: TraversalScope): [ChainPath, TraversalScope];
17
+ get(scope: TraversalScope): any;
18
+ set(scope: TraversalScope, value: any): void;
19
+ }
@@ -0,0 +1,137 @@
1
+ import { ClassCategory, describeObject } from "../Constants/SerialisationTypes.js";
2
+ import { ValidExpressionTypes } from "./TypeRegistry/Registry.js";
3
+ import { Pointer } from "../Transformers/Reference.js";
4
+ import { ReplType } from "./TypeRegistry/ReplAPI.js";
5
+ function prepareScope(scope) {
6
+ return Object.assign(Object.assign({}, scope), { global: Object.assign({}, scope.global), local: Object.assign({}, scope.local) });
7
+ }
8
+ export class EvaluationChain {
9
+ constructor(steps, generatedTypes, data, config) {
10
+ //Output types are the types that the expression is allowed to return, they can
11
+ // be more narrow than the types that the expression was instantiated with.
12
+ this.outputTypes = [];
13
+ //Output chains are the internal representation of the types above.
14
+ this.outputChains = [];
15
+ this.wrapped = false;
16
+ this.config = config;
17
+ this.steps = steps;
18
+ this.data = data;
19
+ this.outputChains = [...generatedTypes];
20
+ for (let chain of this.outputChains) {
21
+ let [types, style] = chain.getOutputTypes();
22
+ switch (style) {
23
+ case "Array2":
24
+ if (config.outputArray != 2) {
25
+ throw new Error(`Error! Expression ${this.rawText} output a double array but property expects something else.`);
26
+ }
27
+ break;
28
+ case "Array":
29
+ if (config.outputArray != 1) {
30
+ throw new Error(`Error! Expression ${this.rawText} output a single array but property expects something else.`);
31
+ }
32
+ break;
33
+ case "Map":
34
+ if (!config.outputMap) {
35
+ throw new Error(`Error! Expression ${this.rawText} output a map but property expects something else.`);
36
+ }
37
+ break;
38
+ }
39
+ //Expression type checking - no checking if any type is allowed.
40
+ if (config.outputTypes.includes("any")) {
41
+ this.outputTypes.push(...types);
42
+ }
43
+ else {
44
+ let desiredTypes = config.outputTypes.map((entry) => {
45
+ let desiredType = ValidExpressionTypes.GetTypeChain(entry);
46
+ if (!desiredType) {
47
+ throw new Error(`Error! ${describeObject(entry)} is not a valid expression type, did you remember to register it?`);
48
+ }
49
+ return desiredType;
50
+ });
51
+ //Check that each generated output type maps onto at least one configuration type.
52
+ for (let discoveredType of types) {
53
+ let handled = false;
54
+ for (let desiredType of desiredTypes) {
55
+ if (desiredType.isAssignableCompile(this.config.version, discoveredType, "Single")) {
56
+ handled = true;
57
+ this.outputTypes.push(...desiredType.getOutputTypes()[0]);
58
+ break;
59
+ }
60
+ }
61
+ if (!handled) {
62
+ throw new Error(`Error! ${describeObject(discoveredType)} is not assignable to any provided`
63
+ + ` expression configuration output types: ${config.outputTypes.map((e) => describeObject(e)).join(", ")}.`);
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ navigate(scope) {
70
+ scope = prepareScope(scope);
71
+ let currentStep = this.steps;
72
+ let expressionValue = this.steps.eval(scope);
73
+ scope.self = expressionValue;
74
+ while (currentStep.next && currentStep.next.length > 0) {
75
+ let found = false;
76
+ let verifiedValue = expressionValue instanceof Pointer ? expressionValue.valOrNull : expressionValue;
77
+ for (let next of currentStep.next) {
78
+ if (next.node.isAssignableLive(this.config.version, verifiedValue)) {
79
+ currentStep = next;
80
+ found = true;
81
+ break;
82
+ }
83
+ }
84
+ if (!found) {
85
+ throw new Error(`Error! ${describeObject(verifiedValue)} is not assignable to`
86
+ + ` ${currentStep.next.map((e) => e.node.debugName).join(", ")}`);
87
+ }
88
+ expressionValue = currentStep.eval(scope);
89
+ scope.self = expressionValue;
90
+ }
91
+ return [currentStep, scope];
92
+ }
93
+ get(scope) {
94
+ let [_, finalScope] = this.navigate(scope);
95
+ let value = finalScope.self instanceof Pointer ? finalScope.self.val : finalScope.self;
96
+ let types = this.outputChains.filter((e) => e.isAssignableLive(this.config.version, value));
97
+ if (types.length == 0) {
98
+ throw new Error(`Error! ${describeObject(value)} is not assignable to`
99
+ + ` ${this.outputChains.map((e) => e.debugName).join(", ")}`);
100
+ }
101
+ //TODO: This is a hack - it wraps return values in pointers if they're not already pointers.
102
+ // This is used for functions atm, because they can return raw values sometimes.
103
+ let needsPtr = false;
104
+ for (let type of types) {
105
+ if (type instanceof ReplType && ClassCategory.isType(ClassCategory.Pointer, type.repl.category)) {
106
+ needsPtr = true;
107
+ }
108
+ }
109
+ if (needsPtr && !(finalScope.self instanceof Pointer)) {
110
+ if (!this.wrapped) {
111
+ this.result = new Pointer(finalScope.self);
112
+ }
113
+ else {
114
+ this.result.val = finalScope.self;
115
+ }
116
+ return this.result;
117
+ }
118
+ return finalScope.self;
119
+ }
120
+ set(scope, value) {
121
+ if (this.data) {
122
+ throw new Error(`Cannot set value on data.`);
123
+ }
124
+ if (!this.outputChains.some((e) => e.isAssignableLive(this.config.version, value))) {
125
+ throw new Error(`Cannot set value, ${describeObject(value)} is not assignable to`
126
+ + ` ${this.outputChains.map((e) => e.debugName).join(", ")}`);
127
+ }
128
+ let currentStep;
129
+ [currentStep, scope] = this.navigate(scope);
130
+ if (!currentStep.set) {
131
+ throw new Error(`Error! Cannot set value on ${currentStep.node.debugName}`);
132
+ }
133
+ else {
134
+ return currentStep.set(scope, value);
135
+ }
136
+ }
137
+ }
@@ -0,0 +1,19 @@
1
+ export declare const matchExpression: RegExp;
2
+ export declare function isExpression(str: string): boolean;
3
+ export declare enum ExpressionType {
4
+ String = 0,
5
+ Value = 1,
6
+ Pointer = 2,
7
+ Collection = 3,
8
+ Function = 4
9
+ }
10
+ export interface ExpressionConfiguration {
11
+ version: string;
12
+ outputTypes: any[];
13
+ outputArray?: 2 | 1 | 0;
14
+ outputMap?: boolean;
15
+ outputDict?: boolean;
16
+ startType: any;
17
+ cacheable?: boolean;
18
+ duringLoad?: boolean;
19
+ }
@@ -0,0 +1,12 @@
1
+ export const matchExpression = /@\{[^}]*?}/gm;
2
+ export function isExpression(str) {
3
+ return matchExpression.test(str);
4
+ }
5
+ export var ExpressionType;
6
+ (function (ExpressionType) {
7
+ ExpressionType[ExpressionType["String"] = 0] = "String";
8
+ ExpressionType[ExpressionType["Value"] = 1] = "Value";
9
+ ExpressionType[ExpressionType["Pointer"] = 2] = "Pointer";
10
+ ExpressionType[ExpressionType["Collection"] = 3] = "Collection";
11
+ ExpressionType[ExpressionType["Function"] = 4] = "Function";
12
+ })(ExpressionType || (ExpressionType = {}));
@@ -0,0 +1,21 @@
1
+ import { EvaluationChain } from "./EvaluatorChain.js";
2
+ import { ExpressionConfiguration, ExpressionType } from "./EvaluatorSteps.js";
3
+ import { TraversalScope } from "./TypeRegistry/Types.js";
4
+ export declare class EvaluationString {
5
+ readonly rawText: string;
6
+ protected preparedText: string;
7
+ outputTypes: any[];
8
+ finalTypes: any[];
9
+ config: Required<ExpressionConfiguration>;
10
+ protected expressions: {
11
+ expression: EvaluationChain;
12
+ offset: number;
13
+ }[];
14
+ type: ExpressionType;
15
+ constructor(rawText: string, preparedText: string, expressions: {
16
+ expression: EvaluationChain;
17
+ offset: number;
18
+ }[], config: Required<ExpressionConfiguration>);
19
+ get(start: TraversalScope): any;
20
+ set(start: TraversalScope, value: any): void;
21
+ }
@@ -0,0 +1,26 @@
1
+ import { ExpressionType } from "./EvaluatorSteps.js";
2
+ export class EvaluationString {
3
+ constructor(rawText, preparedText, expressions, config) {
4
+ //Output types are the types that the expression is allowed to return.
5
+ this.outputTypes = [String];
6
+ //Final types are the expected types that the expression can return, which may
7
+ // be less than the output types.
8
+ this.finalTypes = [String];
9
+ this.expressions = [];
10
+ this.type = ExpressionType.String;
11
+ this.rawText = rawText;
12
+ this.preparedText = preparedText;
13
+ this.config = config;
14
+ this.expressions = expressions;
15
+ }
16
+ get(start) {
17
+ let newText = "" + this.preparedText;
18
+ for (let i = 0; i < this.expressions.length; i++) {
19
+ newText = newText.replace("${" + i + "}", this.expressions[i].expression.get(start));
20
+ }
21
+ return newText;
22
+ }
23
+ set(start, value) {
24
+ throw new Error(`Cannot set expression string.`);
25
+ }
26
+ }
@@ -0,0 +1,36 @@
1
+ import { TraversalStep } from "../Constants/TraversalStep.js";
2
+ import { TraversalScope } from "./TypeRegistry/Types.js";
3
+ import { EvaluationChain } from "./EvaluatorChain.js";
4
+ import { EvaluationString } from "./EvaluatorString.js";
5
+ import { ExpressionConfiguration } from "./EvaluatorSteps.js";
6
+ /**
7
+ * A wrapper for either ExpressionChain or ExpressionString.
8
+ */
9
+ export declare class Expression<T = any> extends TraversalStep<T> {
10
+ text: string;
11
+ scope: TraversalScope;
12
+ expression: EvaluationChain | EvaluationString;
13
+ constructor(expr: {
14
+ text: string;
15
+ sourceFile: string;
16
+ }, config: ExpressionConfiguration);
17
+ constructor(expr: EvaluationChain | EvaluationString, config?: Pick<ExpressionConfiguration, "outputTypes">);
18
+ protected setup(): void;
19
+ static ChangeScope<T>(scope: {
20
+ [prop: string]: any;
21
+ }, expression: Expression<T>): void;
22
+ get(): T;
23
+ set(value: T): void;
24
+ call<F extends T extends (...args: any[]) => any ? T : never>(...args: Parameters<F>): ReturnType<F>;
25
+ }
26
+ export declare namespace Expression {
27
+ type PreloadedExpression = EvaluationChain | EvaluationString;
28
+ function setCurrentScope(type: any, scope: {
29
+ [key: string]: any;
30
+ }): void;
31
+ function setCurrentStartScopeType(name: string | null): void;
32
+ function getLatestSetScope(): string | undefined;
33
+ function isExpressionString(str: any): str is string;
34
+ function isExpressionKind(value: any): value is Expression | EvaluationString | EvaluationChain;
35
+ function Parse(expression: string, sourceFile: string, config: ExpressionConfiguration): EvaluationString | EvaluationChain;
36
+ }
@@ -0,0 +1,147 @@
1
+ import { TraversalStep } from "../Constants/TraversalStep.js";
2
+ import { ReplicableRegistry } from "../Constants/ReplicableRegistry.js";
3
+ import { EvaluationChain } from "./EvaluatorChain.js";
4
+ import { EvaluationString } from "./EvaluatorString.js";
5
+ import { ExpressionType } from "./EvaluatorSteps.js";
6
+ import { CreateExpression } from "./CreateEvaluator.js";
7
+ import { ExpressionScopes } from "./TypeRegistry/Registry.js";
8
+ import { describeObject } from "../Constants/SerialisationTypes.js";
9
+ /**
10
+ * A wrapper for either ExpressionChain or ExpressionString.
11
+ */
12
+ export class Expression extends TraversalStep {
13
+ constructor(expr, config) {
14
+ super();
15
+ if (expr instanceof EvaluationChain || expr instanceof EvaluationString) {
16
+ this.text = expr.rawText;
17
+ this.expression = expr;
18
+ if (!config)
19
+ config = expr.config;
20
+ }
21
+ else {
22
+ this.text = expr.text;
23
+ this.expression = Expression.Parse(expr.text, expr.sourceFile, config);
24
+ if (!config) {
25
+ throw new Error(`Cannot create expression without configuration.`);
26
+ }
27
+ }
28
+ this.setup();
29
+ if (config.outputTypes.length < 1) {
30
+ throw new Error(`Expressions must specify at least one output type`);
31
+ }
32
+ }
33
+ setup() {
34
+ if (this.scope)
35
+ return;
36
+ let [globalRule, scopeRule, scopeMap] = ExpressionScopes.GetScopeChain(this.expression.config.startType);
37
+ if (!scopeRule)
38
+ throw new Error(`Cannot evaluate expression, requires valid starting scope for type ${describeObject(this.expression.config.startType)} but none is registered.`);
39
+ let scope = scopeMap;
40
+ scope.data = this.expression.config.duringLoad;
41
+ scope.self = null;
42
+ this.scope = scope;
43
+ }
44
+ // eslint-disable-next-line @typescript-eslint/naming-convention
45
+ static ChangeScope(scope, expression) {
46
+ Object.defineProperties(expression.scope, {
47
+ local: {
48
+ value: Object.assign({}, scope),
49
+ writable: false,
50
+ configurable: true,
51
+ enumerable: true
52
+ }
53
+ });
54
+ }
55
+ get() {
56
+ const value = this.expression.get(this.scope);
57
+ if (this.expression.type === ExpressionType.Collection) {
58
+ if (this.expression.config.outputArray) {
59
+ if (value instanceof Map) {
60
+ return Array.from(value.values());
61
+ }
62
+ else if (typeof value === "object") {
63
+ if (Array.isArray(value)) {
64
+ return value;
65
+ }
66
+ if (value.__proto__ !== Object.prototype) {
67
+ return [value];
68
+ }
69
+ return Array.from(Object.values(value));
70
+ }
71
+ else {
72
+ return [value];
73
+ }
74
+ }
75
+ else {
76
+ if (value instanceof Map) {
77
+ return new Map([...value.entries()]);
78
+ }
79
+ if (Array.isArray(value) || value.__proto__ === Object.prototype || typeof value !== "object") {
80
+ throw new Error(`Expression returns non-map value.`);
81
+ }
82
+ return value;
83
+ }
84
+ }
85
+ else {
86
+ return value;
87
+ }
88
+ }
89
+ set(value) {
90
+ if (this.expression.type !== ExpressionType.Value) {
91
+ throw new Error(`Can't set expression that isn't a value.`);
92
+ }
93
+ this.expression.set(this.scope, value);
94
+ }
95
+ call(...args) {
96
+ if (this.expression.type !== ExpressionType.Function) {
97
+ throw new Error(`Can't call expression that isn't a function.`);
98
+ }
99
+ return this.expression.get(this.scope)(...args);
100
+ }
101
+ }
102
+ (function (Expression) {
103
+ let latestScopeName;
104
+ function setCurrentScope(type, scope) {
105
+ if (typeof type === "string") {
106
+ latestScopeName = type;
107
+ type = ReplicableRegistry.GetTypesForName(latestScopeName)[0];
108
+ }
109
+ else {
110
+ latestScopeName = ReplicableRegistry.GetDataName(type);
111
+ }
112
+ ExpressionScopes.setLocalScope(type, scope);
113
+ ExpressionScopes.setLocalScope(latestScopeName, scope);
114
+ }
115
+ Expression.setCurrentScope = setCurrentScope;
116
+ function setCurrentStartScopeType(name) {
117
+ if (name === null) {
118
+ latestScopeName = undefined;
119
+ }
120
+ else {
121
+ latestScopeName = name;
122
+ }
123
+ }
124
+ Expression.setCurrentStartScopeType = setCurrentStartScopeType;
125
+ function getLatestSetScope() {
126
+ return latestScopeName;
127
+ }
128
+ Expression.getLatestSetScope = getLatestSetScope;
129
+ //Can't use /g because it makes the regexp stateful causing test to fail every second time.
130
+ const matchExpression = /@\{[^}]*?}/;
131
+ function isExpressionString(str) {
132
+ return typeof str === "string" && matchExpression.test(str);
133
+ }
134
+ Expression.isExpressionString = isExpressionString;
135
+ function isExpressionKind(value) {
136
+ return (value instanceof Expression ||
137
+ value instanceof EvaluationString ||
138
+ value instanceof EvaluationChain);
139
+ }
140
+ Expression.isExpressionKind = isExpressionKind;
141
+ function Parse(expression, sourceFile, config) {
142
+ var _a, _b, _c, _d, _e;
143
+ let initialisedConfig = Object.assign(Object.assign({}, config), { cacheable: (_a = config.cacheable) !== null && _a !== void 0 ? _a : false, duringLoad: (_b = config.duringLoad) !== null && _b !== void 0 ? _b : false, outputArray: (_c = config.outputArray) !== null && _c !== void 0 ? _c : 0, outputMap: (_d = config.outputMap) !== null && _d !== void 0 ? _d : false, outputDict: (_e = config.outputDict) !== null && _e !== void 0 ? _e : false });
144
+ return CreateExpression(expression, sourceFile, initialisedConfig);
145
+ }
146
+ Expression.Parse = Parse;
147
+ })(Expression || (Expression = {}));
@@ -0,0 +1,28 @@
1
+ import { ExpressionAST } from "./Compiler/BuiltinGrammar.js";
2
+ import { EAST_Token } from "./Compiler/ExpressionGrammar.js";
3
+ import { ExpressionConfiguration } from "./EvaluatorSteps.js";
4
+ import { EvaluationChain } from "./EvaluatorChain.js";
5
+ import "./TypeRegistry/Primitive.js";
6
+ import FileNode = ExpressionAST.FileNode;
7
+ interface PreparedToken {
8
+ type: "Token";
9
+ node: EAST_Token;
10
+ }
11
+ interface PreparedOp {
12
+ type: "Op";
13
+ node: EAST_Token;
14
+ params: [PreparedAST];
15
+ }
16
+ interface PreparedCast {
17
+ type: "Cast" | "ForceCast";
18
+ node: EAST_Token;
19
+ }
20
+ interface PreparedCall {
21
+ type: "Call";
22
+ node: EAST_Token;
23
+ params: PreparedAST[];
24
+ }
25
+ type PreparedAST = (PreparedToken | PreparedOp | PreparedCast | PreparedCall)[];
26
+ export declare function OrderASTSequentially(ast: FileNode): PreparedAST[];
27
+ export declare function OrderedNodeSequencesToTrees(orderedNodes: PreparedAST[], config: Required<ExpressionConfiguration>): EvaluationChain[];
28
+ export {};