whet 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/bin/HxOverrides.d.ts +8 -0
  4. package/bin/HxOverrides.js +54 -0
  5. package/bin/Lambda.d.ts +86 -0
  6. package/bin/Lambda.js +141 -0
  7. package/bin/Map.d.ts +5 -0
  8. package/bin/Reflect.d.ts +19 -0
  9. package/bin/Reflect.js +41 -0
  10. package/bin/Std.d.ts +49 -0
  11. package/bin/Std.js +96 -0
  12. package/bin/StdTypes.d.ts +57 -0
  13. package/bin/StringTools.d.ts +23 -0
  14. package/bin/StringTools.js +36 -0
  15. package/bin/commander/AddHelpTextContext.d.ts +6 -0
  16. package/bin/commander/AddHelpTextPosition.d.ts +2 -0
  17. package/bin/commander/CommandOptions.d.ts +6 -0
  18. package/bin/commander/ErrorOptions.d.ts +11 -0
  19. package/bin/commander/ExecutableCommandOptions.d.ts +7 -0
  20. package/bin/commander/HelpContext.d.ts +4 -0
  21. package/bin/commander/HookEvent.d.ts +2 -0
  22. package/bin/commander/OptionValueSource.d.ts +2 -0
  23. package/bin/commander/OutputConfiguration.d.ts +8 -0
  24. package/bin/commander/ParseOptions.d.ts +4 -0
  25. package/bin/commander/ParseOptionsResult.d.ts +5 -0
  26. package/bin/genes/Register.d.ts +15 -0
  27. package/bin/genes/Register.js +107 -0
  28. package/bin/genes/util/EsMap.d.ts +12 -0
  29. package/bin/genes/util/EsMap.js +51 -0
  30. package/bin/haxe/Constraints.d.ts +8 -0
  31. package/bin/haxe/Constraints.js +5 -0
  32. package/bin/haxe/Exception.d.ts +66 -0
  33. package/bin/haxe/Exception.js +88 -0
  34. package/bin/haxe/NativeStackTrace.d.ts +7 -0
  35. package/bin/haxe/PosInfos.d.ts +19 -0
  36. package/bin/haxe/Rest.d.ts +2 -0
  37. package/bin/haxe/ValueException.d.ts +24 -0
  38. package/bin/haxe/ValueException.js +36 -0
  39. package/bin/haxe/crypto/Crc32.d.ts +12 -0
  40. package/bin/haxe/crypto/Crc32.js +40 -0
  41. package/bin/haxe/ds/List.d.ts +31 -0
  42. package/bin/haxe/ds/List.js +55 -0
  43. package/bin/haxe/ds/ObjectMap.d.ts +7 -0
  44. package/bin/haxe/ds/ObjectMap.js +25 -0
  45. package/bin/haxe/ds/StringMap.d.ts +6 -0
  46. package/bin/haxe/ds/StringMap.js +25 -0
  47. package/bin/haxe/exceptions/NotImplementedException.d.ts +10 -0
  48. package/bin/haxe/exceptions/NotImplementedException.js +27 -0
  49. package/bin/haxe/exceptions/PosException.d.ts +19 -0
  50. package/bin/haxe/exceptions/PosException.js +36 -0
  51. package/bin/haxe/extern/Rest.d.ts +11 -0
  52. package/bin/haxe/io/ArrayBufferView.d.ts +2 -0
  53. package/bin/haxe/io/Bytes.d.ts +19 -0
  54. package/bin/haxe/io/Bytes.js +78 -0
  55. package/bin/haxe/io/BytesBuffer.d.ts +19 -0
  56. package/bin/haxe/io/BytesBuffer.js +67 -0
  57. package/bin/haxe/io/BytesData.d.ts +2 -0
  58. package/bin/haxe/io/BytesOutput.d.ts +18 -0
  59. package/bin/haxe/io/BytesOutput.js +39 -0
  60. package/bin/haxe/io/Encoding.d.ts +20 -0
  61. package/bin/haxe/io/Encoding.js +20 -0
  62. package/bin/haxe/io/Error.d.ts +35 -0
  63. package/bin/haxe/io/Error.js +31 -0
  64. package/bin/haxe/io/Output.d.ts +63 -0
  65. package/bin/haxe/io/Output.js +126 -0
  66. package/bin/haxe/io/Path.d.ts +109 -0
  67. package/bin/haxe/io/Path.js +217 -0
  68. package/bin/haxe/io/UInt8Array.d.ts +2 -0
  69. package/bin/haxe/iterators/ArrayIterator.d.ts +19 -0
  70. package/bin/haxe/iterators/ArrayIterator.js +35 -0
  71. package/bin/haxe/macro/Expr.d.ts +331 -0
  72. package/bin/haxe/macro/Type.d.ts +609 -0
  73. package/bin/haxe/zip/Compress.d.ts +5 -0
  74. package/bin/haxe/zip/Compress.js +21 -0
  75. package/bin/haxe/zip/Entry.d.ts +27 -0
  76. package/bin/haxe/zip/Entry.js +15 -0
  77. package/bin/haxe/zip/Tools.d.ts +5 -0
  78. package/bin/haxe/zip/Tools.js +24 -0
  79. package/bin/haxe/zip/Writer.d.ts +22 -0
  80. package/bin/haxe/zip/Writer.js +149 -0
  81. package/bin/js/Boot.d.ts +18 -0
  82. package/bin/js/Boot.js +225 -0
  83. package/bin/js/Node.d.ts +6 -0
  84. package/bin/js/lib/ArrayBuffer.d.ts +4 -0
  85. package/bin/js/lib/ArrayBuffer.js +24 -0
  86. package/bin/js/lib/Iterator.d.ts +23 -0
  87. package/bin/js/lib/Map.d.ts +2 -0
  88. package/bin/js/lib/Object.d.ts +82 -0
  89. package/bin/js/lib/Promise.d.ts +10 -0
  90. package/bin/js/lib/intl/NumberFormat.d.ts +114 -0
  91. package/bin/js/node/Buffer.d.ts +3 -0
  92. package/bin/js/node/ChildProcess.d.ts +424 -0
  93. package/bin/js/node/Crypto.d.ts +21 -0
  94. package/bin/js/node/Dns.d.ts +57 -0
  95. package/bin/js/node/Fs.d.ts +308 -0
  96. package/bin/js/node/Http.d.ts +114 -0
  97. package/bin/js/node/Https.d.ts +330 -0
  98. package/bin/js/node/Iterator.d.ts +5 -0
  99. package/bin/js/node/Path.d.ts +44 -0
  100. package/bin/js/node/Process.d.ts +6 -0
  101. package/bin/js/node/Tls.d.ts +304 -0
  102. package/bin/js/node/Url.d.ts +126 -0
  103. package/bin/js/node/Util.d.ts +115 -0
  104. package/bin/js/node/Zlib.d.ts +29 -0
  105. package/bin/js/node/buffer/Buffer.d.ts +23 -0
  106. package/bin/js/node/buffer/Buffer.js +24 -0
  107. package/bin/js/node/child_process/ChildProcess.d.ts +11 -0
  108. package/bin/js/node/console/Console.d.ts +26 -0
  109. package/bin/js/node/http/Agent.d.ts +40 -0
  110. package/bin/js/node/http/ClientRequest.d.ts +10 -0
  111. package/bin/js/node/https/Agent.d.ts +50 -0
  112. package/bin/js/node/net/Server.d.ts +22 -0
  113. package/bin/js/node/net/Socket.d.ts +101 -0
  114. package/bin/js/node/stream/Duplex.d.ts +86 -0
  115. package/bin/js/node/stream/Readable.d.ts +41 -0
  116. package/bin/js/node/stream/Transform.d.ts +92 -0
  117. package/bin/js/node/stream/Writable.d.ts +57 -0
  118. package/bin/js/node/tls/SecureContext.d.ts +74 -0
  119. package/bin/js/node/tls/TLSSocket.d.ts +47 -0
  120. package/bin/ts/Undefined.d.ts +5 -0
  121. package/bin/whet/Log.d.ts +16 -0
  122. package/bin/whet/Log.js +106 -0
  123. package/bin/whet/Project.d.ts +33 -0
  124. package/bin/whet/Project.js +71 -0
  125. package/bin/whet/Source.d.ts +51 -0
  126. package/bin/whet/Source.js +136 -0
  127. package/bin/whet/SourceHash.d.ts +15 -0
  128. package/bin/whet/SourceHash.js +68 -0
  129. package/bin/whet/SourceId.d.ts +10 -0
  130. package/bin/whet/SourceId.js +74 -0
  131. package/bin/whet/Stone.d.ts +88 -0
  132. package/bin/whet/Stone.js +157 -0
  133. package/bin/whet/Utils.d.ts +16 -0
  134. package/bin/whet/Utils.js +72 -0
  135. package/bin/whet/Whet.d.ts +4 -0
  136. package/bin/whet/Whet.js +117 -0
  137. package/bin/whet/cache/BaseCache.d.ts +27 -0
  138. package/bin/whet/cache/BaseCache.js +210 -0
  139. package/bin/whet/cache/Cache.d.ts +72 -0
  140. package/bin/whet/cache/Cache.js +57 -0
  141. package/bin/whet/cache/CacheManager.d.ts +23 -0
  142. package/bin/whet/cache/CacheManager.js +103 -0
  143. package/bin/whet/cache/FileCache.d.ts +35 -0
  144. package/bin/whet/cache/FileCache.js +295 -0
  145. package/bin/whet/cache/MemoryCache.d.ts +12 -0
  146. package/bin/whet/cache/MemoryCache.js +58 -0
  147. package/bin/whet/magic/MaybeArray.d.ts +4 -0
  148. package/bin/whet/magic/MaybeArray.js +25 -0
  149. package/bin/whet/magic/RoutePathType.d.ts +9 -0
  150. package/bin/whet/magic/RoutePathType.js +48 -0
  151. package/bin/whet/magic/RouteType.d.ts +12 -0
  152. package/bin/whet/magic/RouteType.js +70 -0
  153. package/bin/whet/magic/StoneId.d.ts +5 -0
  154. package/bin/whet/magic/StoneId.js +32 -0
  155. package/bin/whet/route/Route.d.ts +15 -0
  156. package/bin/whet/route/Route.js +81 -0
  157. package/bin/whet/route/RouteResult.d.ts +22 -0
  158. package/bin/whet/route/RouteResult.js +25 -0
  159. package/bin/whet/route/Router.d.ts +33 -0
  160. package/bin/whet/route/Router.js +224 -0
  161. package/bin/whet/stones/Files.d.ts +28 -0
  162. package/bin/whet/stones/Files.js +86 -0
  163. package/bin/whet/stones/JsonStone.d.ts +33 -0
  164. package/bin/whet/stones/JsonStone.js +117 -0
  165. package/bin/whet/stones/RemoteFile.d.ts +28 -0
  166. package/bin/whet/stones/RemoteFile.js +71 -0
  167. package/bin/whet/stones/Server.d.ts +42 -0
  168. package/bin/whet/stones/Server.js +113 -0
  169. package/bin/whet/stones/Zip.d.ts +30 -0
  170. package/bin/whet/stones/Zip.js +111 -0
  171. package/bin/whet/stones/haxe/HaxeBuild.d.ts +34 -0
  172. package/bin/whet/stones/haxe/HaxeBuild.js +89 -0
  173. package/bin/whet/stones/haxe/Hxml.d.ts +102 -0
  174. package/bin/whet/stones/haxe/Hxml.js +348 -0
  175. package/bin/whet.d.ts +20 -0
  176. package/bin/whet.js +18 -0
  177. package/package.json +32 -0
