@bikky/replication 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Constants/Errors.d.ts +27 -0
- package/Constants/Errors.js +75 -0
- package/Constants/Logging.d.ts +17 -0
- package/Constants/Logging.js +97 -0
- package/Constants/ReplicableRegistry.d.ts +37 -0
- package/Constants/ReplicableRegistry.js +234 -0
- package/Constants/SerialisationTypes.d.ts +82 -0
- package/Constants/SerialisationTypes.js +160 -0
- package/Constants/SourceMaps.d.ts +10 -0
- package/Constants/SourceMaps.js +12 -0
- package/Constants/TraversalStep.d.ts +5 -0
- package/Constants/TraversalStep.js +2 -0
- package/Constants/Versions.d.ts +15 -0
- package/Constants/Versions.js +63 -0
- package/Expressions/Compiler/BuiltinGrammar.d.ts +234 -0
- package/Expressions/Compiler/BuiltinGrammar.js +446 -0
- package/Expressions/Compiler/ExpressionGrammar.d.ts +89 -0
- package/Expressions/Compiler/ExpressionGrammar.js +70 -0
- package/Expressions/Compiler/Parser.d.ts +56 -0
- package/Expressions/Compiler/Parser.js +314 -0
- package/Expressions/Compiler/Tokenizer.d.ts +52 -0
- package/Expressions/Compiler/Tokenizer.js +222 -0
- package/Expressions/Compiler/__tests__/Replicable.Expressions.Parser.test.d.ts +1 -0
- package/Expressions/Compiler/__tests__/Replicable.Expressions.Parser.test.js +516 -0
- package/Expressions/Compiler/__tests__/Replicable.Expressions.Tokenizer.test.d.ts +1 -0
- package/Expressions/Compiler/__tests__/Replicable.Expressions.Tokenizer.test.js +68 -0
- package/Expressions/CreateEvaluator.d.ts +4 -0
- package/Expressions/CreateEvaluator.js +85 -0
- package/Expressions/EvaluatorChain.d.ts +19 -0
- package/Expressions/EvaluatorChain.js +137 -0
- package/Expressions/EvaluatorSteps.d.ts +19 -0
- package/Expressions/EvaluatorSteps.js +12 -0
- package/Expressions/EvaluatorString.d.ts +21 -0
- package/Expressions/EvaluatorString.js +26 -0
- package/Expressions/Expression.d.ts +36 -0
- package/Expressions/Expression.js +147 -0
- package/Expressions/Traverser.d.ts +28 -0
- package/Expressions/Traverser.js +348 -0
- package/Expressions/TypeRegistry/Accessors.d.ts +26 -0
- package/Expressions/TypeRegistry/Accessors.js +58 -0
- package/Expressions/TypeRegistry/ChainCollections.d.ts +51 -0
- package/Expressions/TypeRegistry/ChainCollections.js +134 -0
- package/Expressions/TypeRegistry/ChainTypes.d.ts +23 -0
- package/Expressions/TypeRegistry/ChainTypes.js +46 -0
- package/Expressions/TypeRegistry/CustomAPI.d.ts +36 -0
- package/Expressions/TypeRegistry/CustomAPI.js +181 -0
- package/Expressions/TypeRegistry/Primitive.d.ts +19 -0
- package/Expressions/TypeRegistry/Primitive.js +47 -0
- package/Expressions/TypeRegistry/Registry.d.ts +27 -0
- package/Expressions/TypeRegistry/Registry.js +270 -0
- package/Expressions/TypeRegistry/ReplAPI.d.ts +41 -0
- package/Expressions/TypeRegistry/ReplAPI.js +220 -0
- package/Expressions/TypeRegistry/Scope.d.ts +24 -0
- package/Expressions/TypeRegistry/Scope.js +44 -0
- package/Expressions/TypeRegistry/Types.d.ts +23 -0
- package/Expressions/TypeRegistry/Types.js +1 -0
- package/Expressions/TypeRegistry/__tests__/Replicable.Expressions.Accessors.test.d.ts +1 -0
- package/Expressions/TypeRegistry/__tests__/Replicable.Expressions.Accessors.test.js +31 -0
- package/Expressions/__tests__/ExpressionExamples.d.ts +28 -0
- package/Expressions/__tests__/ExpressionExamples.js +50 -0
- package/Expressions/__tests__/Replicable.Expressions.Expressions.test.d.ts +1 -0
- package/Expressions/__tests__/Replicable.Expressions.Expressions.test.js +166 -0
- package/IDPool.d.ts +18 -0
- package/IDPool.data.d.ts +17 -0
- package/IDPool.js +139 -0
- package/License.txt +1 -0
- package/Main.d.ts +13 -0
- package/Main.js +13 -0
- package/Networking.d.ts +60 -0
- package/Networking.js +626 -0
- package/Replicatable.d.ts +66 -0
- package/Replicatable.js +123 -0
- package/Tracking/Buffable.d.ts +68 -0
- package/Tracking/Buffable.js +194 -0
- package/Tracking/Class.d.ts +97 -0
- package/Tracking/Class.js +221 -0
- package/Tracking/Functions.d.ts +14 -0
- package/Tracking/Functions.js +27 -0
- package/Tracking/GlobalGroup.d.ts +5 -0
- package/Tracking/GlobalGroup.js +39 -0
- package/Tracking/Property.d.ts +95 -0
- package/Tracking/Property.js +125 -0
- package/Tracking/Types.d.ts +33 -0
- package/Tracking/Types.js +1 -0
- package/Tracking/__tests__/Replicable.Tracking.Decorator.test.d.ts +1 -0
- package/Tracking/__tests__/Replicable.Tracking.Decorator.test.js +151 -0
- package/Tracking/__tests__/Replicable.Tracking.Deserialisation.test.d.ts +1 -0
- package/Tracking/__tests__/Replicable.Tracking.Deserialisation.test.js +253 -0
- package/Tracking/__tests__/Replicable.Tracking.MixinSchemaGeneration.test.d.ts +1 -0
- package/Tracking/__tests__/Replicable.Tracking.MixinSchemaGeneration.test.js +135 -0
- package/Tracking/__tests__/Replicable.Tracking.Struct.test.d.ts +1 -0
- package/Tracking/__tests__/Replicable.Tracking.Struct.test.js +66 -0
- package/Tracking/__tests__/Replicable.Tracking.Type.test.d.ts +1 -0
- package/Tracking/__tests__/Replicable.Tracking.Type.test.js +67 -0
- package/Transformers/Configurer.d.ts +39 -0
- package/Transformers/Configurer.js +415 -0
- package/Transformers/Constructor.d.ts +12 -0
- package/Transformers/Constructor.js +44 -0
- package/Transformers/Definitions.d.ts +102 -0
- package/Transformers/Definitions.js +626 -0
- package/Transformers/Loader.d.ts +45 -0
- package/Transformers/Loader.js +350 -0
- package/Transformers/Progress.d.ts +32 -0
- package/Transformers/Progress.js +429 -0
- package/Transformers/Reference.d.ts +37 -0
- package/Transformers/Reference.js +212 -0
- package/Transformers/SchemaGenerator.d.ts +102 -0
- package/Transformers/SchemaGenerator.js +564 -0
- package/Transformers/Serialiser.d.ts +31 -0
- package/Transformers/Serialiser.js +366 -0
- package/Transformers/Utils.d.ts +33 -0
- package/Transformers/Utils.js +287 -0
- package/Transformers/__tests__/Examples.d.ts +168 -0
- package/Transformers/__tests__/Examples.js +263 -0
- package/Transformers/__tests__/Replicable.Transformers.Definitions.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.Definitions.test.js +457 -0
- package/Transformers/__tests__/Replicable.Transformers.Loader.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.Loader.test.js +339 -0
- package/Transformers/__tests__/Replicable.Transformers.Progress.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.Progress.test.js +256 -0
- package/Transformers/__tests__/Replicable.Transformers.Reference.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.Reference.test.js +167 -0
- package/Transformers/__tests__/Replicable.Transformers.SchemaGenerator.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.SchemaGenerator.test.js +400 -0
- package/Transformers/__tests__/Replicable.Transformers.SchemaGeneratorOutput.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.SchemaGeneratorOutput.test.js +441 -0
- package/Transformers/__tests__/Replicable.Transformers.Serialiser.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.Serialiser.test.js +320 -0
- package/Transformers/__tests__/Replicable.Transformers.Utils.test.d.ts +1 -0
- package/Transformers/__tests__/Replicable.Transformers.Utils.test.js +534 -0
- package/__tests__/Replicable.Expressions.test.d.ts +1 -0
- package/__tests__/Replicable.Expressions.test.js +166 -0
- package/__tests__/Replicable.IDPool.test.d.ts +1 -0
- package/__tests__/Replicable.IDPool.test.js +11 -0
- package/__tests__/Replicable.ReplicableRegistry.test.d.ts +1 -0
- package/__tests__/Replicable.ReplicableRegistry.test.js +154 -0
- package/__tests__/Replicable.Serialisation.test.d.ts +1 -0
- package/__tests__/Replicable.Serialisation.test.js +283 -0
- package/package.json +14 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { Decorate } from "@bikky/decorators";
|
|
2
|
+
import { BikPath } from "@bikky/path";
|
|
3
|
+
import { VersionMap, WeakArray } from "@bikky/smart-collections";
|
|
4
|
+
import { ClassCategory, DataSymbol, describeObject, generateDataName, isPrimitiveType, TypeSymbol } from "../Constants/SerialisationTypes.js";
|
|
5
|
+
import { GetAllVersions, GetVersionController } from "../Constants/Versions.js";
|
|
6
|
+
import { ReplAPI } from "../Expressions/TypeRegistry/ReplAPI.js";
|
|
7
|
+
import { ExpressionScopes } from "../Expressions/TypeRegistry/Registry.js";
|
|
8
|
+
import { Progress } from "../Transformers/Progress.js";
|
|
9
|
+
const Primitives = ["undefined", "string", "number", "boolean"];
|
|
10
|
+
export class ReplicableClass {
|
|
11
|
+
constructor(category, typeClass, opts) {
|
|
12
|
+
var _a, _b, _c, _d, _e;
|
|
13
|
+
//Items are stored on the object itself (or prototype itself) so that
|
|
14
|
+
// they survive mixins and stuff.
|
|
15
|
+
this.properties = new VersionMap(GetVersionController());
|
|
16
|
+
this.functions = new VersionMap(GetVersionController());
|
|
17
|
+
this.finalised_properties = new Map();
|
|
18
|
+
this.finalised_functions = new Map();
|
|
19
|
+
this.finalised_propertyNames = [];
|
|
20
|
+
this.finalised_functionNames = [];
|
|
21
|
+
this.finalised_ownPropertyNames = [];
|
|
22
|
+
this.finalised_ownFunctionNames = [];
|
|
23
|
+
//This is a list of all the parameters on the class that can be used to uniquely identify this instance
|
|
24
|
+
// when reporting errors.
|
|
25
|
+
this.liveIDs = [];
|
|
26
|
+
//This is a list of all the parameters on the data that can be used to uniquely identify this instance
|
|
27
|
+
// when reporting errors.
|
|
28
|
+
this.dataIDs = [];
|
|
29
|
+
this.parents = [];
|
|
30
|
+
//Children is not used for anything except some fancy validation checking by Arkhaven.
|
|
31
|
+
this.children = new WeakArray();
|
|
32
|
+
this.classConstructor = typeClass;
|
|
33
|
+
typeClass.prototype[TypeSymbol] = this;
|
|
34
|
+
this.category = category;
|
|
35
|
+
if ("DefinitionType" in this.classConstructor && !("DataIsType" in this.classConstructor)) {
|
|
36
|
+
throw new Error(`All classes which specify a DefinitionType must also specify a DataIsType function.\n${this.classConstructor.name} does not.`);
|
|
37
|
+
}
|
|
38
|
+
this.opts = {
|
|
39
|
+
version: opts.version,
|
|
40
|
+
file: opts.file,
|
|
41
|
+
typescriptTypeName: (_b = (_a = opts.typescriptTypeName) !== null && _a !== void 0 ? _a : opts.name) !== null && _b !== void 0 ? _b : this.classConstructor.name,
|
|
42
|
+
dataTypeName: (_d = (_c = opts.dataTypeName) !== null && _c !== void 0 ? _c : (opts.name ? generateDataName(opts.name) : undefined)) !== null && _d !== void 0 ? _d : generateDataName(this.classConstructor.name),
|
|
43
|
+
abstract: (_e = opts.abstract) !== null && _e !== void 0 ? _e : false
|
|
44
|
+
};
|
|
45
|
+
let parent = this.classConstructor.prototype.__proto__;
|
|
46
|
+
while (parent && parent.__proto__ !== Object) {
|
|
47
|
+
if (parent[TypeSymbol]) {
|
|
48
|
+
this.parents.push(parent[TypeSymbol]);
|
|
49
|
+
}
|
|
50
|
+
parent = parent.__proto__;
|
|
51
|
+
}
|
|
52
|
+
this.parents = [...new Set(this.removeParentsParentsFromArray(this.parents))];
|
|
53
|
+
for (let parent of this.parents) {
|
|
54
|
+
parent.children.push(this);
|
|
55
|
+
}
|
|
56
|
+
this.rule = new ReplAPI("Repl", this);
|
|
57
|
+
Progress.FinishReplicableType(this);
|
|
58
|
+
}
|
|
59
|
+
getIDAsString(val, data = false) {
|
|
60
|
+
if (data) {
|
|
61
|
+
if (this.dataIDs.length === 0)
|
|
62
|
+
return `(<${this.opts.dataTypeName}>` + describeObject(val) + ")";
|
|
63
|
+
return `(<${this.opts.dataTypeName}>` + this.dataIDs.map((e) => `${e}= ${val[e]}`).join(", ") + ")";
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
if (this.liveIDs.length === 0)
|
|
67
|
+
return `(<${this.opts.typescriptTypeName}>` + describeObject(val) + ")";
|
|
68
|
+
return `(<${this.opts.typescriptTypeName}>` + this.liveIDs.map((e) => `${e}= ${val[e]}`).join(", ") + ")";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
getAppropriateEnclosingRule() {
|
|
72
|
+
let [_, rule] = ExpressionScopes.GetScopeChain(this.opts.dataTypeName);
|
|
73
|
+
if (rule)
|
|
74
|
+
return rule;
|
|
75
|
+
for (let parent of this.parents) {
|
|
76
|
+
rule = parent.getAppropriateEnclosingRule();
|
|
77
|
+
if (rule)
|
|
78
|
+
return rule;
|
|
79
|
+
}
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
removeParentsParentsFromArray(parents) {
|
|
83
|
+
let newParents = [...parents];
|
|
84
|
+
for (let i = 0; i < this.parents.length; i++) {
|
|
85
|
+
let parent = this.parents[i];
|
|
86
|
+
newParents = parent.removeParentsParentsFromArray(newParents);
|
|
87
|
+
}
|
|
88
|
+
let parentsParents = new Set(this.parents.flatMap((e) => e.parents));
|
|
89
|
+
newParents = newParents.filter((e) => !parentsParents.has(e));
|
|
90
|
+
return newParents;
|
|
91
|
+
}
|
|
92
|
+
isObjectOfThisType(object) {
|
|
93
|
+
if (typeof object !== "object" || object === null) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (object[TypeSymbol] === this) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
while (object.__proto__ && object.__proto__ !== Object.prototype) {
|
|
100
|
+
if (object.__proto__[TypeSymbol] === this) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
object = object.__proto__;
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
isChildTypeOfThisType(specificType) {
|
|
108
|
+
if ((typeof specificType != "object" && typeof specificType !== "function") || specificType == null)
|
|
109
|
+
return false;
|
|
110
|
+
if (specificType == this)
|
|
111
|
+
return true;
|
|
112
|
+
if (specificType instanceof ReplicableClass) {
|
|
113
|
+
for (let parent of specificType.parents) {
|
|
114
|
+
if (this.isChildTypeOfThisType(parent)) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return this.isObjectOfThisType(specificType.classConstructor.prototype);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
return this.isObjectOfThisType(specificType.prototype);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
getPropDefinition(version, property) {
|
|
125
|
+
var _a;
|
|
126
|
+
let definition = (_a = this.finalised_properties.get(version)) === null || _a === void 0 ? void 0 : _a[property];
|
|
127
|
+
if (!definition) {
|
|
128
|
+
throw new Error(`Failed to retrieve definition for property ${property}, as it was not found in class ${this.opts.typescriptTypeName}`);
|
|
129
|
+
}
|
|
130
|
+
return definition;
|
|
131
|
+
}
|
|
132
|
+
getPropHistoryDefinition(property) {
|
|
133
|
+
let allDefinitions = {};
|
|
134
|
+
for (let version of GetAllVersions()) {
|
|
135
|
+
let history = this.finalised_properties.get(version);
|
|
136
|
+
allDefinitions[version] = history[property];
|
|
137
|
+
}
|
|
138
|
+
return allDefinitions;
|
|
139
|
+
}
|
|
140
|
+
addProperty(version, property, data) {
|
|
141
|
+
var _a, _b;
|
|
142
|
+
let propDef = Object.assign(Object.assign({}, data), { property,
|
|
143
|
+
version, dataName: (_b = (_a = data.customLoad) !== null && _a !== void 0 ? _a : data.dataName) !== null && _b !== void 0 ? _b : generateDataName(property) });
|
|
144
|
+
this.properties.set(version, property, propDef);
|
|
145
|
+
switch (propDef.id) {
|
|
146
|
+
case "Live":
|
|
147
|
+
this.liveIDs.push(property);
|
|
148
|
+
break;
|
|
149
|
+
case "Data":
|
|
150
|
+
this.dataIDs.push(propDef.dataName);
|
|
151
|
+
break;
|
|
152
|
+
case true:
|
|
153
|
+
this.liveIDs.push(property);
|
|
154
|
+
this.dataIDs.push(propDef.dataName);
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
removeProperty(version, property, opts) {
|
|
159
|
+
let propDef = Object.assign({ property,
|
|
160
|
+
version, removed: true, dataName: generateDataName(property) }, opts);
|
|
161
|
+
this.properties.set(version, property, propDef);
|
|
162
|
+
}
|
|
163
|
+
addFunction(version, funcName, outputType, parameters, options) {
|
|
164
|
+
var _a;
|
|
165
|
+
let dataName = (_a = options === null || options === void 0 ? void 0 : options.dataName) !== null && _a !== void 0 ? _a : generateDataName(funcName);
|
|
166
|
+
this.functions.set(version, funcName, {
|
|
167
|
+
dataName,
|
|
168
|
+
funcName,
|
|
169
|
+
parameters,
|
|
170
|
+
outputType,
|
|
171
|
+
options,
|
|
172
|
+
version
|
|
173
|
+
});
|
|
174
|
+
// this.rule.addFunction(version as Versions, { name: funcName, exprName: dataName }, outputType, parameters);
|
|
175
|
+
}
|
|
176
|
+
static typesToString(allTypes) {
|
|
177
|
+
return allTypes.map((e) => {
|
|
178
|
+
if (typeof e === "string")
|
|
179
|
+
return e;
|
|
180
|
+
if (typeof e === "undefined")
|
|
181
|
+
return "undefined";
|
|
182
|
+
if (e === null)
|
|
183
|
+
return "null";
|
|
184
|
+
return isPrimitiveType(e) ? e.name.toLowerCase() : e.opts.dataTypeName;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
getOriginalPropertyValue(object, property) {
|
|
188
|
+
var _a;
|
|
189
|
+
let def = this.properties.get(this.opts.version, property);
|
|
190
|
+
if (!def)
|
|
191
|
+
return undefined;
|
|
192
|
+
if ("removed" in def)
|
|
193
|
+
return undefined;
|
|
194
|
+
let data = object[DataSymbol];
|
|
195
|
+
return (_a = data[def.dataName]) !== null && _a !== void 0 ? _a : def.default;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Used for some fancy Arkhaven type checking.
|
|
199
|
+
*/
|
|
200
|
+
getChildClassesNames() {
|
|
201
|
+
return this.children.map((e) => e === null || e === void 0 ? void 0 : e.opts.typescriptTypeName).filter((e) => !!e);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const ClassDecorator = Decorate.Class({
|
|
205
|
+
onDecorate: (classConstructor, type, opts) => {
|
|
206
|
+
new ReplicableClass(type, classConstructor, opts);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
export function Type(version, opts) {
|
|
210
|
+
return ClassDecorator(ClassCategory.Pointer, Object.assign(Object.assign({}, (opts !== null && opts !== void 0 ? opts : {})), { version: version, file: BikPath.getCallerFilepath() }));
|
|
211
|
+
}
|
|
212
|
+
export function Struct(version, opts) {
|
|
213
|
+
return ClassDecorator(ClassCategory.Struct, Object.assign(Object.assign({}, (opts !== null && opts !== void 0 ? opts : {})), { version: version, file: BikPath.getCallerFilepath() }));
|
|
214
|
+
}
|
|
215
|
+
export function CustomReplicableType(version, _class, opts) {
|
|
216
|
+
if (!("prototype" in _class)) {
|
|
217
|
+
_class.prototype = {};
|
|
218
|
+
}
|
|
219
|
+
new ReplicableClass(ClassCategory.Custom, _class, Object.assign(Object.assign({}, (opts !== null && opts !== void 0 ? opts : {})), { version: version, file: BikPath.getCallerFilepath() }));
|
|
220
|
+
return _class;
|
|
221
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Versions } from "../Constants/Versions.js";
|
|
2
|
+
export interface FunctionOptions {
|
|
3
|
+
dataName?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function Method(version: Versions, properties: any[][], outputTypes: any[], options?: FunctionOptions): (_class: any, property: (string | symbol)) => {
|
|
6
|
+
configurable: true;
|
|
7
|
+
enumerable: true;
|
|
8
|
+
writable: true;
|
|
9
|
+
};
|
|
10
|
+
export declare function Accessor(version: Versions, outputType: any[], options?: FunctionOptions): (_class: any, property: (string | symbol)) => {
|
|
11
|
+
configurable: true;
|
|
12
|
+
enumerable: true;
|
|
13
|
+
writable: true;
|
|
14
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Progress } from "../Transformers/Progress.js";
|
|
2
|
+
import { FormatPropInput } from "./Property.js";
|
|
3
|
+
export function Method(version, properties, outputTypes, options) {
|
|
4
|
+
let compOutputTypes = FormatPropInput(outputTypes);
|
|
5
|
+
let compProperties = [];
|
|
6
|
+
for (let i = 0; i < properties.length; i++) {
|
|
7
|
+
compProperties[i] = FormatPropInput(properties[1]);
|
|
8
|
+
}
|
|
9
|
+
return (_class, property) => {
|
|
10
|
+
if (typeof property === "symbol") {
|
|
11
|
+
throw new Error("Cannot use a symbol as a property name.");
|
|
12
|
+
}
|
|
13
|
+
// Decorating a property typically returns the class' .prototype value instead of the class itself,
|
|
14
|
+
// we want the class so we fix that here (with an exception for interfaces that have modules as representatives):
|
|
15
|
+
if (!("prototype" in _class) && "constructor" in _class)
|
|
16
|
+
_class = _class.constructor;
|
|
17
|
+
Progress.RegisterFunctionAdd(_class, [version, property, compOutputTypes, compProperties, options !== null && options !== void 0 ? options : {}]);
|
|
18
|
+
return {
|
|
19
|
+
configurable: true,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
writable: true
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function Accessor(version, outputType, options) {
|
|
26
|
+
return Method(version, [], outputType, options !== null && options !== void 0 ? options : {});
|
|
27
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ExpressionScopes } from "../Expressions/TypeRegistry/Registry.js";
|
|
2
|
+
export var GlobalGroup;
|
|
3
|
+
(function (GlobalGroup) {
|
|
4
|
+
const groups = new Map();
|
|
5
|
+
function getGroupID(object) {
|
|
6
|
+
let type = object.__proto__.constructor;
|
|
7
|
+
if (type.Reference) {
|
|
8
|
+
return type.Reference(object).join(".");
|
|
9
|
+
}
|
|
10
|
+
else if (typeof object !== "object") {
|
|
11
|
+
return object;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return JSON.stringify(object);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
GlobalGroup.getGroupID = getGroupID;
|
|
18
|
+
function AddToGroup(name, object) {
|
|
19
|
+
var _a;
|
|
20
|
+
let type = object.__proto__.constructor;
|
|
21
|
+
if (type === Object) {
|
|
22
|
+
type = (_a = object.Class) !== null && _a !== void 0 ? _a : Object;
|
|
23
|
+
}
|
|
24
|
+
let group = groups.get(name);
|
|
25
|
+
if (!group) {
|
|
26
|
+
group = {};
|
|
27
|
+
groups.set(name, group);
|
|
28
|
+
ExpressionScopes.addGlobalVariable(name, [type], group, "Map");
|
|
29
|
+
}
|
|
30
|
+
group[getGroupID(object)] = object;
|
|
31
|
+
}
|
|
32
|
+
GlobalGroup.AddToGroup = AddToGroup;
|
|
33
|
+
function AddToGroups(groupNames, object) {
|
|
34
|
+
for (let name of groupNames) {
|
|
35
|
+
AddToGroup(name, object);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
GlobalGroup.AddToGroups = AddToGroups;
|
|
39
|
+
})(GlobalGroup || (GlobalGroup = {}));
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Versions } from "../Constants/Versions.js";
|
|
2
|
+
import { ReplicableClassConstructor } from "./Types.js";
|
|
3
|
+
import { IDPool } from "../IDPool.js";
|
|
4
|
+
import UUID = IDPool.UUID;
|
|
5
|
+
import { Primitive, PropertyTypes } from "../Constants/SerialisationTypes.js";
|
|
6
|
+
import { ReplicableClass } from "./Class.js";
|
|
7
|
+
import { Expression } from "../Expressions/Expression.js";
|
|
8
|
+
import { ExpressionConfiguration } from "../Expressions/EvaluatorSteps.js";
|
|
9
|
+
export type ComplexPropertyType = {
|
|
10
|
+
type: (string | any)[];
|
|
11
|
+
reference?: boolean;
|
|
12
|
+
serialised?: boolean;
|
|
13
|
+
data?: boolean;
|
|
14
|
+
} & ({} | {
|
|
15
|
+
type: String;
|
|
16
|
+
restrictedTo?: readonly (number | string)[];
|
|
17
|
+
} | {
|
|
18
|
+
type: Number;
|
|
19
|
+
restrictedTo?: readonly (number | string)[];
|
|
20
|
+
} | {
|
|
21
|
+
array: boolean | 2;
|
|
22
|
+
} | {
|
|
23
|
+
mapKey: typeof String | typeof Number | typeof Expression | (typeof String | typeof Number | typeof Expression)[];
|
|
24
|
+
restrictedTo?: readonly (number | string)[];
|
|
25
|
+
} | {
|
|
26
|
+
dictKey: typeof String | typeof Number | (typeof String | typeof Number)[];
|
|
27
|
+
restrictedTo?: readonly (number | string)[];
|
|
28
|
+
});
|
|
29
|
+
export interface PropertyOptions {
|
|
30
|
+
computed?: boolean | "manualLoad";
|
|
31
|
+
customLoad?: string;
|
|
32
|
+
readonly?: boolean;
|
|
33
|
+
manualRestore?: boolean;
|
|
34
|
+
expression?: boolean;
|
|
35
|
+
setter?: boolean;
|
|
36
|
+
inline?: boolean;
|
|
37
|
+
optional?: boolean;
|
|
38
|
+
default?: any;
|
|
39
|
+
dataName?: string;
|
|
40
|
+
id?: "Live" | "Data" | true;
|
|
41
|
+
customDataType?: ReplicableClassConstructor | UUID | string | (string | any)[] | ComplexPropertyType | ComplexPropertyType[];
|
|
42
|
+
}
|
|
43
|
+
export interface PropertyLoadingTypeInfo {
|
|
44
|
+
types: (ReplicableClass | Primitive)[] | string;
|
|
45
|
+
sortIndex: string;
|
|
46
|
+
modifiers: PropertyTypes;
|
|
47
|
+
restrictedTo?: (string | number)[];
|
|
48
|
+
keyType?: (typeof String | typeof Number | typeof Expression)[];
|
|
49
|
+
}
|
|
50
|
+
export interface PropertySerialiseTypeInfo {
|
|
51
|
+
types: (ReplicableClass | Primitive)[];
|
|
52
|
+
sortIndex: string;
|
|
53
|
+
modifiers: PropertyTypes;
|
|
54
|
+
restrictedTo?: (string | number)[];
|
|
55
|
+
keyType?: (typeof String | typeof Number | typeof Expression)[];
|
|
56
|
+
}
|
|
57
|
+
export interface PropertyConfiguration {
|
|
58
|
+
name: string;
|
|
59
|
+
load: {
|
|
60
|
+
present: true | false | "optional";
|
|
61
|
+
skipLoad: boolean;
|
|
62
|
+
name: string;
|
|
63
|
+
default: any;
|
|
64
|
+
possibleModifiers: PropertyTypes;
|
|
65
|
+
types: PropertyLoadingTypeInfo[];
|
|
66
|
+
};
|
|
67
|
+
serialisation: {
|
|
68
|
+
present: true | false | "writeOnly";
|
|
69
|
+
inline: boolean;
|
|
70
|
+
possibleModifiers: PropertyTypes;
|
|
71
|
+
types: PropertySerialiseTypeInfo[];
|
|
72
|
+
};
|
|
73
|
+
expressionForProperty: {
|
|
74
|
+
[version in Versions | string]: ExpressionConfiguration;
|
|
75
|
+
} | undefined;
|
|
76
|
+
expressionForValue: {
|
|
77
|
+
[version in Versions | string]: ExpressionConfiguration;
|
|
78
|
+
} | undefined;
|
|
79
|
+
expressionForKey: {
|
|
80
|
+
[version in Versions | string]: ExpressionConfiguration;
|
|
81
|
+
} | undefined;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Converts a prop input of [Class], "ClassName", or any other configuration into { type: [Class] }.
|
|
85
|
+
* It does do a ton of fancy string manipulation, so you can enter "Serialised:ClassName" etc. to get
|
|
86
|
+
* the serialised version without needing to write out an entire complex type.
|
|
87
|
+
* @param raw The raw input.
|
|
88
|
+
* @constructor
|
|
89
|
+
*/
|
|
90
|
+
export declare function FormatPropInput(raw: any): ComplexPropertyType[];
|
|
91
|
+
export declare function Property(version: Versions, type: ComplexPropertyType | ComplexPropertyType[], options?: PropertyOptions): (_class: any, property: (string | symbol)) => void;
|
|
92
|
+
export declare function Property(version: Versions, type: any, options?: PropertyOptions): (_class: any, property: (string | symbol)) => void;
|
|
93
|
+
export declare namespace Property {
|
|
94
|
+
function Remove(version: Versions, opts: Parameters<ReplicableClass["removeProperty"]>[2]): (_class: any, property: (string | symbol)) => void;
|
|
95
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { isPrimitiveType } from "../Constants/SerialisationTypes.js";
|
|
2
|
+
import { Progress } from "../Transformers/Progress.js";
|
|
3
|
+
/**
|
|
4
|
+
* Converts a prop input of [Class], "ClassName", or any other configuration into { type: [Class] }.
|
|
5
|
+
* It does do a ton of fancy string manipulation, so you can enter "Serialised:ClassName" etc. to get
|
|
6
|
+
* the serialised version without needing to write out an entire complex type.
|
|
7
|
+
* @param raw The raw input.
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
10
|
+
export function FormatPropInput(raw) {
|
|
11
|
+
if (Array.isArray(raw)) {
|
|
12
|
+
return raw.flatMap(FormatPropInput);
|
|
13
|
+
}
|
|
14
|
+
if (typeof raw !== "string") {
|
|
15
|
+
if (Array.isArray(raw)) {
|
|
16
|
+
return [{ type: raw }];
|
|
17
|
+
}
|
|
18
|
+
if (isPrimitiveType(raw)) {
|
|
19
|
+
return [{ type: [raw] }];
|
|
20
|
+
}
|
|
21
|
+
if ("type" in raw) {
|
|
22
|
+
if (!Array.isArray(raw.type)) {
|
|
23
|
+
raw = [Object.assign(Object.assign({}, raw), { type: [raw.type] })];
|
|
24
|
+
}
|
|
25
|
+
else if (raw.__proto__ === Object.prototype) {
|
|
26
|
+
return [raw];
|
|
27
|
+
}
|
|
28
|
+
return raw;
|
|
29
|
+
}
|
|
30
|
+
return [{ type: [raw] }];
|
|
31
|
+
}
|
|
32
|
+
//raw is string:
|
|
33
|
+
let input = raw.trim();
|
|
34
|
+
let complex = {
|
|
35
|
+
type: []
|
|
36
|
+
};
|
|
37
|
+
if (input.endsWith("[][]")) {
|
|
38
|
+
complex = Object.assign(Object.assign({}, complex), { array: 2 });
|
|
39
|
+
input = input.slice(0, -4);
|
|
40
|
+
}
|
|
41
|
+
else if (input.endsWith("[]")) {
|
|
42
|
+
complex = Object.assign(Object.assign({}, complex), { array: true });
|
|
43
|
+
input = input.slice(0, -2);
|
|
44
|
+
}
|
|
45
|
+
if (input.startsWith("{")) {
|
|
46
|
+
input = input.slice(1, -1);
|
|
47
|
+
let [index, type] = input.split(":", 1).map((e) => e.trim());
|
|
48
|
+
let indexType;
|
|
49
|
+
switch (index.toLowerCase()) {
|
|
50
|
+
case "string": {
|
|
51
|
+
indexType = String;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case "number": {
|
|
55
|
+
indexType = Number;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
default: {
|
|
59
|
+
throw new Error(`Map index type is invalid: ${index}.`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
complex = Object.assign(Object.assign({}, complex), { dictKey: indexType });
|
|
63
|
+
input = type;
|
|
64
|
+
}
|
|
65
|
+
if (input.includes(":")) {
|
|
66
|
+
let [restraint, type] = input.split(":", 1);
|
|
67
|
+
switch (restraint.toLowerCase()) {
|
|
68
|
+
case "reference": {
|
|
69
|
+
complex.reference = true;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case "serialised": {
|
|
73
|
+
complex.serialised = true;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case "data": {
|
|
77
|
+
complex.data = true;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
default: {
|
|
81
|
+
throw new Error(`Property type prefix ${restraint} is unknown.`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
input = type;
|
|
85
|
+
}
|
|
86
|
+
complex.type = [input];
|
|
87
|
+
return [complex];
|
|
88
|
+
}
|
|
89
|
+
export function Property(version, type, options) {
|
|
90
|
+
let compType = FormatPropInput(type);
|
|
91
|
+
let compCustomType = undefined;
|
|
92
|
+
if (options && options.customDataType) {
|
|
93
|
+
compCustomType = FormatPropInput(options.customDataType);
|
|
94
|
+
}
|
|
95
|
+
return (_class, property) => {
|
|
96
|
+
if (typeof property === "symbol")
|
|
97
|
+
throw new Error("Cannot use a symbol as a property name.");
|
|
98
|
+
// Decorating a property typically returns the class' .prototype value instead of the class itself,
|
|
99
|
+
// we want the class so we fix that here (with an exception for interfaces that have modules as representatives):
|
|
100
|
+
if (!("prototype" in _class) && "constructor" in _class)
|
|
101
|
+
_class = _class.constructor;
|
|
102
|
+
let propOpts = Object.assign(Object.assign({}, options), { type: compType });
|
|
103
|
+
if (compCustomType)
|
|
104
|
+
propOpts.customDataType = compCustomType;
|
|
105
|
+
Progress.RegisterPropertyLoad(_class, [version, property, propOpts]);
|
|
106
|
+
return {
|
|
107
|
+
configurable: true,
|
|
108
|
+
enumerable: true,
|
|
109
|
+
writable: true
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
(function (Property) {
|
|
114
|
+
function Remove(version, opts) {
|
|
115
|
+
return (_class, property) => {
|
|
116
|
+
Progress.RegisterPropertyRemove(_class, [version, property, opts]);
|
|
117
|
+
return {
|
|
118
|
+
configurable: true,
|
|
119
|
+
enumerable: true,
|
|
120
|
+
writable: true
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
Property.Remove = Remove;
|
|
125
|
+
})(Property || (Property = {}));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SourceMap } from "../Constants/SourceMaps.js";
|
|
2
|
+
import { ErrorStack } from "../Constants/Errors.js";
|
|
3
|
+
import { Primitive } from "../Constants/SerialisationTypes.js";
|
|
4
|
+
import { Versions } from "../Main.js";
|
|
5
|
+
import { ComplexPropertyType } from "./Property.js";
|
|
6
|
+
export interface ConstructorArgs<DefinitionType = any, OwnerType = any> {
|
|
7
|
+
data: DefinitionType | [type: string, data: any];
|
|
8
|
+
source: SourceMap;
|
|
9
|
+
owner?: OwnerType;
|
|
10
|
+
}
|
|
11
|
+
export type TypeClass = {
|
|
12
|
+
DefinitionType?: string | ComplexPropertyType | ComplexPropertyType[];
|
|
13
|
+
SerialisedType?: string | ComplexPropertyType | ComplexPropertyType[];
|
|
14
|
+
DataIsType?: (val: any, errors: string[]) => boolean;
|
|
15
|
+
Create?: (config: ConstructorArgs) => object;
|
|
16
|
+
Reference(value: any): any[];
|
|
17
|
+
Dereference(value: any[]): any;
|
|
18
|
+
};
|
|
19
|
+
export type StructClass = AbstractClass<object>;
|
|
20
|
+
export type CustomClass = {
|
|
21
|
+
name: string;
|
|
22
|
+
Create: (config: ConstructorArgs) => object;
|
|
23
|
+
DefinitionType?: string | ComplexPropertyType | ComplexPropertyType[];
|
|
24
|
+
SerialisedType?: string | ComplexPropertyType | ComplexPropertyType[];
|
|
25
|
+
DataIsType: (version: Versions, val: any, errors: ErrorStack) => boolean;
|
|
26
|
+
Reference(value: any): any[];
|
|
27
|
+
Dereference(value: any[]): any;
|
|
28
|
+
};
|
|
29
|
+
export type ReplicableBaseType = TypeClass | StructClass | CustomClass;
|
|
30
|
+
export type AnyReplType = ReplicableBaseType | Primitive;
|
|
31
|
+
export type ReplicableClassConstructor = ((TypeClass | StructClass) & Function) | (CustomClass & {
|
|
32
|
+
prototype: any;
|
|
33
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|