@bikky/compiler 0.1.18 → 0.2.0
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/.idea/Compiler.iml +1 -0
- package/.idea/scopes/All_Typescript_Files.xml +3 -0
- package/Execution/generate.mjs +17 -1
- package/Execution/generate.mjs.map +1 -1
- package/Execution/generate.mts +33 -3
- package/Libraries/BiscuitLibraries.d.mts +2 -0
- package/Libraries/BiscuitLibraries.d.mts.map +1 -1
- package/Libraries/BiscuitLibraries.mjs +4 -0
- package/Libraries/BiscuitLibraries.mjs.map +1 -1
- package/Libraries/BiscuitLibraries.mts +5 -1
- package/Libraries/ClassMigration.d.mts +88 -0
- package/Libraries/ClassMigration.d.mts.map +1 -0
- package/Libraries/ClassMigration.mjs +368 -0
- package/Libraries/ClassMigration.mjs.map +1 -0
- package/Libraries/ClassMigration.mts +431 -0
- package/Libraries/RBF.d.mts +4 -0
- package/Libraries/RBF.d.mts.map +1 -0
- package/Libraries/RBF.mjs +36 -0
- package/Libraries/RBF.mjs.map +1 -0
- package/Libraries/RBF.mts +46 -0
- package/Libraries/RBFTypes.d.ts +43 -0
- package/Source/ASTInterface/Crawler.d.ts +2 -1
- package/Source/ASTInterface/Crawler.d.ts.map +1 -1
- package/Source/ASTInterface/Crawler.js +14 -2
- package/Transformers/Main.d.ts +1 -1
- package/Transformers/Main.d.ts.map +1 -1
- package/Transformers/Main.js +3 -2
- package/Transformers/RBFHelpers/Constants.d.ts +3 -0
- package/Transformers/RBFHelpers/Constants.d.ts.map +1 -0
- package/Transformers/RBFHelpers/Constants.js +7 -0
- package/Transformers/RBFHelpers/Imports.d.ts +12 -0
- package/Transformers/RBFHelpers/Imports.d.ts.map +1 -0
- package/Transformers/RBFHelpers/Imports.js +212 -0
- package/Transformers/RBFHelpers/Print.d.ts +1 -0
- package/Transformers/RBFHelpers/Print.d.ts.map +1 -0
- package/Transformers/RBFHelpers/Print.js +2 -0
- package/Transformers/RBFHelpers/PropertyConfig.d.ts +65 -0
- package/Transformers/RBFHelpers/PropertyConfig.d.ts.map +1 -0
- package/Transformers/RBFHelpers/PropertyConfig.js +420 -0
- package/Transformers/RBFTransformer.d.ts +2 -0
- package/Transformers/RBFTransformer.d.ts.map +1 -0
- package/Transformers/RBFTransformer.js +317 -0
- package/package.json +1 -1
- package/tsconfig.build.libs.tsbuildinfo +1 -1
- package/tsconfig.build.src.tsbuildinfo +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/Transformers/ReplicableTransformer.d.ts +0 -2
- package/Transformers/ReplicableTransformer.d.ts.map +0 -1
- package/Transformers/ReplicableTransformer.js +0 -797
package/.idea/Compiler.iml
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
6
6
|
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
7
7
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
+
<excludeFolder url="file://$MODULE_DIR$/Cache" />
|
|
8
9
|
</content>
|
|
9
10
|
<orderEntry type="inheritedJdk" />
|
|
10
11
|
<orderEntry type="sourceFolder" forTests="false" />
|
package/Execution/generate.mjs
CHANGED
|
@@ -15,7 +15,7 @@ if (!fs.existsSync(cache)) {
|
|
|
15
15
|
{ //Clear the cache.
|
|
16
16
|
let files = fs.readdirSync(cache);
|
|
17
17
|
for (let file of files) {
|
|
18
|
-
if (file.includes("lib.")) {
|
|
18
|
+
if (file.includes("lib.") && fs.existsSync(Path.join(cache, file))) {
|
|
19
19
|
fs.rmSync(Path.join(cache, file));
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -28,9 +28,13 @@ if (!fs.existsSync(cache)) {
|
|
|
28
28
|
fs.copyFileSync(Path.join(libPath, file), Path.join(cache, file));
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
fs.rmSync(Path.join(cache, "./tsserverlibrary.js"));
|
|
31
32
|
fs.copyFileSync(Path.join(libPath, "./tsserverlibrary.js"), Path.join(cache, "./tsserverlibrary.js"));
|
|
33
|
+
fs.rmSync(Path.join(cache, "./tsserverlibrary.d.ts"));
|
|
32
34
|
fs.copyFileSync(Path.join(libPath, "./tsserverlibrary.d.ts"), Path.join(cache, "./tsserverlibrary.d.ts"));
|
|
35
|
+
fs.rmSync(Path.join(cache, "./typescript.d.ts"));
|
|
33
36
|
fs.copyFileSync(Path.join(libPath, "./typescript.d.ts"), Path.join(cache, "./typescript.d.ts"));
|
|
37
|
+
fs.rmSync(Path.join(cache, "./tsc.d.ts"));
|
|
34
38
|
fs.copyFileSync(Path.join(libPath, "./typescript.d.ts"), Path.join(cache, "./tsc.d.ts"));
|
|
35
39
|
}
|
|
36
40
|
{ //Create a modified tsc.js file.
|
|
@@ -45,12 +49,24 @@ if (!fs.existsSync(cache)) {
|
|
|
45
49
|
`.trim());
|
|
46
50
|
//Allow our custom plugins to resolve from a different directory location.
|
|
47
51
|
tspSource.js = tspSource.js.replace(`const entryFilePath = require.resolve(configTransformValue, { paths: [resolveBaseDir] });`, `const entryFilePath = require.resolve(configTransformValue, { paths: [config.baseDir ?? resolveBaseDir] });`);
|
|
52
|
+
//Allow our custom plugins to work even when the compiler is being run programmatically.
|
|
53
|
+
tspSource.js = tspSource.js.replace(`if (["tsc", "tsserver", "tsserverlibrary"].includes(tsp.currentLibrary)) {`, `if (["tsc", "tsserver", "tsserverlibrary", "typescript"].includes(tsp.currentLibrary)) {`);
|
|
48
54
|
fs.writeFileSync(Path.join(cache, "./tsc.js"), tspSource.js, "utf8");
|
|
49
55
|
}
|
|
50
56
|
{ //Create a modified typescript.js file.
|
|
51
57
|
const tsPackage = tspackage.getTsPackage(tscPath);
|
|
52
58
|
const tsModule = tsmodule.getTsModule(tsPackage, "typescript.js");
|
|
53
59
|
const tspSource = tspatch.getPatchedSource(tsModule, { log: console.log.bind(console) });
|
|
60
|
+
//Insert our custom plugins!
|
|
61
|
+
tspSource.js = tspSource.js.replace(`const projectConfig = getProjectConfig(options, rootNames);`, `
|
|
62
|
+
const projectConfig = getProjectConfig(options, rootNames);
|
|
63
|
+
projectConfig.compilerOptions.plugins = projectConfig.compilerOptions.plugins ?? [];
|
|
64
|
+
projectConfig.compilerOptions.plugins.push({ "transform": "../Transformers/Main.js", baseDir: __dirname, "type": "program", "after": false });
|
|
65
|
+
`.trim());
|
|
66
|
+
//Allow our custom plugins to resolve from a different directory location.
|
|
67
|
+
tspSource.js = tspSource.js.replace(`const entryFilePath = require.resolve(configTransformValue, { paths: [resolveBaseDir] });`, `const entryFilePath = require.resolve(configTransformValue, { paths: [config.baseDir ?? resolveBaseDir] });`);
|
|
68
|
+
//Allow our custom plugins to work even when the compiler is being run programmatically.
|
|
69
|
+
tspSource.js = tspSource.js.replace(`if (["tsc", "tsserver", "tsserverlibrary"].includes(tsp.currentLibrary)) {`, `if (["tsc", "tsserver", "tsserverlibrary", "typescript"].includes(tsp.currentLibrary)) {`);
|
|
54
70
|
fs.writeFileSync(Path.join(cache, "./typescript.js"), tspSource.js, "utf8");
|
|
55
71
|
}
|
|
56
72
|
{ //Create a modified tsserver.js file.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.mjs","sourceRoot":"","sources":["generate.mts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAC;AACzD,OAAO,KAAK,OAAO,MAAM,sCAAsC,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAE3B,aAAa;AACb,MAAM,IAAI,GAAG,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACzE,MAA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CAAC,CAAC;AAChF,CAAC;AACD,CAAC,CAAC,qCAAqC;IACnC,MAAM,SAAS,GAAG,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAEzF,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,gBAAgB,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;AAC/E,CAAC"}
|
package/Execution/generate.mts
CHANGED
|
@@ -18,7 +18,7 @@ if (!fs.existsSync(cache)) {
|
|
|
18
18
|
{ //Clear the cache.
|
|
19
19
|
let files = fs.readdirSync(cache);
|
|
20
20
|
for (let file of files) {
|
|
21
|
-
if (file.includes("lib.")) {
|
|
21
|
+
if (file.includes("lib.") && fs.existsSync(Path.join(cache, file))) {
|
|
22
22
|
fs.rmSync(Path.join(cache, file));
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -32,9 +32,13 @@ if (!fs.existsSync(cache)) {
|
|
|
32
32
|
fs.copyFileSync(Path.join(libPath, file), Path.join(cache, file));
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
fs.rmSync(Path.join(cache, "./tsserverlibrary.js"));
|
|
35
36
|
fs.copyFileSync(Path.join(libPath, "./tsserverlibrary.js"), Path.join(cache, "./tsserverlibrary.js"));
|
|
37
|
+
fs.rmSync(Path.join(cache, "./tsserverlibrary.d.ts"));
|
|
36
38
|
fs.copyFileSync(Path.join(libPath, "./tsserverlibrary.d.ts"), Path.join(cache, "./tsserverlibrary.d.ts"));
|
|
39
|
+
fs.rmSync(Path.join(cache, "./typescript.d.ts"));
|
|
37
40
|
fs.copyFileSync(Path.join(libPath, "./typescript.d.ts"), Path.join(cache, "./typescript.d.ts"));
|
|
41
|
+
fs.rmSync(Path.join(cache, "./tsc.d.ts"));
|
|
38
42
|
fs.copyFileSync(Path.join(libPath, "./typescript.d.ts"), Path.join(cache, "./tsc.d.ts"));
|
|
39
43
|
}
|
|
40
44
|
|
|
@@ -43,6 +47,7 @@ if (!fs.existsSync(cache)) {
|
|
|
43
47
|
const tsModule = tsmodule.getTsModule(tsPackage, "tsc.js");
|
|
44
48
|
const tspSource = tspatch.getPatchedSource(tsModule, { log: console.log.bind(console) });
|
|
45
49
|
|
|
50
|
+
|
|
46
51
|
//Insert our custom plugins!
|
|
47
52
|
tspSource.js = tspSource.js.replace(`const projectConfig = getProjectConfig(options, rootNames);`,
|
|
48
53
|
`
|
|
@@ -56,14 +61,39 @@ if (!fs.existsSync(cache)) {
|
|
|
56
61
|
`const entryFilePath = require.resolve(configTransformValue, { paths: [resolveBaseDir] });`,
|
|
57
62
|
`const entryFilePath = require.resolve(configTransformValue, { paths: [config.baseDir ?? resolveBaseDir] });`
|
|
58
63
|
);
|
|
59
|
-
|
|
64
|
+
|
|
65
|
+
//Allow our custom plugins to work even when the compiler is being run programmatically.
|
|
66
|
+
tspSource.js = tspSource.js.replace(
|
|
67
|
+
`if (["tsc", "tsserver", "tsserverlibrary"].includes(tsp.currentLibrary)) {`,
|
|
68
|
+
`if (["tsc", "tsserver", "tsserverlibrary", "typescript"].includes(tsp.currentLibrary)) {`,
|
|
69
|
+
);
|
|
70
|
+
|
|
60
71
|
fs.writeFileSync(Path.join(cache, "./tsc.js"), tspSource.js, "utf8");
|
|
61
72
|
}
|
|
62
73
|
{ //Create a modified typescript.js file.
|
|
63
74
|
const tsPackage = tspackage.getTsPackage(tscPath);
|
|
64
75
|
const tsModule = tsmodule.getTsModule(tsPackage, "typescript.js");
|
|
65
76
|
const tspSource = tspatch.getPatchedSource(tsModule, { log: console.log.bind(console) });
|
|
66
|
-
|
|
77
|
+
|
|
78
|
+
//Insert our custom plugins!
|
|
79
|
+
tspSource.js = tspSource.js.replace(`const projectConfig = getProjectConfig(options, rootNames);`,
|
|
80
|
+
`
|
|
81
|
+
const projectConfig = getProjectConfig(options, rootNames);
|
|
82
|
+
projectConfig.compilerOptions.plugins = projectConfig.compilerOptions.plugins ?? [];
|
|
83
|
+
projectConfig.compilerOptions.plugins.push({ "transform": "../Transformers/Main.js", baseDir: __dirname, "type": "program", "after": false });
|
|
84
|
+
`.trim());
|
|
85
|
+
|
|
86
|
+
//Allow our custom plugins to resolve from a different directory location.
|
|
87
|
+
tspSource.js = tspSource.js.replace(
|
|
88
|
+
`const entryFilePath = require.resolve(configTransformValue, { paths: [resolveBaseDir] });`,
|
|
89
|
+
`const entryFilePath = require.resolve(configTransformValue, { paths: [config.baseDir ?? resolveBaseDir] });`
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
//Allow our custom plugins to work even when the compiler is being run programmatically.
|
|
93
|
+
tspSource.js = tspSource.js.replace(
|
|
94
|
+
`if (["tsc", "tsserver", "tsserverlibrary"].includes(tsp.currentLibrary)) {`,
|
|
95
|
+
`if (["tsc", "tsserver", "tsserverlibrary", "typescript"].includes(tsp.currentLibrary)) {`,
|
|
96
|
+
);
|
|
67
97
|
fs.writeFileSync(Path.join(cache, "./typescript.js"), tspSource.js, "utf8");
|
|
68
98
|
}
|
|
69
99
|
{ //Create a modified tsserver.js file.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BiscuitLibraries.d.mts","sourceRoot":"","sources":["BiscuitLibraries.mts"],"names":[],"mappings":";AAEA,OAAO,iBAAiB,CAAC;AAEzB,OAAO,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"BiscuitLibraries.d.mts","sourceRoot":"","sources":["BiscuitLibraries.mts"],"names":[],"mappings":";AAEA,OAAO,iBAAiB,CAAC;AAEzB,OAAO,gBAAgB,CAAC;AAExB,OAAO,sBAAsB,CAAA;AAE7B,cAAc,WAAW,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BiscuitLibraries.mjs","sourceRoot":"","sources":["BiscuitLibraries.mts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,aAAa;AACb,OAAO,iBAAiB,CAAC;AACzB,aAAa;AACb,OAAO,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"BiscuitLibraries.mjs","sourceRoot":"","sources":["BiscuitLibraries.mts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,aAAa;AACb,OAAO,iBAAiB,CAAC;AACzB,aAAa;AACb,OAAO,gBAAgB,CAAC;AACxB,aAAa;AACb,OAAO,sBAAsB,CAAA;AAC7B,aAAa;AACb,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versions have both a "base" version and a list of mods that apply to the current object.
|
|
3
|
+
* In the form `{base: string, mods: {[name: string]: string}}`.
|
|
4
|
+
*/
|
|
5
|
+
interface SerialisedVersions {
|
|
6
|
+
core: Migration.Version;
|
|
7
|
+
mods: {
|
|
8
|
+
[modName: string]: Migration.Version;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
declare class ClassMigrator<F, T = never> {
|
|
12
|
+
fromClassName: string;
|
|
13
|
+
toClassName?: string;
|
|
14
|
+
constructor(fromClassName: string, toClassName?: string);
|
|
15
|
+
/**
|
|
16
|
+
* Migrate instances of this class to become instances of another class.
|
|
17
|
+
*/
|
|
18
|
+
toClass<X>(klass: Class<X>): ClassMigrator<F, X>;
|
|
19
|
+
/**
|
|
20
|
+
* Migrate data from an instance or a class that no longer exists into the current class.
|
|
21
|
+
*/
|
|
22
|
+
fromInterface<X = never>(name: string): ClassMigrator<X, F>;
|
|
23
|
+
/**
|
|
24
|
+
* Load data of an old class/data name into the current class, expects that both classes have largely the same structure.
|
|
25
|
+
*/
|
|
26
|
+
renamedFrom(name: string): ClassMigrator<F, F>;
|
|
27
|
+
/**
|
|
28
|
+
* Migrate from one version to another.
|
|
29
|
+
*/
|
|
30
|
+
step(fromVersion: Migration.Version, toVersion: Migration.Version): PublicMigratorAPI;
|
|
31
|
+
}
|
|
32
|
+
interface ValueMigrator {
|
|
33
|
+
prop?: (val: string) => string;
|
|
34
|
+
serValue?: (val: any) => any;
|
|
35
|
+
dataValue?: (val: any) => any;
|
|
36
|
+
dataProp?: (val: string) => string;
|
|
37
|
+
}
|
|
38
|
+
declare class ClassVersionMigrator {
|
|
39
|
+
propOperations: Map<string, ValueMigrator>;
|
|
40
|
+
dataOperations: Map<string, ValueMigrator>;
|
|
41
|
+
newClassName?: string;
|
|
42
|
+
publicAPI: PublicMigratorAPI;
|
|
43
|
+
addOperation(prop: string, operation: ValueMigrator): void;
|
|
44
|
+
addDataOperation(dataName: string, operation: ValueMigrator): void;
|
|
45
|
+
}
|
|
46
|
+
declare class PublicMigratorAPI {
|
|
47
|
+
#private;
|
|
48
|
+
constructor(cvm: ClassVersionMigrator);
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
renameProperty(oldName: string, newName: string): void;
|
|
53
|
+
renameDataProperty(propName: string, dataName: string): void;
|
|
54
|
+
arrayToDict(propName: string, keyProp: string): void;
|
|
55
|
+
dictToArray(propName: string, keyProp: string): void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Migrates a given serialised or data object up to a new API version.
|
|
59
|
+
* @param obj the data to update.
|
|
60
|
+
*/
|
|
61
|
+
export declare function Migrate<T = any>(obj: T): T;
|
|
62
|
+
export declare namespace Migration {
|
|
63
|
+
class Version {
|
|
64
|
+
#private;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Registers a migration pattern for the provided class.
|
|
68
|
+
* @param klass the class to migrate data for.
|
|
69
|
+
*/
|
|
70
|
+
function Register<T>(klass: Class<T>): ClassMigrator<unknown, never>;
|
|
71
|
+
function SetBaseVersion(version: string): Version;
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @param priorVersion the version that this version is based from.
|
|
75
|
+
* @param version
|
|
76
|
+
* @param coreVersionChange
|
|
77
|
+
* @constructor
|
|
78
|
+
*/
|
|
79
|
+
function AddCoreVersion(priorVersion: Version, version: string): Version;
|
|
80
|
+
function AddModVersion(coreVersion: string, modName: string, version: string, opts?: {
|
|
81
|
+
beforeMods: (string | Version)[];
|
|
82
|
+
afterMods: (string | Version)[];
|
|
83
|
+
beforeBaseVersionUpgrade?: boolean;
|
|
84
|
+
}): Version;
|
|
85
|
+
function getLatestVersion(): SerialisedVersions;
|
|
86
|
+
}
|
|
87
|
+
export {};
|
|
88
|
+
//# sourceMappingURL=ClassMigration.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClassMigration.d.mts","sourceRoot":"","sources":["ClassMigration.mts"],"names":[],"mappings":"AAEA;;;GAGG;AAIH,UAAU,kBAAkB;IAC3B,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC;IACxB,IAAI,EAAE;QAAC,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC,OAAO,CAAA;KAAC,CAAC;CAC7C;AA+BD,cAAM,aAAa,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;gBAET,aAAa,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;IAKvD;;OAEG;IACH,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAI1B;;OAEG;IACH,aAAa,CAAC,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,MAAM;IAIrC;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM;IAIxB;;OAEG;IACH,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,OAAO;CAmBjE;AAED,UAAU,aAAa;IACtB,IAAI,C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AG,OAAO,CAW9E;IAED,SAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAC,UAAU,EAAE,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;QAAC,SAAS,EAAE,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;QAAC,wBAAwB,CAAC,EAAE,OAAO,CAAA;KAAC,GAAG,OAAO,CA0E5M;IAED,SAAgB,gBAAgB,IAAI,kBAAkB,CAErD;CACD"}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/// <reference path="./GlobalTypes.d.ts">
|
|
2
|
+
const versionMigration = [];
|
|
3
|
+
const latestVersion = {
|
|
4
|
+
core: "",
|
|
5
|
+
mods: {}
|
|
6
|
+
};
|
|
7
|
+
class ClassMigrator {
|
|
8
|
+
fromClassName;
|
|
9
|
+
toClassName;
|
|
10
|
+
constructor(fromClassName, toClassName) {
|
|
11
|
+
this.fromClassName = fromClassName;
|
|
12
|
+
this.toClassName = toClassName;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Migrate instances of this class to become instances of another class.
|
|
16
|
+
*/
|
|
17
|
+
toClass(klass) {
|
|
18
|
+
return new ClassMigrator(this.toClassName ?? this.fromClassName, klass.name);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Migrate data from an instance or a class that no longer exists into the current class.
|
|
22
|
+
*/
|
|
23
|
+
fromInterface(name) {
|
|
24
|
+
return new ClassMigrator(name, this.fromClassName);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Load data of an old class/data name into the current class, expects that both classes have largely the same structure.
|
|
28
|
+
*/
|
|
29
|
+
renamedFrom(name) {
|
|
30
|
+
return new ClassMigrator(name, this.fromClassName);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Migrate from one version to another.
|
|
34
|
+
*/
|
|
35
|
+
step(fromVersion, toVersion) {
|
|
36
|
+
for (let i = 0; i < versionMigration.length; i++) {
|
|
37
|
+
let vers = versionMigration[i];
|
|
38
|
+
if (fromVersion !== versionMigration[i - 1].name) {
|
|
39
|
+
throw new Error(`Trying to migrate from ${fromVersion} to ${toVersion}, but the previous version is ${versionMigration[i - 1].name} and cannot be skipped.`);
|
|
40
|
+
}
|
|
41
|
+
if (vers.name === toVersion) {
|
|
42
|
+
let result = vers.migration.get(this.fromClassName);
|
|
43
|
+
if (!result) {
|
|
44
|
+
vers.migration.set(this.fromClassName, result = new ClassVersionMigrator());
|
|
45
|
+
}
|
|
46
|
+
if (this.toClassName) {
|
|
47
|
+
result.newClassName = this.toClassName;
|
|
48
|
+
}
|
|
49
|
+
return result.publicAPI;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`Version ${toVersion} does not exist.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
class ClassVersionMigrator {
|
|
56
|
+
propOperations = new Map();
|
|
57
|
+
dataOperations = new Map();
|
|
58
|
+
newClassName;
|
|
59
|
+
publicAPI = new PublicMigratorAPI(this);
|
|
60
|
+
addOperation(prop, operation) {
|
|
61
|
+
let existingOperations = this.propOperations.get(prop);
|
|
62
|
+
if (!existingOperations) {
|
|
63
|
+
existingOperations = { prop: (val) => val };
|
|
64
|
+
this.propOperations.set(prop, existingOperations);
|
|
65
|
+
let dataName = prop[0].toUpperCase() + prop.slice(1);
|
|
66
|
+
this.dataOperations.set(dataName, existingOperations);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
for (let key of Object.getOwnPropertyNames(operation)) {
|
|
70
|
+
existingOperations[key] = operation[key];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
addDataOperation(dataName, operation) {
|
|
75
|
+
let propName = dataName[0].toLowerCase() + dataName.slice(1);
|
|
76
|
+
let existingOperations = this.propOperations.get(propName);
|
|
77
|
+
if (!existingOperations) {
|
|
78
|
+
existingOperations = { dataProp: (val) => val };
|
|
79
|
+
this.propOperations.set(propName, existingOperations);
|
|
80
|
+
this.dataOperations.set(dataName, existingOperations);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
for (let key of Object.getOwnPropertyNames(operation)) {
|
|
84
|
+
existingOperations[key] = operation[key];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
class PublicMigratorAPI {
|
|
90
|
+
#private;
|
|
91
|
+
constructor(cvm) {
|
|
92
|
+
this.#private = cvm;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
*/
|
|
97
|
+
renameProperty(oldName, newName) {
|
|
98
|
+
this.#private.addOperation(oldName, { prop: (val) => newName });
|
|
99
|
+
}
|
|
100
|
+
renameDataProperty(propName, dataName) {
|
|
101
|
+
this.#private.addOperation(propName, { dataProp: (val) => dataName });
|
|
102
|
+
}
|
|
103
|
+
arrayToDict(propName, keyProp) {
|
|
104
|
+
this.#private.addOperation(propName, {
|
|
105
|
+
dataValue: (val) => {
|
|
106
|
+
return val.reduce((acc, cur) => { acc[cur[keyProp]] = cur; return acc; }, {});
|
|
107
|
+
},
|
|
108
|
+
serValue: (val) => {
|
|
109
|
+
return val.reduce((acc, cur) => { acc[cur[keyProp]] = cur; return acc; }, {});
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
dictToArray(propName, keyProp) {
|
|
114
|
+
this.#private.addDataOperation(propName, {
|
|
115
|
+
serValue: (val) => {
|
|
116
|
+
return Object.keys(val).map(key => [key, val[key]]);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function getUpgradesInOrder(desiredVersions, className) {
|
|
122
|
+
let currentVersionIndex = versionMigration.findIndex((v) => v.name == desiredVersions.core);
|
|
123
|
+
let modsStartFound = {};
|
|
124
|
+
let upgrades = [];
|
|
125
|
+
while (currentVersionIndex < versionMigration.length - 1) {
|
|
126
|
+
let currentVersion = versionMigration[currentVersionIndex];
|
|
127
|
+
for (let something of currentVersion.preMigration) {
|
|
128
|
+
if (something.modName in desiredVersions.mods) {
|
|
129
|
+
if (modsStartFound[something.modName]) {
|
|
130
|
+
let classUpgrader = currentVersion.migration.get(className);
|
|
131
|
+
if (classUpgrader) {
|
|
132
|
+
if (classUpgrader.newClassName) {
|
|
133
|
+
className = classUpgrader.newClassName;
|
|
134
|
+
}
|
|
135
|
+
upgrades.push(classUpgrader);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (something.version === desiredVersions.mods[something.modName]) {
|
|
139
|
+
modsStartFound[something.modName] = true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
let classUpgrader = currentVersion.migration.get(className);
|
|
144
|
+
if (classUpgrader) {
|
|
145
|
+
if (classUpgrader.newClassName) {
|
|
146
|
+
className = classUpgrader.newClassName;
|
|
147
|
+
}
|
|
148
|
+
upgrades.push(classUpgrader);
|
|
149
|
+
}
|
|
150
|
+
for (let something of currentVersion.postMigration) {
|
|
151
|
+
if (something.modName in desiredVersions.mods) {
|
|
152
|
+
if (modsStartFound[something.modName]) {
|
|
153
|
+
let classUpgrader = currentVersion.migration.get(className);
|
|
154
|
+
if (classUpgrader) {
|
|
155
|
+
if (classUpgrader.newClassName) {
|
|
156
|
+
className = classUpgrader.newClassName;
|
|
157
|
+
}
|
|
158
|
+
upgrades.push(classUpgrader);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (something.version === desiredVersions.mods[something.modName]) {
|
|
162
|
+
modsStartFound[something.modName] = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
currentVersionIndex++;
|
|
167
|
+
}
|
|
168
|
+
return upgrades;
|
|
169
|
+
}
|
|
170
|
+
export function Migrate(obj) {
|
|
171
|
+
if (Array.isArray(obj)) {
|
|
172
|
+
//serialised object.
|
|
173
|
+
let className = obj[0];
|
|
174
|
+
let actualObject = obj[1];
|
|
175
|
+
let desiredVersions = actualObject.version;
|
|
176
|
+
let upgrades = getUpgradesInOrder(desiredVersions, className);
|
|
177
|
+
let upgradedObject = {
|
|
178
|
+
version: latestVersion
|
|
179
|
+
};
|
|
180
|
+
for (let upgrader of upgrades) {
|
|
181
|
+
if (upgrader.newClassName)
|
|
182
|
+
className = upgrader.newClassName;
|
|
183
|
+
for (let name in actualObject) {
|
|
184
|
+
if (name === "version") {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
let propUpgrader = upgrader.propOperations.get(name);
|
|
188
|
+
name = propUpgrader?.prop?.(name) ?? name;
|
|
189
|
+
if (Array.isArray(actualObject[name]) && actualObject[name].length == 2 && actualObject[name] instanceof Object && actualObject[name][1].version) {
|
|
190
|
+
let value = Migrate(actualObject[name]);
|
|
191
|
+
if (propUpgrader?.serValue) {
|
|
192
|
+
value = propUpgrader.serValue(value);
|
|
193
|
+
}
|
|
194
|
+
upgradedObject[name] = [name, value];
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
let value = actualObject[name];
|
|
198
|
+
if (propUpgrader?.dataValue) {
|
|
199
|
+
value = propUpgrader.dataValue(value);
|
|
200
|
+
}
|
|
201
|
+
upgradedObject[name] = value;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return [className, upgradedObject];
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
//data object.
|
|
209
|
+
let desiredVersions = obj.version;
|
|
210
|
+
let upgrades = getUpgradesInOrder(desiredVersions, obj.Class);
|
|
211
|
+
let upgradedObject = {
|
|
212
|
+
Class: obj.Class,
|
|
213
|
+
version: latestVersion
|
|
214
|
+
};
|
|
215
|
+
for (let upgrader of upgrades) {
|
|
216
|
+
if (upgrader.newClassName)
|
|
217
|
+
upgradedObject.Class = upgrader.newClassName;
|
|
218
|
+
for (let name in obj) {
|
|
219
|
+
if (name === "version" || name === "Class") {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
let propUpgrader = upgrader.propOperations.get(name);
|
|
223
|
+
name = propUpgrader?.prop?.(name) ?? name;
|
|
224
|
+
if (obj[name] instanceof Object && obj[name].version && obj[name].Class) {
|
|
225
|
+
let value = Migrate(obj[name]);
|
|
226
|
+
if (propUpgrader?.serValue) {
|
|
227
|
+
value = propUpgrader.serValue(value);
|
|
228
|
+
}
|
|
229
|
+
upgradedObject[name] = [name, value];
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
let value = obj[name];
|
|
233
|
+
if (propUpgrader?.dataValue) {
|
|
234
|
+
value = propUpgrader.dataValue(value);
|
|
235
|
+
}
|
|
236
|
+
upgradedObject[name] = value;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return upgradedObject;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
export var Migration;
|
|
244
|
+
(function (Migration) {
|
|
245
|
+
/**
|
|
246
|
+
* Registers a migration pattern for the provided class.
|
|
247
|
+
* @param klass the class to migrate data for.
|
|
248
|
+
*/
|
|
249
|
+
function Register(klass) {
|
|
250
|
+
return new ClassMigrator(klass.constructor.name);
|
|
251
|
+
}
|
|
252
|
+
Migration.Register = Register;
|
|
253
|
+
function SetBaseVersion(version) {
|
|
254
|
+
if (versionMigration.length > 0)
|
|
255
|
+
throw new Error("Base version was already set, cannot set base version again.");
|
|
256
|
+
versionMigration.push({
|
|
257
|
+
name: version,
|
|
258
|
+
migration: new Map(),
|
|
259
|
+
api: new Map(),
|
|
260
|
+
postMigration: [],
|
|
261
|
+
preMigration: [],
|
|
262
|
+
});
|
|
263
|
+
latestVersion.core = version;
|
|
264
|
+
return version;
|
|
265
|
+
}
|
|
266
|
+
Migration.SetBaseVersion = SetBaseVersion;
|
|
267
|
+
/**
|
|
268
|
+
*
|
|
269
|
+
* @param priorVersion the version that this version is based from.
|
|
270
|
+
* @param version
|
|
271
|
+
* @param coreVersionChange
|
|
272
|
+
* @constructor
|
|
273
|
+
*/
|
|
274
|
+
function AddCoreVersion(priorVersion, version) {
|
|
275
|
+
let index = versionMigration.findIndex((v) => v.name == priorVersion) + 1;
|
|
276
|
+
versionMigration.splice(index, 0, {
|
|
277
|
+
name: version,
|
|
278
|
+
migration: new Map(),
|
|
279
|
+
api: new Map(),
|
|
280
|
+
postMigration: [],
|
|
281
|
+
preMigration: [],
|
|
282
|
+
});
|
|
283
|
+
latestVersion.core = version;
|
|
284
|
+
return version;
|
|
285
|
+
}
|
|
286
|
+
Migration.AddCoreVersion = AddCoreVersion;
|
|
287
|
+
function AddModVersion(coreVersion, modName, version, opts) {
|
|
288
|
+
let currentVersion = versionMigration.find((v) => v.name == coreVersion);
|
|
289
|
+
if (!currentVersion)
|
|
290
|
+
throw new Error(`Cannot add mod version ${version} to core version ${coreVersion} as it does not exist.`);
|
|
291
|
+
let finalVersionName = (modName + "_" + version);
|
|
292
|
+
let migrationTime = opts?.beforeBaseVersionUpgrade ? currentVersion.preMigration : currentVersion.postMigration;
|
|
293
|
+
let beforeLoc = opts?.beforeMods ?? [];
|
|
294
|
+
let afterLoc = opts?.afterMods ?? [];
|
|
295
|
+
latestVersion.mods[modName] = finalVersionName;
|
|
296
|
+
migrationTime.forEach((e) => {
|
|
297
|
+
//TODO: Check to see if any of the befores are already in the afters and vice versa
|
|
298
|
+
// - that's an error condition.
|
|
299
|
+
if (beforeLoc.includes(e.modName) || beforeLoc.includes(e.version)) {
|
|
300
|
+
e.after = e.after.concat(afterLoc);
|
|
301
|
+
afterLoc = afterLoc.concat(e.after);
|
|
302
|
+
}
|
|
303
|
+
if (afterLoc.includes(e.modName) || afterLoc.includes(e.version)) {
|
|
304
|
+
e.before = e.before.concat(beforeLoc);
|
|
305
|
+
beforeLoc = beforeLoc.concat(e.before);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
migrationTime.push({
|
|
309
|
+
modName: modName,
|
|
310
|
+
version: finalVersionName,
|
|
311
|
+
migration: new Map(),
|
|
312
|
+
api: new Map(),
|
|
313
|
+
before: beforeLoc,
|
|
314
|
+
after: afterLoc,
|
|
315
|
+
});
|
|
316
|
+
migrationTime.sort((a, b) => {
|
|
317
|
+
if (a.before.includes(b.modName) || a.before.includes(b.version)) {
|
|
318
|
+
return -1;
|
|
319
|
+
}
|
|
320
|
+
if (b.before.includes(a.modName) || b.before.includes(a.version)) {
|
|
321
|
+
return 1;
|
|
322
|
+
}
|
|
323
|
+
if (a.after.includes(b.modName) || a.after.includes(b.version)) {
|
|
324
|
+
return 1;
|
|
325
|
+
}
|
|
326
|
+
if (b.after.includes(a.modName) || b.after.includes(a.version)) {
|
|
327
|
+
return -1;
|
|
328
|
+
}
|
|
329
|
+
return 0;
|
|
330
|
+
});
|
|
331
|
+
// let earlyIndex = migrationTime.reduce<number>((previousIndex, currentMod, index) => {
|
|
332
|
+
// if (beforeLoc.includes(currentMod.modName)) {
|
|
333
|
+
// return index;
|
|
334
|
+
// }
|
|
335
|
+
// if (currentMod.after.includes(modName)) {
|
|
336
|
+
// return index;
|
|
337
|
+
// }
|
|
338
|
+
// return previousIndex;
|
|
339
|
+
// }, 0 ) ?? 0;
|
|
340
|
+
// let lateIndex = migrationTime.reduceRight<number>((previousIndex, currentMod, index) => {
|
|
341
|
+
// if (afterLoc.includes(currentMod.modName)) {
|
|
342
|
+
// return index + 1;
|
|
343
|
+
// }
|
|
344
|
+
// if (currentMod.before.includes(modName)) {
|
|
345
|
+
// return index + 1;
|
|
346
|
+
// }
|
|
347
|
+
// return previousIndex;
|
|
348
|
+
// }, migrationTime.length - 1 ) ?? migrationTime.length - 1;
|
|
349
|
+
// if (earlyIndex > lateIndex) {
|
|
350
|
+
// throw new Error(`Cannot add mod version ${version} to core version ${coreVersion} as it conflicts with other mods.`);
|
|
351
|
+
// }
|
|
352
|
+
// migrationTime.splice(earlyIndex, 0, {
|
|
353
|
+
// modName: modName,
|
|
354
|
+
// version: finalVersionName,
|
|
355
|
+
// migration: new Map(),
|
|
356
|
+
// api: new Map(),
|
|
357
|
+
// before: opts?.beforeMods ?? [],
|
|
358
|
+
// after: opts?.afterMods ?? [],
|
|
359
|
+
// });
|
|
360
|
+
return finalVersionName;
|
|
361
|
+
}
|
|
362
|
+
Migration.AddModVersion = AddModVersion;
|
|
363
|
+
function getLatestVersion() {
|
|
364
|
+
return latestVersion;
|
|
365
|
+
}
|
|
366
|
+
Migration.getLatestVersion = getLatestVersion;
|
|
367
|
+
})(Migration || (Migration = {}));
|
|
368
|
+
//# sourceMappingURL=ClassMigration.mjs.map
|