@@ -0,0 +1,117 @@
1
+ import {Project} from "./Project.js"
2
+ import {LogLevel, Log} from "./Log.js"
3
+ import * as Url from "url"
4
+ import {Register} from "../genes/Register.js"
5
+ import {Command} from "commander"
6
+ import {Std} from "../Std.js"
7
+
8
+ const $global = Register.$global
9
+
10
+ export const Whet_Fields_ = Register.global("$hxClasses")["whet._Whet.Whet_Fields_"] =
11
+ class Whet_Fields_ {
12
+ static main() {
13
+ Whet_Fields_.program.enablePositionalOptions().passThroughOptions().description("Project tooling.").usage("[options] [command] [+ [command]...]").version("0.0.1", "-v, --version").allowUnknownOption(true).showSuggestionAfterError(true).option("-p, --project <file>", "project to run", "Project.mjs").option("-l, --log-level <level>", "log level, a string/number", "info");
14
+ Whet_Fields_.program.parse();
15
+ var options = Whet_Fields_.program.opts();
16
+ if (options.logLevel != null) {
17
+ var n = Std.parseInt(options.logLevel);
18
+ if (n == null) {
19
+ n = LogLevel.fromString(options.logLevel);
20
+ };
21
+ if (n == null) {
22
+ Whet_Fields_.program.error("Invalid value for --log-level");
23
+ } else {
24
+ Log.logLevel = n;
25
+ };
26
+ };
27
+ global.setImmediate(Whet_Fields_.init, options);
28
+ }
29
+ static init(options) {
30
+ if (Project.projects.length > 0) {
31
+ Whet_Fields_.initProjects();
32
+ } else {
33
+ Log.log(30, ...["Loading project.", {"file": options.project}]);
34
+ var path = Url.pathToFileURL(options.project).href;
35
+ Log.log(20, ...["Resolved project path.", {"path": path}]);
36
+ import(path).then(function (module) {
37
+ Log.log(10, ...["Project module imported."]);
38
+ Whet_Fields_.initProjects();
39
+ })["catch"](function (e) {
40
+ Log.log(50, ...["Error loading project.", {"error": e}]);
41
+ return Whet_Fields_.program.help();
42
+ });
43
+ };
44
+ }
45
+ static initProjects() {
46
+ Log.log(10, ...["Parsing remaining arguments.", {"args": Whet_Fields_.program.args}]);
47
+ var _g = 0;
48
+ var _g1 = Project.projects;
49
+ while (_g < _g1.length) {
50
+ var _g2 = 0;
51
+ var _g3 = _g1[_g++].options;
52
+ while (_g2 < _g3.length) Whet_Fields_.program.addOption(_g3[_g2++]);
53
+ };
54
+ Whet_Fields_.program.allowUnknownOption(false);
55
+ var commands = Whet_Fields_.getCommands(Whet_Fields_.program.args);
56
+ var initProm;
57
+ if (commands.length > 0) {
58
+ var res = Whet_Fields_.program.parseOptions(commands[0]);
59
+ commands[0] = res.operands.concat(res.unknown);
60
+ var promises = [];
61
+ var _g = 0;
62
+ var _g1 = Project.projects;
63
+ while (_g < _g1.length) {
64
+ var p = _g1[_g];
65
+ ++_g;
66
+ if (p.onInit != null) {
67
+ var prom = p.onInit(Whet_Fields_.program.opts());
68
+ if (prom != null) {
69
+ promises.push(prom);
70
+ };
71
+ };
72
+ };
73
+ initProm = Promise.all(promises);
74
+ } else {
75
+ initProm = Promise.resolve();
76
+ };
77
+ var nextCommand = null;
78
+ nextCommand = function () {
79
+ if (commands.length == 0) {
80
+ return;
81
+ };
82
+ var c = commands.shift();
83
+ Log.log(10, ...["Executing command.", {"commandArgs": c}]);
84
+ Whet_Fields_.program.parseAsync(c, {"from": "user"}).then(function (_) {
85
+ nextCommand();
86
+ });
87
+ };
88
+ initProm.then(function (_) {
89
+ nextCommand();
90
+ });
91
+ }
92
+ static getCommands(args) {
93
+ var commands = [];
94
+ var from = 0;
95
+ var to;
96
+ while (true) {
97
+ to = args.indexOf("+", from);
98
+ commands.push((to < 0) ? args.slice(from) : args.slice(from, to));
99
+ from = to + 1;
100
+ if (!(to >= 0)) {
101
+ break;
102
+ };
103
+ };
104
+ return commands;
105
+ }
106
+ static get __name__() {
107
+ return "whet._Whet.Whet_Fields_"
108
+ }
109
+ get __class__() {
110
+ return Whet_Fields_
111
+ }
112
+ }
113
+
114
+
115
+ Whet_Fields_.program = new Command("whet")
116
+ export const program = Whet_Fields_.program
117
+ export const main = Whet_Fields_.main
@@ -0,0 +1,27 @@
1
+ import {Cache, CacheDurability, DurabilityCheck} from "./Cache"
2
+ import {AnyStone} from "../Stone"
3
+ import {SourceHash} from "../SourceHash"
4
+ import {Source} from "../Source"
5
+ import {Map as Map__1} from "../../Map"
6
+
7
+ export declare class BaseCache<Key, Value extends {
8
+ ctime: number,
9
+ hash: SourceHash
10
+ }> implements Cache {
11
+ constructor(rootDir: string, cache: Map__1<Key, Value[]>)
12
+ protected cache: Map__1<Key, Value[]>
13
+ protected rootDir: string
14
+ get(stone: AnyStone, durability: CacheDurability, check: DurabilityCheck): Promise<Source>
15
+ protected set(source: Source): Promise<Value>
16
+ getUniqueDir(stone: AnyStone, baseDir: string, hash?: null | SourceHash): string
17
+ protected checkDurability(stone: AnyStone, values: Value[], durability: CacheDurability, useIndex: ((arg0: Value) => number), ageIndex: ((arg0: Value) => number)): void
18
+ protected shouldKeep(stone: AnyStone, val: Value, durability: CacheDurability, useIndex: ((arg0: Value) => number), ageIndex: ((arg0: Value) => number)): boolean
19
+ protected setRecentUseOrder(values: Value[], value: Value): boolean
20
+ protected remove(stone: AnyStone, value: Value): Promise<any>
21
+ protected key(stone: AnyStone): Key
22
+ protected value(source: Source): Promise<Value>
23
+ protected source(stone: AnyStone, value: Value): Promise<Source>
24
+ protected getExistingDirs(stone: AnyStone): string[]
25
+ protected getDirFor(value: Value): string
26
+ toString(): string
27
+ }
@@ -0,0 +1,210 @@
1
+ import {Cache} from "./Cache.js"
2
+ import {SourceId} from "../SourceId.js"
3
+ import {SourceHash} from "../SourceHash.js"
4
+ import {Log} from "../Log.js"
5
+ import {Boot} from "../../js/Boot.js"
6
+ import {Path} from "../../haxe/io/Path.js"
7
+ import {Register} from "../../genes/Register.js"
8
+ import {Std} from "../../Std.js"
9
+ import {Lambda} from "../../Lambda.js"
10
+ import {HxOverrides} from "../../HxOverrides.js"
11
+
12
+ const $global = Register.$global
13
+
14
+ export const BaseCache = Register.global("$hxClasses")["whet.cache.BaseCache"] =
15
+ class BaseCache extends Register.inherits() {
16
+ new(rootDir, cache) {
17
+ var norm = "/" + Path.normalize((rootDir.charAt(0) == "/") ? HxOverrides.substr(rootDir, 1, null) : rootDir);
18
+ var tmp = (rootDir.lastIndexOf("/") == rootDir.length - 1) ? Path.addTrailingSlash(norm) : norm;
19
+ var s = Path.addTrailingSlash(Path.directory(rootDir));
20
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
21
+ if (tmp != ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm)) {
22
+ throw new Error("Root dir is a not a dir.");
23
+ };
24
+ this.rootDir = rootDir;
25
+ this.cache = cache;
26
+ }
27
+ get(stone, durability, check) {
28
+ var _gthis = this;
29
+ Log.log(20, ...["Looking for cached source.", {"stone": stone, "cache": this}]);
30
+ return stone.generateHash().then(function (hash) {
31
+ if (hash == null) {
32
+ Log.log(10, ...["Generating source, because it does not supply a hash.", {"stone": stone, "cache": _gthis}]);
33
+ };
34
+ if (hash == null) {
35
+ return stone.generateSource(null).then(function (generatedSource) {
36
+ return {"generatedSource": generatedSource, "hash": generatedSource.hash};
37
+ });
38
+ } else {
39
+ return Promise.resolve({"generatedSource": null, "hash": hash});
40
+ };
41
+ }).then(function (data) {
42
+ var generatedSource = data.generatedSource;
43
+ var hash = data.hash;
44
+ var values = _gthis.cache.get(_gthis.key(stone));
45
+ var ageCount = function (val) {
46
+ return Lambda.count(values, function (v) {
47
+ if (v != val) {
48
+ return v.ctime > val.ctime;
49
+ } else {
50
+ return false;
51
+ };
52
+ });
53
+ };
54
+ var value = null;
55
+ if (values != null && values.length > 0) {
56
+ value = Lambda.find(values, function (v) {
57
+ return SourceHash.equals(v.hash, hash);
58
+ });
59
+ if (value != null && check._hx_index == 2 && !_gthis.shouldKeep(stone, value, durability, function (v) {
60
+ return 0;
61
+ }, ageCount)) {
62
+ _gthis.remove(stone, value);
63
+ value = null;
64
+ };
65
+ if (value != null) {
66
+ _gthis.setRecentUseOrder(values, value);
67
+ };
68
+ };
69
+ var srcPromise = ((value != null) ? _gthis.source(stone, value) : Promise.resolve(null)).then(function (src) {
70
+ if (src == null) {
71
+ Log.log(10, ...["Not cached.", {"stone": stone, "cache": _gthis}]);
72
+ return ((value != null) ? _gthis.remove(stone, value) : Promise.resolve(null)).then(function (_) {
73
+ if (check._hx_index == 1) {
74
+ _gthis.checkDurability(stone, values, durability, function (v) {
75
+ return values.indexOf(v) + 1;
76
+ }, function (v) {
77
+ return ageCount(v) + 1;
78
+ });
79
+ };
80
+ return ((generatedSource != null) ? Promise.resolve(generatedSource) : stone.generateSource(hash)).then(function (src) {
81
+ return _gthis.set(src);
82
+ }).then(function (val) {
83
+ return _gthis.source(stone, val);
84
+ });
85
+ });
86
+ } else {
87
+ Log.log(10, ...["Found in cache", {"stone": stone, "cache": _gthis}]);
88
+ return Promise.resolve(src);
89
+ };
90
+ });
91
+ srcPromise.then(function (_) {
92
+ if ((check == null) ? true : check._hx_index == 0) {
93
+ _gthis.checkDurability(stone, values, durability, function (v) {
94
+ return values.indexOf(v);
95
+ }, ageCount);
96
+ };
97
+ });
98
+ return srcPromise;
99
+ });
100
+ }
101
+ set(source) {
102
+ var _gthis = this;
103
+ var k = this.key(source.origin);
104
+ if (!this.cache.exists(k)) {
105
+ this.cache.set(k, []);
106
+ };
107
+ return this.value(source).then(function (val) {
108
+ _gthis.cache.get(k).unshift(val);
109
+ return val;
110
+ });
111
+ }
112
+ getUniqueDir(stone, baseDir, hash) {
113
+ var _gthis = this;
114
+ if (hash != null) {
115
+ var values = this.cache.get(this.key(stone));
116
+ if (values != null) {
117
+ var existingVal = Lambda.find(values, function (v) {
118
+ return SourceHash.equals(v.hash, hash);
119
+ });
120
+ if (existingVal != null) {
121
+ var existingPath = this.getDirFor(existingVal);
122
+ if (existingPath != null) {
123
+ return existingPath;
124
+ };
125
+ };
126
+ };
127
+ };
128
+ var filenames = this.getExistingDirs(stone);
129
+ var maxNum = (filenames != null) ? Lambda.fold(filenames, function (fn, num) {
130
+ var s = Path.addTrailingSlash(Path.directory(fn));
131
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
132
+ var this1 = (s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm;
133
+ var root = _gthis.rootDir;
134
+ var parts = ((root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1).split("/");
135
+ var name = (parts.length > 1) ? parts[parts.length - 2] : "";
136
+ return Math.max(num, (name.charAt(0) == "v") ? Std.parseInt(HxOverrides.substr(name, 1, null)) : 0);
137
+ }, 0) : 0;
138
+ ++maxNum;
139
+ var s = "v" + maxNum + "/";
140
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
141
+ return SourceId.getPutInDir((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm, baseDir);
142
+ }
143
+ checkDurability(stone, values, durability, useIndex, ageIndex) {
144
+ Log.log(10, ...["Checking durability.", {"stone": stone, "durability": Std.string(durability)}]);
145
+ if (values == null || values.length == 0) {
146
+ return;
147
+ };
148
+ var i = values.length;
149
+ while (--i > 0) if (!this.shouldKeep(stone, values[i], durability, useIndex, ageIndex)) {
150
+ this.remove(stone, values[i]);
151
+ };
152
+ }
153
+ shouldKeep(stone, val, durability, useIndex, ageIndex) {
154
+ var _gthis = this;
155
+ switch (durability._hx_index) {
156
+ case 0:
157
+ return true;
158
+ break
159
+ case 1:
160
+ return useIndex(val) < durability.count;
161
+ break
162
+ case 2:
163
+ return ageIndex(val) < durability.count;
164
+ break
165
+ case 3:
166
+ return Date.now() / 1000 - val.ctime <= durability.seconds;
167
+ break
168
+ case 4:
169
+ return durability.keep(stone, val);
170
+ break
171
+ case 5:
172
+ return Lambda.foreach(durability.keepIfAll, function (d) {
173
+ return _gthis.shouldKeep(stone, val, d, useIndex, ageIndex);
174
+ });
175
+ break
176
+ case 6:
177
+ return Lambda.exists(durability.keepIfAny, function (d) {
178
+ return _gthis.shouldKeep(stone, val, d, useIndex, ageIndex);
179
+ });
180
+ break
181
+
182
+ };
183
+ }
184
+ setRecentUseOrder(values, value) {
185
+ if (values[0] == value) {
186
+ return false;
187
+ };
188
+ HxOverrides.remove(values, value);
189
+ values.unshift(value);
190
+ return true;
191
+ }
192
+ remove(stone, value) {
193
+ HxOverrides.remove(this.cache.get(this.key(stone)), value);
194
+ return Promise.resolve(null);
195
+ }
196
+ toString() {
197
+ var c = Boot.getClass(this);
198
+ return c.__name__;
199
+ }
200
+ static get __name__() {
201
+ return "whet.cache.BaseCache"
202
+ }
203
+ static get __interfaces__() {
204
+ return [Cache]
205
+ }
206
+ get __class__() {
207
+ return BaseCache
208
+ }
209
+ }
210
+
@@ -0,0 +1,72 @@
1
+ import {AnyStone} from "../Stone"
2
+
3
+ export declare interface Cache {
4
+ }
5
+
6
+ export declare namespace CacheStrategy {
7
+ export type None = {_hx_index: 0, __enum__: "whet.cache.CacheStrategy"}
8
+ export const None: None
9
+ export type InMemory = {_hx_index: 1, durability: CacheDurability, check: null | DurabilityCheck, __enum__: "whet.cache.CacheStrategy"}
10
+ export const InMemory: (durability: CacheDurability, check: null | DurabilityCheck) => CacheStrategy
11
+ export type InFile = {_hx_index: 2, durability: CacheDurability, check: null | DurabilityCheck, __enum__: "whet.cache.CacheStrategy"}
12
+ export const InFile: (durability: CacheDurability, check: null | DurabilityCheck) => CacheStrategy
13
+ export type AbsolutePath = {_hx_index: 3, path: string, durability: CacheDurability, check: null | DurabilityCheck, __enum__: "whet.cache.CacheStrategy"}
14
+ export const AbsolutePath: (path: string, durability: CacheDurability, check: null | DurabilityCheck) => CacheStrategy
15
+ }
16
+
17
+ export declare type CacheStrategy =
18
+ | CacheStrategy.None
19
+ | CacheStrategy.InMemory
20
+ | CacheStrategy.InFile
21
+ | CacheStrategy.AbsolutePath
22
+
23
+ export declare namespace CacheDurability {
24
+ export type MaxAge = {_hx_index: 3, seconds: number, __enum__: "whet.cache.CacheDurability"}
25
+ export const MaxAge: (seconds: number) => CacheDurability
26
+ export type LimitCountByLastUse = {_hx_index: 1, count: number, __enum__: "whet.cache.CacheDurability"}
27
+ export const LimitCountByLastUse: (count: number) => CacheDurability
28
+ export type LimitCountByAge = {_hx_index: 2, count: number, __enum__: "whet.cache.CacheDurability"}
29
+ export const LimitCountByAge: (count: number) => CacheDurability
30
+ export type KeepForever = {_hx_index: 0, __enum__: "whet.cache.CacheDurability"}
31
+ export const KeepForever: KeepForever
32
+ export type Custom = {_hx_index: 4, keep: ((arg0: AnyStone, arg1: any) => boolean), __enum__: "whet.cache.CacheDurability"}
33
+ export const Custom: (keep: ((arg0: AnyStone, arg1: any) => boolean)) => CacheDurability
34
+ export type Any = {_hx_index: 6, keepIfAny: CacheDurability[], __enum__: "whet.cache.CacheDurability"}
35
+ export const Any: (keepIfAny: CacheDurability[]) => CacheDurability
36
+ export type All = {_hx_index: 5, keepIfAll: CacheDurability[], __enum__: "whet.cache.CacheDurability"}
37
+ export const All: (keepIfAll: CacheDurability[]) => CacheDurability
38
+ }
39
+
40
+ export declare type CacheDurability =
41
+ | CacheDurability.MaxAge
42
+ | CacheDurability.LimitCountByLastUse
43
+ | CacheDurability.LimitCountByAge
44
+ | CacheDurability.KeepForever
45
+ | CacheDurability.Custom
46
+ | CacheDurability.Any
47
+ | CacheDurability.All
48
+
49
+ export declare namespace DurabilityCheck {
50
+ export type SingleOnGet = {_hx_index: 2, __enum__: "whet.cache.DurabilityCheck"}
51
+ export const SingleOnGet: SingleOnGet
52
+ export type AllOnUse = {_hx_index: 0, __enum__: "whet.cache.DurabilityCheck"}
53
+ export const AllOnUse: AllOnUse
54
+ export type AllOnSet = {_hx_index: 1, __enum__: "whet.cache.DurabilityCheck"}
55
+ export const AllOnSet: AllOnSet
56
+ }
57
+
58
+ export declare type DurabilityCheck =
59
+ /**
60
+ * Checks just the cached source when receiving it. Useful for custom durability checks
61
+ * and situations where the hash isn't ensuring validity.
62
+ */
63
+ | DurabilityCheck.SingleOnGet
64
+ /**
65
+ Checks all cached sources for a stone, whenever the cache is used. The default.
66
+ */
67
+ | DurabilityCheck.AllOnUse
68
+ /**
69
+ * Checks all cached sources for a stone, whenever any resource is being added to the cache.
70
+ * Improves performance, but can leave behind invalid files.
71
+ */
72
+ | DurabilityCheck.AllOnSet
@@ -0,0 +1,57 @@
1
+ import {Register} from "../../genes/Register.js"
2
+
3
+ const $global = Register.$global
4
+
5
+ export const Cache = {}
6
+
7
+ export const CacheStrategy =
8
+ Register.global("$hxEnums")["whet.cache.CacheStrategy"] =
9
+ {
10
+ __ename__: "whet.cache.CacheStrategy",
11
+
12
+ None: {_hx_name: "None", _hx_index: 0, __enum__: "whet.cache.CacheStrategy"},
13
+ InMemory: Object.assign((durability, check) => ({_hx_index: 1, __enum__: "whet.cache.CacheStrategy", "durability": durability, "check": check}), {_hx_name: "InMemory", __params__: ["durability", "check"]}),
14
+ InFile: Object.assign((durability, check) => ({_hx_index: 2, __enum__: "whet.cache.CacheStrategy", "durability": durability, "check": check}), {_hx_name: "InFile", __params__: ["durability", "check"]}),
15
+ AbsolutePath: Object.assign((path, durability, check) => ({_hx_index: 3, __enum__: "whet.cache.CacheStrategy", "path": path, "durability": durability, "check": check}), {_hx_name: "AbsolutePath", __params__: ["path", "durability", "check"]})
16
+ }
17
+ CacheStrategy.__constructs__ = [CacheStrategy.None, CacheStrategy.InMemory, CacheStrategy.InFile, CacheStrategy.AbsolutePath]
18
+ CacheStrategy.__empty_constructs__ = [CacheStrategy.None]
19
+
20
+ export const CacheDurability =
21
+ Register.global("$hxEnums")["whet.cache.CacheDurability"] =
22
+ {
23
+ __ename__: "whet.cache.CacheDurability",
24
+
25
+ KeepForever: {_hx_name: "KeepForever", _hx_index: 0, __enum__: "whet.cache.CacheDurability"},
26
+ LimitCountByLastUse: Object.assign((count) => ({_hx_index: 1, __enum__: "whet.cache.CacheDurability", "count": count}), {_hx_name: "LimitCountByLastUse", __params__: ["count"]}),
27
+ LimitCountByAge: Object.assign((count) => ({_hx_index: 2, __enum__: "whet.cache.CacheDurability", "count": count}), {_hx_name: "LimitCountByAge", __params__: ["count"]}),
28
+ MaxAge: Object.assign((seconds) => ({_hx_index: 3, __enum__: "whet.cache.CacheDurability", "seconds": seconds}), {_hx_name: "MaxAge", __params__: ["seconds"]}),
29
+ Custom: Object.assign((keep) => ({_hx_index: 4, __enum__: "whet.cache.CacheDurability", "keep": keep}), {_hx_name: "Custom", __params__: ["keep"]}),
30
+ All: Object.assign((keepIfAll) => ({_hx_index: 5, __enum__: "whet.cache.CacheDurability", "keepIfAll": keepIfAll}), {_hx_name: "All", __params__: ["keepIfAll"]}),
31
+ Any: Object.assign((keepIfAny) => ({_hx_index: 6, __enum__: "whet.cache.CacheDurability", "keepIfAny": keepIfAny}), {_hx_name: "Any", __params__: ["keepIfAny"]})
32
+ }
33
+ CacheDurability.__constructs__ = [CacheDurability.KeepForever, CacheDurability.LimitCountByLastUse, CacheDurability.LimitCountByAge, CacheDurability.MaxAge, CacheDurability.Custom, CacheDurability.All, CacheDurability.Any]
34
+ CacheDurability.__empty_constructs__ = [CacheDurability.KeepForever]
35
+
36
+ export const DurabilityCheck =
37
+ Register.global("$hxEnums")["whet.cache.DurabilityCheck"] =
38
+ {
39
+ __ename__: "whet.cache.DurabilityCheck",
40
+
41
+ /**
42
+ Checks all cached sources for a stone, whenever the cache is used. The default.
43
+ */
44
+ AllOnUse: {_hx_name: "AllOnUse", _hx_index: 0, __enum__: "whet.cache.DurabilityCheck"},
45
+ /**
46
+ * Checks all cached sources for a stone, whenever any resource is being added to the cache.
47
+ * Improves performance, but can leave behind invalid files.
48
+ */
49
+ AllOnSet: {_hx_name: "AllOnSet", _hx_index: 1, __enum__: "whet.cache.DurabilityCheck"},
50
+ /**
51
+ * Checks just the cached source when receiving it. Useful for custom durability checks
52
+ * and situations where the hash isn't ensuring validity.
53
+ */
54
+ SingleOnGet: {_hx_name: "SingleOnGet", _hx_index: 2, __enum__: "whet.cache.DurabilityCheck"}
55
+ }
56
+ DurabilityCheck.__constructs__ = [DurabilityCheck.AllOnUse, DurabilityCheck.AllOnSet, DurabilityCheck.SingleOnGet]
57
+ DurabilityCheck.__empty_constructs__ = [DurabilityCheck.AllOnUse, DurabilityCheck.AllOnSet, DurabilityCheck.SingleOnGet]
@@ -0,0 +1,23 @@
1
+ import {MemoryCache} from "./MemoryCache"
2
+ import {FileCache} from "./FileCache"
3
+ import {CacheStrategy} from "./Cache"
4
+ import {AnyStone} from "../Stone"
5
+ import {SourceHash} from "../SourceHash"
6
+ import {Source} from "../Source"
7
+ import {Project} from "../Project"
8
+
9
+ export declare class CacheManager {
10
+ constructor(project: Project)
11
+ project: Project
12
+ defaultStrategy: CacheStrategy
13
+ protected memCache: MemoryCache
14
+ protected fileCache: FileCache
15
+ getSource(stone: AnyStone): Promise<Source>
16
+
17
+ /**
18
+ * Get valid directory to generate files in. The path is unique per stone based on caching rules.
19
+ * If hash is supplied, and a path was already assigned, the same path is returned, assuring consistency.
20
+ * The path is not reserved. Caching depends on stone's `cacheStrategy` and success of source generation.
21
+ */
22
+ getDir(stone: AnyStone, hash?: null | SourceHash): string
23
+ }
@@ -0,0 +1,103 @@
1
+ import {MemoryCache} from "./MemoryCache.js"
2
+ import {FileCache} from "./FileCache.js"
3
+ import {CacheStrategy, DurabilityCheck} from "./Cache.js"
4
+ import {RootDir, SourceId} from "../SourceId.js"
5
+ import {Log} from "../Log.js"
6
+ import {Path} from "../../haxe/io/Path.js"
7
+ import {Register} from "../../genes/Register.js"
8
+ import {HxOverrides} from "../../HxOverrides.js"
9
+
10
+ const $global = Register.$global
11
+
12
+ export const CacheManager = Register.global("$hxClasses")["whet.cache.CacheManager"] =
13
+ class CacheManager extends Register.inherits() {
14
+ new(project) {
15
+ this.fileCache = null;
16
+ this.memCache = null;
17
+ this.defaultStrategy = CacheStrategy.None;
18
+ this.project = project;
19
+ this.fileCache = new FileCache(RootDir.fromProject(project));
20
+ this.memCache = new MemoryCache(RootDir.fromProject(project));
21
+ }
22
+ getSource(stone) {
23
+ var e = stone.cacheStrategy;
24
+ Log.log(10, ...["Looking for cached value.", {"stone": stone, "strategy": Register.global("$hxEnums")[e.__enum__].__constructs__[e._hx_index]._hx_name}]);
25
+ var _g = stone.cacheStrategy;
26
+ switch (_g._hx_index) {
27
+ case 0:
28
+ return stone.generateHash().then(function (hash) {
29
+ return stone.generateSource(hash);
30
+ });
31
+ break
32
+ case 1:
33
+ var _g1 = _g.check;
34
+ return this.memCache.get(stone, _g.durability, (_g1 != null) ? _g1 : DurabilityCheck.AllOnUse);
35
+ break
36
+ case 2:
37
+ var _g1 = _g.check;
38
+ return this.fileCache.get(stone, _g.durability, (_g1 != null) ? _g1 : DurabilityCheck.AllOnUse);
39
+ break
40
+ case 3:
41
+ var _g1 = _g.check;
42
+ return this.fileCache.get(stone, _g.durability, (_g1 != null) ? _g1 : DurabilityCheck.AllOnUse);
43
+ break
44
+
45
+ };
46
+ }
47
+
48
+ /**
49
+ * Get valid directory to generate files in. The path is unique per stone based on caching rules.
50
+ * If hash is supplied, and a path was already assigned, the same path is returned, assuring consistency.
51
+ * The path is not reserved. Caching depends on stone's `cacheStrategy` and success of source generation.
52
+ */
53
+ getDir(stone, hash) {
54
+ var s = stone.id + "/";
55
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
56
+ var baseDir = (s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm;
57
+ var tmp;
58
+ switch (stone.cacheStrategy._hx_index) {
59
+ case 0:
60
+ tmp = true;
61
+ break
62
+ case 1:
63
+ tmp = true;
64
+ break
65
+ default:
66
+ tmp = false;
67
+
68
+ };
69
+ if (tmp) {
70
+ var norm = "/" + Path.normalize((".temp/".charAt(0) == "/") ? HxOverrides.substr(".temp/", 1, null) : ".temp/");
71
+ baseDir = SourceId.getPutInDir(baseDir, (".temp/".lastIndexOf("/") == ".temp/".length - 1) ? Path.addTrailingSlash(norm) : norm);
72
+ };
73
+ var norm = "/" + Path.normalize((".whet/".charAt(0) == "/") ? HxOverrides.substr(".whet/", 1, null) : ".whet/");
74
+ baseDir = SourceId.getPutInDir(baseDir, (".whet/".lastIndexOf("/") == ".whet/".length - 1) ? Path.addTrailingSlash(norm) : norm);
75
+ var id;
76
+ var _g = stone.cacheStrategy;
77
+ switch (_g._hx_index) {
78
+ case 0:
79
+ id = baseDir;
80
+ break
81
+ case 1:
82
+ id = this.memCache.getUniqueDir(stone, baseDir, hash);
83
+ break
84
+ case 2:
85
+ id = this.fileCache.getUniqueDir(stone, baseDir, hash);
86
+ break
87
+ case 3:
88
+ var s = Path.addTrailingSlash(Path.directory(_g.path));
89
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
90
+ id = (s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm;
91
+ break
92
+
93
+ };
94
+ return id;
95
+ }
96
+ static get __name__() {
97
+ return "whet.cache.CacheManager"
98
+ }
99
+ get __class__() {
100
+ return CacheManager
101
+ }
102
+ }
103
+
@@ -0,0 +1,35 @@
1
+ import {BaseCache} from "./BaseCache"
2
+ import {AnyStone} from "../Stone"
3
+ import {SourceHash} from "../SourceHash"
4
+ import {Source} from "../Source"
5
+
6
+ export declare class FileCache extends BaseCache<string, RuntimeFileCacheValue> {
7
+ constructor(rootDir: string)
8
+ protected dbFile: string
9
+ protected flushQueued: boolean
10
+ protected key(stone: AnyStone): string
11
+ protected value(source: Source): Promise<RuntimeFileCacheValue>
12
+ protected source(stone: AnyStone, value: RuntimeFileCacheValue): Promise<Source>
13
+ protected set(source: Source): Promise<RuntimeFileCacheValue>
14
+ protected getExistingDirs(stone: AnyStone): string[]
15
+ protected remove(stone: AnyStone, value: RuntimeFileCacheValue): Promise<any>
16
+ protected setRecentUseOrder(values: RuntimeFileCacheValue[], value: RuntimeFileCacheValue): boolean
17
+ protected getDirFor(value: RuntimeFileCacheValue): string
18
+ protected flush(): void
19
+ }
20
+
21
+ export type FileCacheValue<H, S> = {
22
+ baseDir: S,
23
+ ctime: number,
24
+ ctimePretty?: null | string,
25
+ files: {
26
+ fileHash: H,
27
+ filePath: S,
28
+ id: S
29
+ }[],
30
+ hash: H
31
+ }
32
+
33
+ export type DbJson = {[key: string]: FileCacheValue<string, string>[]}
34
+
35
+ export type RuntimeFileCacheValue = FileCacheValue<SourceHash, string>