@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,102 @@
|
|
|
1
|
+
import { SetMap, SmartArray } from "@bikky/smart-collections";
|
|
2
|
+
import { Primitive } from "../Constants/SerialisationTypes.js";
|
|
3
|
+
import { ReplicableClass } from "../Tracking/Class.js";
|
|
4
|
+
import { ComplexPropertyType, PropertyConfiguration, PropertyLoadingTypeInfo } from "../Tracking/Property.js";
|
|
5
|
+
import { Versions } from "../Constants/Versions.js";
|
|
6
|
+
export declare namespace GeneratorUtilities {
|
|
7
|
+
const ReplRoot: any;
|
|
8
|
+
const ExpressionString = "`@{${string}}`";
|
|
9
|
+
const SerialisedExpressionString = "[ \"Expression\", string ]";
|
|
10
|
+
const GenerationForward = "// This file is automatically generated. Do not edit it, all edits will be overwritten on compile.";
|
|
11
|
+
const DefinitionForward: string;
|
|
12
|
+
interface CustomTypes {
|
|
13
|
+
ts: {
|
|
14
|
+
name: string;
|
|
15
|
+
DefinitionType: string | any[] | ComplexPropertyType[];
|
|
16
|
+
op: "&" | "|";
|
|
17
|
+
append?: string;
|
|
18
|
+
}[];
|
|
19
|
+
ser: {
|
|
20
|
+
name: string;
|
|
21
|
+
DefinitionType: string | any[] | ComplexPropertyType[];
|
|
22
|
+
op: "&" | "|";
|
|
23
|
+
append?: string;
|
|
24
|
+
}[];
|
|
25
|
+
def: {
|
|
26
|
+
name: string;
|
|
27
|
+
DefinitionType: string | any[] | ComplexPropertyType[];
|
|
28
|
+
op: "&" | "|";
|
|
29
|
+
append?: string;
|
|
30
|
+
}[];
|
|
31
|
+
}
|
|
32
|
+
function SortTypes(a: string | ReplicableClass | Primitive, b: string | ReplicableClass | Primitive): 1 | 0 | -1;
|
|
33
|
+
function SortLoadingInfo(a: PropertyLoadingTypeInfo, b: PropertyLoadingTypeInfo): 1 | 0 | -1;
|
|
34
|
+
function SortTypeContainers(a: string | {
|
|
35
|
+
type: ReplicableClass | Primitive;
|
|
36
|
+
}, b: string | {
|
|
37
|
+
type: ReplicableClass | Primitive;
|
|
38
|
+
}): 1 | 0 | -1;
|
|
39
|
+
function ToProjectPath(path: string): string;
|
|
40
|
+
function CalcProjectPath(rel: string | undefined, base: string): string;
|
|
41
|
+
function GenerateInterfaceFilepathForFile(file: string): string;
|
|
42
|
+
function GenerateAPIName(dataType: ReplicableClass | Primitive, style: "creation" | "definition" | "serialised" | "typescript", referencable: boolean): string;
|
|
43
|
+
interface GenerationDetails {
|
|
44
|
+
blocks: string[];
|
|
45
|
+
includes: SetMap<string, string>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generates the scheme for the value of a property ignoring modifiers like array, map and dict.
|
|
49
|
+
*
|
|
50
|
+
* Produces the quoted part of the following definitions:
|
|
51
|
+
* val: {[xx]: `(TypeA | TypeB | Expression)` } | Expression;
|
|
52
|
+
* val: `TypeA | TypeB | Expression`;
|
|
53
|
+
* val: `(TypeA | TypeB | Expression)`[] | Expression;
|
|
54
|
+
*
|
|
55
|
+
* Produces the back quoted part of the following serialised types:
|
|
56
|
+
* ser: [ "Dict", {[xx]: `[ "Primitive", TypeA | TypeB ]` } ] | [ "Expression", string ];
|
|
57
|
+
* ser: `[ "Primitive", TypeA | TypeB ] | [ "Expression", string ]`; <-- note expression included here.
|
|
58
|
+
* ser: [ "Array", `[ "Primitive", TypeA | TypeB ]` ] | [ "Expression", string ];
|
|
59
|
+
*
|
|
60
|
+
* @param className The name of the parent class of the property.
|
|
61
|
+
* @param types The property definition.
|
|
62
|
+
* @param gen The generation details which includes are added to.
|
|
63
|
+
* @param style Whether we're generating creation types, definition types or serialised types.
|
|
64
|
+
*/
|
|
65
|
+
function GenerateValueGroup(className: string, types: (ReplicableClass | Primitive)[], gen: GenerationDetails, forceInline: boolean | undefined, style: "creation" | "definition" | "serialised" | "typescript"): any;
|
|
66
|
+
function GenerateProperty(className: string, conf: PropertyConfiguration, gen: GenerationDetails, style: "creation" | "definition" | "serialised" | "typescript"): GenerationDetails;
|
|
67
|
+
function GenerateClassExtends(type: ReplicableClass, includes: SetMap<string, string>, style: "creation" | "definition" | "serialised"): string;
|
|
68
|
+
function GenerateClass(classType: ReplicableClass, gen: GenerationDetails, style: "creation" | "definition" | "serialised"): GenerationDetails;
|
|
69
|
+
function GenerateClassWithCustomDef(classType: ReplicableClass, gen: GenerationDetails, style: "definition" | "serialised"): GenerationDetails | undefined;
|
|
70
|
+
function GenerateCustomType(types: CustomTypes, gen: GenerationDetails, style: "definition" | "serialised" | "typescript"): void;
|
|
71
|
+
function GenerateImports(file: string, includes: SetMap<string, string>): string;
|
|
72
|
+
function GenerateDefinitionFile(file: string, repls: ReplicableClass[] | undefined, types: CustomTypes | undefined): string;
|
|
73
|
+
function GenerateTypescriptFile(includeFiles: SmartArray<any>, file: string): string;
|
|
74
|
+
}
|
|
75
|
+
export declare namespace SchemaGenerator {
|
|
76
|
+
function RegisterCustomTsInclude(type: {
|
|
77
|
+
name: string;
|
|
78
|
+
DefinitionType: any[];
|
|
79
|
+
}): void;
|
|
80
|
+
function RegisterCustomTsType(type: {
|
|
81
|
+
name: string;
|
|
82
|
+
DefinitionType: any[];
|
|
83
|
+
op: "&" | "|";
|
|
84
|
+
append?: string;
|
|
85
|
+
}): void;
|
|
86
|
+
function RegisterCustomSerialisedType(type: {
|
|
87
|
+
name: string;
|
|
88
|
+
DefinitionType: any[];
|
|
89
|
+
op: "&" | "|";
|
|
90
|
+
append?: string;
|
|
91
|
+
}): void;
|
|
92
|
+
function RegisterCustomDefinitionType(type: {
|
|
93
|
+
name: string;
|
|
94
|
+
DefinitionType: any[];
|
|
95
|
+
op: "&" | "|";
|
|
96
|
+
append?: string;
|
|
97
|
+
}): void;
|
|
98
|
+
function GenerateAllInterfaceTypes(version: string | Versions, options: {
|
|
99
|
+
open(file: string): boolean;
|
|
100
|
+
write(file: string, text: string): boolean;
|
|
101
|
+
}): void;
|
|
102
|
+
}
|
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
import { BikPath } from "@bikky/path";
|
|
2
|
+
import { ArrayMap, SetMap } from "@bikky/smart-collections";
|
|
3
|
+
import { ClassCategory, describeObject, isPrimitiveType, primitiveTypeName, PropertyTypes } from "../Constants/SerialisationTypes.js";
|
|
4
|
+
import { ReplicableRegistry } from "../Constants/ReplicableRegistry.js";
|
|
5
|
+
import { ReplicableClass } from "../Tracking/Class.js";
|
|
6
|
+
import { FormatPropInput } from "../Tracking/Property.js";
|
|
7
|
+
import { Versions } from "../Constants/Versions.js";
|
|
8
|
+
import { Expression } from "../Expressions/Expression.js";
|
|
9
|
+
var getCurrentFilepath = BikPath.getCurrentFilepath;
|
|
10
|
+
export var GeneratorUtilities;
|
|
11
|
+
(function (GeneratorUtilities) {
|
|
12
|
+
GeneratorUtilities.ReplRoot = BikPath.join(getCurrentFilepath(), "../../../../../");
|
|
13
|
+
GeneratorUtilities.ExpressionString = "`@{${string}}`";
|
|
14
|
+
GeneratorUtilities.SerialisedExpressionString = `[ "Expression", string ]`;
|
|
15
|
+
GeneratorUtilities.GenerationForward = "// This file is automatically generated. Do not edit it, all edits will be overwritten on compile.";
|
|
16
|
+
GeneratorUtilities.DefinitionForward = GeneratorUtilities.GenerationForward + `
|
|
17
|
+
// This file contains the typescript types for the data definitions for the corresponding
|
|
18
|
+
// types in the .ts file this file is named after.
|
|
19
|
+
`.trim();
|
|
20
|
+
function SortTypes(a, b) {
|
|
21
|
+
let aName = a instanceof ReplicableClass ? a.opts.typescriptTypeName
|
|
22
|
+
: isPrimitiveType(a) ? primitiveTypeName(a) : a;
|
|
23
|
+
let bName = b instanceof ReplicableClass ? b.opts.typescriptTypeName
|
|
24
|
+
: isPrimitiveType(b) ? primitiveTypeName(b) : b;
|
|
25
|
+
return aName == bName ? 0 : aName < bName ? -1 : 1;
|
|
26
|
+
}
|
|
27
|
+
GeneratorUtilities.SortTypes = SortTypes;
|
|
28
|
+
function SortLoadingInfo(a, b) {
|
|
29
|
+
return a.sortIndex < b.sortIndex ? -1 : a.sortIndex > b.sortIndex ? 1 : 0;
|
|
30
|
+
}
|
|
31
|
+
GeneratorUtilities.SortLoadingInfo = SortLoadingInfo;
|
|
32
|
+
function SortTypeContainers(a, b) {
|
|
33
|
+
return SortTypes(typeof a === "string" ? a : a.type, typeof b === "string" ? b : b.type);
|
|
34
|
+
}
|
|
35
|
+
GeneratorUtilities.SortTypeContainers = SortTypeContainers;
|
|
36
|
+
function ToProjectPath(path) {
|
|
37
|
+
return path.replace(GeneratorUtilities.ReplRoot, "/");
|
|
38
|
+
}
|
|
39
|
+
GeneratorUtilities.ToProjectPath = ToProjectPath;
|
|
40
|
+
function CalcProjectPath(rel, base) {
|
|
41
|
+
return rel ? ToProjectPath(BikPath.join(base, rel)) : ToProjectPath(base);
|
|
42
|
+
}
|
|
43
|
+
GeneratorUtilities.CalcProjectPath = CalcProjectPath;
|
|
44
|
+
function GenerateInterfaceFilepathForFile(file) {
|
|
45
|
+
return file.replace(/\.[jt]s/, ".data.d.ts");
|
|
46
|
+
}
|
|
47
|
+
GeneratorUtilities.GenerateInterfaceFilepathForFile = GenerateInterfaceFilepathForFile;
|
|
48
|
+
function GenerateAPIName(dataType, style, referencable) {
|
|
49
|
+
if (isPrimitiveType(dataType)) {
|
|
50
|
+
return primitiveTypeName(dataType);
|
|
51
|
+
}
|
|
52
|
+
let dataTypeName = dataType.opts.dataTypeName;
|
|
53
|
+
return style === "typescript" ? dataTypeName : style === "creation" ? dataTypeName :
|
|
54
|
+
style === "definition" ? dataTypeName + "Definition" :
|
|
55
|
+
referencable ? dataTypeName + "SerialisedReference" :
|
|
56
|
+
dataTypeName + "Serialised";
|
|
57
|
+
}
|
|
58
|
+
GeneratorUtilities.GenerateAPIName = GenerateAPIName;
|
|
59
|
+
/**
|
|
60
|
+
* Generates the scheme for the value of a property ignoring modifiers like array, map and dict.
|
|
61
|
+
*
|
|
62
|
+
* Produces the quoted part of the following definitions:
|
|
63
|
+
* val: {[xx]: `(TypeA | TypeB | Expression)` } | Expression;
|
|
64
|
+
* val: `TypeA | TypeB | Expression`;
|
|
65
|
+
* val: `(TypeA | TypeB | Expression)`[] | Expression;
|
|
66
|
+
*
|
|
67
|
+
* Produces the back quoted part of the following serialised types:
|
|
68
|
+
* ser: [ "Dict", {[xx]: `[ "Primitive", TypeA | TypeB ]` } ] | [ "Expression", string ];
|
|
69
|
+
* ser: `[ "Primitive", TypeA | TypeB ] | [ "Expression", string ]`; <-- note expression included here.
|
|
70
|
+
* ser: [ "Array", `[ "Primitive", TypeA | TypeB ]` ] | [ "Expression", string ];
|
|
71
|
+
*
|
|
72
|
+
* @param className The name of the parent class of the property.
|
|
73
|
+
* @param types The property definition.
|
|
74
|
+
* @param gen The generation details which includes are added to.
|
|
75
|
+
* @param style Whether we're generating creation types, definition types or serialised types.
|
|
76
|
+
*/
|
|
77
|
+
function GenerateValueGroup(className, types, gen, forceInline = false, style) {
|
|
78
|
+
let sortedTypes = types.toSorted(SortTypes);
|
|
79
|
+
let primTypes = [];
|
|
80
|
+
let value = sortedTypes.map((type) => {
|
|
81
|
+
if (style === "serialised") {
|
|
82
|
+
if (isPrimitiveType(type)) {
|
|
83
|
+
primTypes.push(primitiveTypeName(type));
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
else if (ClassCategory.isType(type.category, ClassCategory.Pointer) && !forceInline) {
|
|
87
|
+
return GenerateAPIName(type, style, true);
|
|
88
|
+
}
|
|
89
|
+
else if (ClassCategory.isType(type.category, ClassCategory.Custom)) {
|
|
90
|
+
if (ClassCategory.isType(type.category, ClassCategory.Pointer) && !forceInline) {
|
|
91
|
+
return `[ "${type.opts.dataTypeName}" | string, ${GenerateAPIName(type, style, false)} | null ]`;
|
|
92
|
+
}
|
|
93
|
+
return `[ "${type.opts.dataTypeName}", ${GenerateAPIName(type, style, false)} ]`;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return `[ "${type.opts.dataTypeName}" | string, ${GenerateAPIName(type, style, false)} | null ]`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (style === "creation" && type instanceof ReplicableClass) {
|
|
100
|
+
return GenerateAPIName(type, style, false) + " | " + GenerateAPIName(type, "definition", true);
|
|
101
|
+
}
|
|
102
|
+
if (style === "typescript" && type instanceof ReplicableClass) {
|
|
103
|
+
return GenerateAPIName(type, style, false);
|
|
104
|
+
}
|
|
105
|
+
return GenerateAPIName(type, style, false);
|
|
106
|
+
}).sort().filter((e) => e).join(" | ");
|
|
107
|
+
if (primTypes.length > 0) {
|
|
108
|
+
let separator = value.trim().length > 0 ? " | " : "";
|
|
109
|
+
if (style === "serialised") {
|
|
110
|
+
value = `[ "Primitive", ${primTypes.sort().join(" | ")} ]` + separator + value;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
value = primTypes.sort().join(" | ") + separator + value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//Add required imports.
|
|
117
|
+
for (let type of sortedTypes) {
|
|
118
|
+
if (type instanceof ReplicableClass) {
|
|
119
|
+
if (style === "typescript") {
|
|
120
|
+
gen.includes.push(CalcProjectPath(undefined, type.opts.file), GenerateAPIName(type, style, true));
|
|
121
|
+
}
|
|
122
|
+
else if (style === "creation") {
|
|
123
|
+
gen.includes.push(GenerateInterfaceFilepathForFile(CalcProjectPath(undefined, type.opts.file)), GenerateAPIName(type, "definition", true));
|
|
124
|
+
gen.includes.push(CalcProjectPath(undefined, type.opts.file), GenerateAPIName(type, style, true));
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
let useReference = ClassCategory.isType(type.category, ClassCategory.Pointer) && !forceInline;
|
|
128
|
+
gen.includes.push(GenerateInterfaceFilepathForFile(CalcProjectPath(undefined, type.opts.file)), GenerateAPIName(type, style, useReference));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
GeneratorUtilities.GenerateValueGroup = GenerateValueGroup;
|
|
135
|
+
function GenerateProperty(className, conf, gen, style) {
|
|
136
|
+
var _a, _b, _c, _d;
|
|
137
|
+
let selection = style !== "serialised" ? conf.load : conf.serialisation;
|
|
138
|
+
let fullValue = "";
|
|
139
|
+
let name = style === "serialised" ? conf.name : conf.load.name;
|
|
140
|
+
for (let def of selection.types) {
|
|
141
|
+
if (!Array.isArray(def.types)) {
|
|
142
|
+
if (fullValue.length > 0)
|
|
143
|
+
fullValue += " | ";
|
|
144
|
+
fullValue += selection.types;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
let value = GeneratorUtilities.GenerateValueGroup(className, def.types, gen, PropertyTypes.isType(def.modifiers, PropertyTypes.ForceInline), style);
|
|
148
|
+
if (conf.expressionForProperty && PropertyTypes.ModOnly(def.modifiers) !== PropertyTypes.Solo) {
|
|
149
|
+
if (style !== "serialised") {
|
|
150
|
+
value += " | " + GeneratorUtilities.ExpressionString;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
value += ` | ` + GeneratorUtilities.SerialisedExpressionString;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (!PropertyTypes.isType(def.modifiers, PropertyTypes.Solo)) {
|
|
157
|
+
if (style === "serialised") {
|
|
158
|
+
if (value.includes("] | [")) {
|
|
159
|
+
value = "(" + value + ")";
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
if (value.includes(" | ")) {
|
|
164
|
+
value = "(" + value + ")";
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
//Map and Dict
|
|
169
|
+
if (PropertyTypes.isTypeOr(def.modifiers, PropertyTypes.Map, PropertyTypes.Dictionary)) {
|
|
170
|
+
/*
|
|
171
|
+
* Creation: Map or Dict. (needs both)
|
|
172
|
+
* Definition: Map or Dict. (needs both)
|
|
173
|
+
* Serialised: Dict typing as map or dict name. (needs both)
|
|
174
|
+
* Typescript: Map or Dict. (needs both)
|
|
175
|
+
*/
|
|
176
|
+
let text;
|
|
177
|
+
let mapText;
|
|
178
|
+
if (def.restrictedTo) {
|
|
179
|
+
text = `{[key in ${def.restrictedTo.map((e) => typeof e === "string" ? `"${e}"` : e).join(" | ")}]: ${value}}`;
|
|
180
|
+
mapText = `Map<${def.restrictedTo.map((e) => typeof e === "string" ? `"${e}"` : e).join(" | ")}, ${value}>`;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
text = `{[key: ${def.keyType.includes(Expression) ? "string" : (_b = (_a = def.keyType) === null || _a === void 0 ? void 0 : _a.map((e) => primitiveTypeName(e)).join(" | ")) !== null && _b !== void 0 ? _b : "string"}]: ${value}}`;
|
|
184
|
+
mapText = `Map<${def.keyType.includes(Expression) ? "string" : (_d = (_c = def.keyType) === null || _c === void 0 ? void 0 : _c.map((e) => primitiveTypeName(e)).join(" | ")) !== null && _d !== void 0 ? _d : "string"}, ${value}>`;
|
|
185
|
+
}
|
|
186
|
+
let isMap = PropertyTypes.isType(def.modifiers, PropertyTypes.Map);
|
|
187
|
+
value = style !== "serialised" ? text : (isMap ? `[ "Map", ${text} ]` : `[ "Dict", ${text} ]`);
|
|
188
|
+
if (isMap && style === "creation") {
|
|
189
|
+
//No expressions allowed in the fancy values.
|
|
190
|
+
value += ` | ` + mapText.replace(" | " + GeneratorUtilities.ExpressionString, "");
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
//Array 2
|
|
194
|
+
else if (PropertyTypes.isType(def.modifiers, PropertyTypes.Array2)) {
|
|
195
|
+
value = style !== "serialised" ? `${value}[][]` : `[ "Array2", ${value}[][] ]`;
|
|
196
|
+
}
|
|
197
|
+
//Array 1
|
|
198
|
+
else if (PropertyTypes.isType(def.modifiers, PropertyTypes.Array)) {
|
|
199
|
+
value = style !== "serialised" ? `${value}[]` : `[ "Array", ${value}[] ]`;
|
|
200
|
+
}
|
|
201
|
+
fullValue += (fullValue.length > 0 ? " | " : "") + value;
|
|
202
|
+
}
|
|
203
|
+
if (conf.expressionForProperty) {
|
|
204
|
+
if (style !== "serialised") {
|
|
205
|
+
fullValue += " | " + GeneratorUtilities.ExpressionString;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
fullValue += ` | ` + GeneratorUtilities.SerialisedExpressionString;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (style !== "serialised" && conf.load.present === "optional") {
|
|
212
|
+
name += "?";
|
|
213
|
+
}
|
|
214
|
+
gen.blocks.push(`\t${name}: ${fullValue};`);
|
|
215
|
+
return gen;
|
|
216
|
+
}
|
|
217
|
+
GeneratorUtilities.GenerateProperty = GenerateProperty;
|
|
218
|
+
function GenerateClassExtends(type, includes, style) {
|
|
219
|
+
let text = "";
|
|
220
|
+
let postfix = style === "creation" ? "Creation" : "";
|
|
221
|
+
if (type.parents.length > 0) {
|
|
222
|
+
let parents = [...type.parents].sort(SortTypes);
|
|
223
|
+
if (style === "definition") {
|
|
224
|
+
text += `extends ${parents.map((e) => `Omit<${GenerateAPIName(e, style, false) + postfix}, "Class">`).join(", ")} `;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
text += `extends ${parents.map((e) => `${GenerateAPIName(e, style, false) + postfix}`).join(", ")} `;
|
|
228
|
+
}
|
|
229
|
+
for (let parent of parents) {
|
|
230
|
+
if (isPrimitiveType(parent.classConstructor))
|
|
231
|
+
continue;
|
|
232
|
+
includes.push(GenerateInterfaceFilepathForFile(CalcProjectPath(undefined, parent.opts.file)), GenerateAPIName(parent, style, false) + postfix);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return text;
|
|
236
|
+
}
|
|
237
|
+
GeneratorUtilities.GenerateClassExtends = GenerateClassExtends;
|
|
238
|
+
function GenerateClass(classType, gen, style) {
|
|
239
|
+
let props = classType.finalised_ownPropertyNames.toSorted();
|
|
240
|
+
let propGen = {
|
|
241
|
+
blocks: [],
|
|
242
|
+
includes: gen.includes
|
|
243
|
+
};
|
|
244
|
+
if (style === "definition") {
|
|
245
|
+
propGen.blocks.push(`\tClass: "${classType.opts.dataTypeName}";`);
|
|
246
|
+
}
|
|
247
|
+
else if (style === "serialised") {
|
|
248
|
+
propGen.blocks.push(`\tversion: string;`);
|
|
249
|
+
}
|
|
250
|
+
for (let propName of classType.finalised_ownPropertyNames) {
|
|
251
|
+
let def = classType.getPropDefinition(Versions.MAX, propName);
|
|
252
|
+
if ("removed" in def || "doesntExist" in def)
|
|
253
|
+
continue;
|
|
254
|
+
if (style !== "serialised" && def.load.present == false)
|
|
255
|
+
continue;
|
|
256
|
+
if (style === "serialised" && def.serialisation.present == false)
|
|
257
|
+
continue;
|
|
258
|
+
GeneratorUtilities.GenerateProperty(classType.opts.dataTypeName, def, propGen, style);
|
|
259
|
+
}
|
|
260
|
+
gen.blocks.sort();
|
|
261
|
+
let name = GeneratorUtilities.GenerateAPIName(classType, style, false) + (style === "creation" ? "Creation" : "");
|
|
262
|
+
gen.blocks.push(`export interface ${name} ${GenerateClassExtends(classType, gen.includes, style)}{`
|
|
263
|
+
+ `\n${propGen.blocks.join("\n")}`
|
|
264
|
+
+ `\n}`);
|
|
265
|
+
if (style === "serialised") {
|
|
266
|
+
if (ClassCategory.isType(classType.category, ClassCategory.Pointer)) {
|
|
267
|
+
gen.blocks.push(`export type ${GeneratorUtilities.GenerateAPIName(classType, style, false)}Reference = [ string, ...(string | number)[] ];`);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
gen.blocks.push(`export type ${GeneratorUtilities.GenerateAPIName(classType, style, false)}Reference = [ string, ${GeneratorUtilities.GenerateAPIName(classType, style, false)} ];`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return gen;
|
|
274
|
+
}
|
|
275
|
+
GeneratorUtilities.GenerateClass = GenerateClass;
|
|
276
|
+
function GenerateClassWithCustomDef(classType, gen, style) {
|
|
277
|
+
if (!("DefinitionType" in classType.classConstructor)) {
|
|
278
|
+
throw new Error(`Failed to find DefinitionType for ${classType.opts.dataTypeName}`);
|
|
279
|
+
}
|
|
280
|
+
let def;
|
|
281
|
+
if (typeof classType.classConstructor.DefinitionType === "string") {
|
|
282
|
+
def = classType.classConstructor.DefinitionType;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
def = FormatPropInput(classType.classConstructor.DefinitionType);
|
|
286
|
+
}
|
|
287
|
+
if (style === "serialised" && "SerialisedType" in classType.classConstructor) {
|
|
288
|
+
if (typeof classType.classConstructor.SerialisedType === "string") {
|
|
289
|
+
def = classType.classConstructor.SerialisedType;
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
def = FormatPropInput(classType.classConstructor.DefinitionType);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (typeof def === "string") {
|
|
296
|
+
if (style === "definition") {
|
|
297
|
+
gen.blocks.push(`export type ${GenerateAPIName(classType, "definition", false)} = ${def};`);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
gen.blocks.push(`export type ${GenerateAPIName(classType, "serialised", false)} = ${def};`);
|
|
301
|
+
gen.blocks.push(`export type ${GenerateAPIName(classType, "serialised", false)}Reference = [ string, ${GenerateAPIName(classType, "serialised", false)} ];`);
|
|
302
|
+
}
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
let valGen = {
|
|
306
|
+
blocks: [],
|
|
307
|
+
includes: gen.includes
|
|
308
|
+
};
|
|
309
|
+
let possibleModifiers = PropertyTypes.AsIs;
|
|
310
|
+
let refinedDefs = def.map((e) => {
|
|
311
|
+
let modifiers = "array" in e ? e.array == 2 ? PropertyTypes.Array2 : PropertyTypes.Array :
|
|
312
|
+
"mapKey" in e ? PropertyTypes.Map : "dictKey" in e ? PropertyTypes.Dictionary : PropertyTypes.Solo;
|
|
313
|
+
let key = "mapKey" in e ? e.mapKey : "dictKey" in e ? e.dictKey : undefined;
|
|
314
|
+
possibleModifiers |= modifiers;
|
|
315
|
+
e.type = e.type.flatMap((e) => {
|
|
316
|
+
if (isPrimitiveType(e))
|
|
317
|
+
return e;
|
|
318
|
+
if (!(e instanceof ReplicableClass)) {
|
|
319
|
+
let types = ReplicableRegistry.__GetReplicablesFor(e);
|
|
320
|
+
return types ? types : e;
|
|
321
|
+
}
|
|
322
|
+
return e;
|
|
323
|
+
});
|
|
324
|
+
return Object.assign(Object.assign({ types: e.type, modifiers, sortIndex: e.type.map((e) => isPrimitiveType(e) ? primitiveTypeName(e) : e.opts.dataTypeName).join(" | ") }, ("restrictedTo" in e ? { restrictedTo: e.restrictedTo } : {})), (key ? { keyType: Array.isArray(key) ? key : [key] } : {}));
|
|
325
|
+
});
|
|
326
|
+
GenerateProperty(classType.opts.dataTypeName, {
|
|
327
|
+
name: classType.opts.dataTypeName,
|
|
328
|
+
load: { name: classType.opts.dataTypeName, skipLoad: false, present: true, default: undefined, possibleModifiers, types: refinedDefs },
|
|
329
|
+
serialisation: { present: true, inline: true, possibleModifiers, types: refinedDefs },
|
|
330
|
+
expressionForProperty: undefined,
|
|
331
|
+
expressionForValue: undefined,
|
|
332
|
+
expressionForKey: undefined
|
|
333
|
+
}, valGen, style);
|
|
334
|
+
valGen.blocks[0] = valGen.blocks[0].replace(/^\t\w*: ?/, "");
|
|
335
|
+
if (style === "definition") {
|
|
336
|
+
gen.blocks.push(`export type ${GenerateAPIName(classType, "definition", false)} = ${valGen.blocks[0]}`);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
gen.blocks.push(`export type ${GenerateAPIName(classType, "serialised", false)} = ${valGen.blocks[0]}`);
|
|
340
|
+
gen.blocks.push(`export type ${GenerateAPIName(classType, "serialised", false)}Reference = [ string, ${GenerateAPIName(classType, "serialised", false)} ];`);
|
|
341
|
+
}
|
|
342
|
+
return gen;
|
|
343
|
+
}
|
|
344
|
+
GeneratorUtilities.GenerateClassWithCustomDef = GenerateClassWithCustomDef;
|
|
345
|
+
function GenerateCustomType(types, gen, style) {
|
|
346
|
+
let styleSpecifier = style === "definition" ? "Definition" : style === "serialised" ? "Serialised" : "";
|
|
347
|
+
let details = style === "definition" ? types.def : style === "serialised" ? types.ser : types.ts;
|
|
348
|
+
for (let config of details) {
|
|
349
|
+
let values = "";
|
|
350
|
+
let def = FormatPropInput(config.DefinitionType);
|
|
351
|
+
let possibleModifiers = PropertyTypes.AsIs;
|
|
352
|
+
let refinedDefs = def.map((e) => {
|
|
353
|
+
let modifiers = "array" in e ? e.array == 2 ? PropertyTypes.Array2 : PropertyTypes.Array :
|
|
354
|
+
"mapKey" in e ? PropertyTypes.Map : "dictKey" in e ? PropertyTypes.Dictionary : PropertyTypes.Solo;
|
|
355
|
+
let key = "mapKey" in e ? e.mapKey : "dictKey" in e ? e.dictKey : undefined;
|
|
356
|
+
possibleModifiers |= modifiers;
|
|
357
|
+
e.type = e.type.flatMap((e) => {
|
|
358
|
+
if (isPrimitiveType(e))
|
|
359
|
+
return e;
|
|
360
|
+
if (!(e instanceof ReplicableClass)) {
|
|
361
|
+
let types = ReplicableRegistry.__GetReplicablesFor(e);
|
|
362
|
+
return types ? types : e;
|
|
363
|
+
}
|
|
364
|
+
return e;
|
|
365
|
+
});
|
|
366
|
+
return Object.assign(Object.assign({ types: e.type, modifiers, sortIndex: e.type.map((e) => {
|
|
367
|
+
if (isPrimitiveType(e)) {
|
|
368
|
+
return primitiveTypeName(e);
|
|
369
|
+
}
|
|
370
|
+
return e.opts.dataTypeName;
|
|
371
|
+
}).join(" | ") }, ("restrictedTo" in e ? { restrictedTo: e.restrictedTo } : {})), (key ? { keyType: Array.isArray(key) ? key : [key] } : {}));
|
|
372
|
+
});
|
|
373
|
+
let valGen = {
|
|
374
|
+
blocks: [],
|
|
375
|
+
includes: gen.includes
|
|
376
|
+
};
|
|
377
|
+
GenerateProperty(config.name, {
|
|
378
|
+
name: config.name,
|
|
379
|
+
load: { name: config.name, skipLoad: false, present: true, default: undefined, possibleModifiers, types: refinedDefs },
|
|
380
|
+
serialisation: { present: true, inline: true, possibleModifiers, types: refinedDefs },
|
|
381
|
+
expressionForProperty: undefined,
|
|
382
|
+
expressionForValue: undefined,
|
|
383
|
+
expressionForKey: undefined
|
|
384
|
+
}, valGen, style);
|
|
385
|
+
for (let block of valGen.blocks) {
|
|
386
|
+
if (values.length > 0)
|
|
387
|
+
values += " " + config.op + " ";
|
|
388
|
+
block = block.replace(/ \| `@\{\$\{string}}`(;?)$/, "$1");
|
|
389
|
+
if (style === "serialised") {
|
|
390
|
+
block = block.replace(/ \| \[ "Expression", string ](;?)$/, "$1");
|
|
391
|
+
block = block.replace(/\[ "\w*", (\w*) ]/g, "$1");
|
|
392
|
+
}
|
|
393
|
+
if (config.op === "&") {
|
|
394
|
+
block = block.replace(/\|/g, "&");
|
|
395
|
+
}
|
|
396
|
+
values += block.replace(`\t${config.name}: `, "").replace(";", "");
|
|
397
|
+
}
|
|
398
|
+
gen.blocks.push(`export type ${config.name}${styleSpecifier} = ${values}${config.append ? " " + config.append : ""};`);
|
|
399
|
+
if (style === "serialised") {
|
|
400
|
+
gen.blocks.push("export type " + config.name + "SerialisedReference = [ " + config.name + " | string, " + config.name + "Serialised ];");
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
GeneratorUtilities.GenerateCustomType = GenerateCustomType;
|
|
405
|
+
function GenerateImports(file, includes) {
|
|
406
|
+
let start = CalcProjectPath(undefined, BikPath.dir(file));
|
|
407
|
+
let paths = Array.from(includes.keys()).sort();
|
|
408
|
+
let header = "";
|
|
409
|
+
for (let path of paths) {
|
|
410
|
+
let imports = Array.from(includes.get(path).values()).sort();
|
|
411
|
+
if (/^\/\\/.test(path)) {
|
|
412
|
+
path = BikPath.join(GeneratorUtilities.ReplRoot, path);
|
|
413
|
+
}
|
|
414
|
+
let from = BikPath.importable(BikPath.getRelativePathTo(start, path));
|
|
415
|
+
if (from === "./" + BikPath.file(file)) {
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
from = from.replace(/(?:\.d)?\.ts$/, ".js");
|
|
419
|
+
header += `import { ` + imports.join(", ") + ` } from "${from}";\n`;
|
|
420
|
+
}
|
|
421
|
+
return header;
|
|
422
|
+
}
|
|
423
|
+
GeneratorUtilities.GenerateImports = GenerateImports;
|
|
424
|
+
function GenerateDefinitionFile(file, repls, types) {
|
|
425
|
+
let includes = new SetMap();
|
|
426
|
+
let tsGen = {
|
|
427
|
+
blocks: [],
|
|
428
|
+
includes: includes
|
|
429
|
+
};
|
|
430
|
+
let topGen = {
|
|
431
|
+
blocks: [],
|
|
432
|
+
includes: includes
|
|
433
|
+
};
|
|
434
|
+
let middleGen = {
|
|
435
|
+
blocks: [],
|
|
436
|
+
includes: includes
|
|
437
|
+
};
|
|
438
|
+
let bottomGen = {
|
|
439
|
+
blocks: [],
|
|
440
|
+
includes: includes
|
|
441
|
+
};
|
|
442
|
+
if (types) {
|
|
443
|
+
GeneratorUtilities.GenerateCustomType(types, tsGen, "typescript");
|
|
444
|
+
GeneratorUtilities.GenerateCustomType(types, topGen, "definition");
|
|
445
|
+
GeneratorUtilities.GenerateCustomType(types, middleGen, "serialised");
|
|
446
|
+
}
|
|
447
|
+
if (repls) {
|
|
448
|
+
for (let repl of repls) {
|
|
449
|
+
if ("DefinitionType" in repl.classConstructor) {
|
|
450
|
+
GeneratorUtilities.GenerateClassWithCustomDef(repl, topGen, "definition");
|
|
451
|
+
GeneratorUtilities.GenerateClassWithCustomDef(repl, middleGen, "serialised");
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
GeneratorUtilities.GenerateClass(repl, topGen, "definition");
|
|
455
|
+
GeneratorUtilities.GenerateClass(repl, middleGen, "serialised");
|
|
456
|
+
GeneratorUtilities.GenerateClass(repl, bottomGen, "creation");
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (repls && repls.length > 0) {
|
|
461
|
+
//Delete the current file from the list of includes.
|
|
462
|
+
let outputFilepath = GenerateInterfaceFilepathForFile(file);
|
|
463
|
+
includes.delete(outputFilepath);
|
|
464
|
+
}
|
|
465
|
+
return GeneratorUtilities.GenerateImports(file, topGen.includes) + "\n\n\n"
|
|
466
|
+
+ GeneratorUtilities.DefinitionForward + "\n\n\n"
|
|
467
|
+
+ (tsGen.blocks.length > 0 ? tsGen.blocks.join("\n\n") + "\n\n\n\n" : "")
|
|
468
|
+
+ topGen.blocks.join("\n\n") + "\n\n\n\n"
|
|
469
|
+
+ middleGen.blocks.join("\n\n") + "\n\n\n\n"
|
|
470
|
+
+ bottomGen.blocks.join("\n\n");
|
|
471
|
+
}
|
|
472
|
+
GeneratorUtilities.GenerateDefinitionFile = GenerateDefinitionFile;
|
|
473
|
+
function GetReplTypesForArray(propTypes, from) {
|
|
474
|
+
return propTypes.flatMap((e) => {
|
|
475
|
+
if (typeof e !== "string" && isPrimitiveType(e) || e === Object)
|
|
476
|
+
return e;
|
|
477
|
+
let result = ReplicableRegistry.__GetReplicablesFor(e);
|
|
478
|
+
if (!result) {
|
|
479
|
+
throw new Error(`Failed to find type ${describeObject(e)} for imports.`
|
|
480
|
+
+ ` Did you forget the @Type or @Struct decorator? \nFound in ${from.replace(".js", ".ts")}`);
|
|
481
|
+
}
|
|
482
|
+
return result;
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
function GenerateTypescriptFile(includeFiles, file) {
|
|
486
|
+
let types = GetReplTypesForArray(includeFiles.flat(), file);
|
|
487
|
+
let str = "";
|
|
488
|
+
for (let type of types) {
|
|
489
|
+
if (isPrimitiveType(type))
|
|
490
|
+
continue;
|
|
491
|
+
str += `import "${BikPath.getRelativePathTo(file, type.opts.file)}";\n`;
|
|
492
|
+
}
|
|
493
|
+
return GeneratorUtilities.GenerationForward + "\n\n" + str;
|
|
494
|
+
}
|
|
495
|
+
GeneratorUtilities.GenerateTypescriptFile = GenerateTypescriptFile;
|
|
496
|
+
})(GeneratorUtilities || (GeneratorUtilities = {}));
|
|
497
|
+
export var SchemaGenerator;
|
|
498
|
+
(function (SchemaGenerator) {
|
|
499
|
+
const CustomTypesByFile = new Map();
|
|
500
|
+
const IncludeFiles = new ArrayMap();
|
|
501
|
+
function RegisterCustomTsInclude(type) {
|
|
502
|
+
let callerPath = BikPath.normalise(BikPath.getCallerFilepath());
|
|
503
|
+
let includePath = callerPath.replace(/\.[jt]s/, ".includes.ts");
|
|
504
|
+
IncludeFiles.push(includePath, type.DefinitionType);
|
|
505
|
+
}
|
|
506
|
+
SchemaGenerator.RegisterCustomTsInclude = RegisterCustomTsInclude;
|
|
507
|
+
function RegisterCustomTsType(type) {
|
|
508
|
+
let callerPath = BikPath.normalise(BikPath.getCallerFilepath());
|
|
509
|
+
let path = GeneratorUtilities.GenerateInterfaceFilepathForFile(callerPath);
|
|
510
|
+
let val = CustomTypesByFile.get(path);
|
|
511
|
+
if (!val)
|
|
512
|
+
CustomTypesByFile.set(path, val = { ts: [], ser: [], def: [] });
|
|
513
|
+
val.ts.push(type);
|
|
514
|
+
}
|
|
515
|
+
SchemaGenerator.RegisterCustomTsType = RegisterCustomTsType;
|
|
516
|
+
function RegisterCustomSerialisedType(type) {
|
|
517
|
+
let path = GeneratorUtilities.GenerateInterfaceFilepathForFile(BikPath.normalise(BikPath.getCallerFilepath()));
|
|
518
|
+
let val = CustomTypesByFile.get(path);
|
|
519
|
+
if (!val)
|
|
520
|
+
CustomTypesByFile.set(path, val = { ts: [], ser: [], def: [] });
|
|
521
|
+
val.ser.push(type);
|
|
522
|
+
}
|
|
523
|
+
SchemaGenerator.RegisterCustomSerialisedType = RegisterCustomSerialisedType;
|
|
524
|
+
function RegisterCustomDefinitionType(type) {
|
|
525
|
+
let path = GeneratorUtilities.GenerateInterfaceFilepathForFile(BikPath.normalise(BikPath.getCallerFilepath()));
|
|
526
|
+
let val = CustomTypesByFile.get(path);
|
|
527
|
+
if (!val)
|
|
528
|
+
CustomTypesByFile.set(path, val = { ts: [], ser: [], def: [] });
|
|
529
|
+
val.def.push(type);
|
|
530
|
+
}
|
|
531
|
+
SchemaGenerator.RegisterCustomDefinitionType = RegisterCustomDefinitionType;
|
|
532
|
+
function GenerateAllInterfaceTypes(version, options) {
|
|
533
|
+
let types = ReplicableRegistry.__GetAllReplicables();
|
|
534
|
+
let files = new SetMap();
|
|
535
|
+
for (let type of types) {
|
|
536
|
+
files.push(GeneratorUtilities.GenerateInterfaceFilepathForFile(type.opts.file), type);
|
|
537
|
+
}
|
|
538
|
+
for (let file of files.keys()) {
|
|
539
|
+
let types = [...files.get(file)].sort(GeneratorUtilities.SortTypes);
|
|
540
|
+
if (types.length < 1)
|
|
541
|
+
continue;
|
|
542
|
+
file = BikPath.normalise(file);
|
|
543
|
+
let str = GeneratorUtilities.GenerateDefinitionFile(file, types, CustomTypesByFile.get(file));
|
|
544
|
+
CustomTypesByFile.delete(file);
|
|
545
|
+
options.open(file);
|
|
546
|
+
options.write(file, str);
|
|
547
|
+
}
|
|
548
|
+
for (let [file, types] of CustomTypesByFile.entries()) {
|
|
549
|
+
file = BikPath.normalise(file);
|
|
550
|
+
let str = GeneratorUtilities.GenerateDefinitionFile(file, undefined, CustomTypesByFile.get(file));
|
|
551
|
+
options.open(file);
|
|
552
|
+
options.write(file, str);
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Generate a file that you can import to import a bunch of other files.
|
|
556
|
+
*/
|
|
557
|
+
for (let [file, startTypes] of IncludeFiles) {
|
|
558
|
+
let str = GeneratorUtilities.GenerateTypescriptFile(startTypes, file);
|
|
559
|
+
options.open(file);
|
|
560
|
+
options.write(file, str);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
SchemaGenerator.GenerateAllInterfaceTypes = GenerateAllInterfaceTypes;
|
|
564
|
+
})(SchemaGenerator || (SchemaGenerator = {}));
|