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,295 @@
1
+ import {BaseCache} from "./BaseCache.js"
2
+ import {Utils} from "../Utils.js"
3
+ import {SourceHash} from "../SourceHash.js"
4
+ import {SourceData, Source} from "../Source.js"
5
+ import {Log} from "../Log.js"
6
+ import {Path} from "../../haxe/io/Path.js"
7
+ import {StringMap} from "../../haxe/ds/StringMap.js"
8
+ import {Register} from "../../genes/Register.js"
9
+ import * as Fs from "fs"
10
+ import {Reflect as Reflect__1} from "../../Reflect.js"
11
+ import {Lambda} from "../../Lambda.js"
12
+ import {HxOverrides} from "../../HxOverrides.js"
13
+
14
+ const $global = Register.$global
15
+
16
+ export const FileCache = Register.global("$hxClasses")["whet.cache.FileCache"] =
17
+ class FileCache extends Register.inherits(BaseCache) {
18
+ new(rootDir) {
19
+ this.flushQueued = false;
20
+ super.new(rootDir, new StringMap());
21
+ var norm = "/" + Path.normalize((".whet/cache.json".charAt(0) == "/") ? HxOverrides.substr(".whet/cache.json", 1, null) : ".whet/cache.json");
22
+ var this1 = (".whet/cache.json".lastIndexOf("/") == ".whet/cache.json".length - 1) ? Path.addTrailingSlash(norm) : norm;
23
+ this.dbFile = (rootDir.length == 1) ? this1.substring(1) : rootDir.substring(1, rootDir.length - 1) + this1;
24
+ try {
25
+ var db = JSON.parse(Fs.readFileSync(this.dbFile, {"encoding": "utf-8"}));
26
+ var _g_keys = Reflect__1.fields(db);
27
+ var _g_index = 0;
28
+ while (_g_index < _g_keys.length) {
29
+ var key = _g_keys[_g_index++];
30
+ var _g1_value = db[key];
31
+ var this1 = this.cache;
32
+ var _g = [];
33
+ var _g1 = 0;
34
+ while (_g1 < _g1_value.length) {
35
+ var val = _g1_value[_g1];
36
+ ++_g1;
37
+ var tmp = SourceHash.fromHex(val.hash);
38
+ var val1 = val.ctime;
39
+ var s = val.baseDir;
40
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
41
+ var tmp1 = (s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm;
42
+ var _g2 = [];
43
+ var _g3 = 0;
44
+ var _g4 = val.files;
45
+ while (_g3 < _g4.length) {
46
+ var file = _g4[_g3];
47
+ ++_g3;
48
+ var tmp2 = SourceHash.fromHex(file.fileHash);
49
+ var s1 = file.filePath;
50
+ var norm1 = "/" + Path.normalize((s1.charAt(0) == "/") ? HxOverrides.substr(s1, 1, null) : s1);
51
+ var tmp3 = (s1.lastIndexOf("/") == s1.length - 1) ? Path.addTrailingSlash(norm1) : norm1;
52
+ var s2 = file.id;
53
+ var norm2 = "/" + Path.normalize((s2.charAt(0) == "/") ? HxOverrides.substr(s2, 1, null) : s2);
54
+ _g2.push({"fileHash": tmp2, "filePath": tmp3, "id": (s2.lastIndexOf("/") == s2.length - 1) ? Path.addTrailingSlash(norm2) : norm2});
55
+ };
56
+ _g.push({"hash": tmp, "ctime": val1, "baseDir": tmp1, "files": _g2});
57
+ };
58
+ this1.inst.set(key, _g);
59
+ };
60
+ }catch (_g) {
61
+ };
62
+ }
63
+ key(stone) {
64
+ return stone.id;
65
+ }
66
+ value(source) {
67
+ var idOverride;
68
+ var _g = source.origin.cacheStrategy;
69
+ if (_g._hx_index == 3) {
70
+ if (source.data.length == 1) {
71
+ var s = Path.withoutDirectory(_g.path);
72
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
73
+ idOverride = (s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm;
74
+ } else {
75
+ idOverride = null;
76
+ };
77
+ } else {
78
+ idOverride = null;
79
+ };
80
+ var _g = [];
81
+ var _g1 = 0;
82
+ var _g2 = source.data;
83
+ while (_g1 < _g2.length) {
84
+ var data = [_g2[_g1]];
85
+ ++_g1;
86
+ _g.push(data[0].getFilePathId(idOverride).then((function (data) {
87
+ return function (filePath) {
88
+ return {"fileHash": SourceHash.fromBytes(data[0].data), "filePath": filePath, "id": data[0].id};
89
+ };
90
+ })(data)));
91
+ };
92
+ return Promise.all(_g).then(function (files) {
93
+ return {"hash": source.hash, "ctime": source.ctime, "baseDir": source.getDirPath(), "ctimePretty": null, "files": files};
94
+ });
95
+ }
96
+ source(stone, value) {
97
+ var _gthis = this;
98
+ var _g = stone.cacheStrategy;
99
+ if (_g._hx_index == 3) {
100
+ var _g1 = _g.path;
101
+ var invalidPath;
102
+ if (value.files.length == 1) {
103
+ invalidPath = value.files[0].filePath != _g1;
104
+ } else {
105
+ var value1 = value.baseDir;
106
+ var s = Path.addTrailingSlash(Path.directory(_g1));
107
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
108
+ invalidPath = value1 != ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm);
109
+ };
110
+ if (invalidPath) {
111
+ return Promise.resolve(null);
112
+ };
113
+ };
114
+ var _g = [];
115
+ var _g1 = 0;
116
+ var _g2 = value.files;
117
+ while (_g1 < _g2.length) _g.push(new Promise((function (file) {
118
+ return function (res, rej) {
119
+ var this1 = file[0].filePath;
120
+ var root = _gthis.rootDir;
121
+ SourceData.fromFile(file[0].id, (root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1, file[0].filePath).then((function (file) {
122
+ return function (sourceData) {
123
+ if (sourceData == null || !stone.ignoreFileHash && !SourceHash.equals(sourceData.hash, file[0].fileHash)) {
124
+ rej("Wrong hash.");
125
+ } else {
126
+ res(sourceData);
127
+ };
128
+ };
129
+ })(file));
130
+ };
131
+ })([_g2[_g1++]])));
132
+ return Promise.all(_g).then(function (data) {
133
+ return new Source(data, value.hash, stone, value.ctime);
134
+ }, function (rejected) {
135
+ if (rejected == "Wrong hash.") {
136
+ return null;
137
+ } else {
138
+ throw rejected;
139
+ return null;
140
+ };
141
+ });
142
+ }
143
+ set(source) {
144
+ var _gthis = this;
145
+ return super.set(source).then(function (vals) {
146
+ _gthis.flush();
147
+ return vals;
148
+ });
149
+ }
150
+ getExistingDirs(stone) {
151
+ var list = this.cache.inst.get(stone.id);
152
+ if (list != null) {
153
+ var result = new Array(list.length);
154
+ var _g = 0;
155
+ var _g1 = list.length;
156
+ while (_g < _g1) {
157
+ var i = _g++;
158
+ result[i] = list[i].baseDir;
159
+ };
160
+ return result;
161
+ } else {
162
+ return null;
163
+ };
164
+ }
165
+ remove(stone, value) {
166
+ var _gthis = this;
167
+ Log.log(20, ...["Removing stone from file cache.", {"stone": stone, "valueHash": SourceHash.toHex(value.hash)}]);
168
+ var isAlone = Lambda.count(this.cache.inst.get(stone.id), function (v) {
169
+ return v.baseDir == value.baseDir;
170
+ }) == 1;
171
+ return super.remove(stone, value).then(function (_) {
172
+ _gthis.flush();
173
+ if (!isAlone) {
174
+ return Promise.resolve(null);
175
+ } else {
176
+ var _g = [];
177
+ var _g1 = 0;
178
+ var _g2 = value.files;
179
+ while (_g1 < _g2.length) _g.push(new Promise((function (file) {
180
+ return function (res, rej) {
181
+ var this1 = file[0].filePath;
182
+ var root = _gthis.rootDir;
183
+ Log.log(20, ...["Deleting file.", {"path": (root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1}]);
184
+ var this1 = file[0].filePath;
185
+ var root = _gthis.rootDir;
186
+ Fs.unlink((root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1, (function () {
187
+ return function (err) {
188
+ if (err != null) {
189
+ Log.log(50, ...[err]);
190
+ };
191
+ res(null);
192
+ };
193
+ })());
194
+ };
195
+ })([_g2[_g1++]])));
196
+ return Promise.all(_g);
197
+ };
198
+ }).then(function (_) {
199
+ return new Promise(function (res, rej) {
200
+ var this1 = value.baseDir;
201
+ var root = _gthis.rootDir;
202
+ Fs.readdir((root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1, function (err, files) {
203
+ if (err != null) {
204
+ Log.log(50, ...[err]);
205
+ res(null);
206
+ } else if (files.length == 0) {
207
+ var this1 = value.baseDir;
208
+ var root = _gthis.rootDir;
209
+ Fs.rmdir((root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1, function (err) {
210
+ if (err != null) {
211
+ Log.log(50, ...[err]);
212
+ };
213
+ res(null);
214
+ });
215
+ } else {
216
+ res(null);
217
+ };
218
+ });
219
+ });
220
+ });
221
+ }
222
+ setRecentUseOrder(values, value) {
223
+ var changed = super.setRecentUseOrder(values, value);
224
+ if (changed) {
225
+ this.flush();
226
+ };
227
+ return changed;
228
+ }
229
+ getDirFor(value) {
230
+ return value.baseDir;
231
+ }
232
+ flush() {
233
+ var _gthis = this;
234
+ if (this.flushQueued) {
235
+ return;
236
+ };
237
+ this.flushQueued = true;
238
+ global.setTimeout(function () {
239
+ _gthis.flushQueued = false;
240
+ var db = {};
241
+ var this1 = _gthis.cache;
242
+ var _g_keys = this1.keys();
243
+ while (_g_keys.hasNext()) {
244
+ var key = _g_keys.next();
245
+ var _g1_value = this1.get(key);
246
+ var _g = [];
247
+ var _g1 = 0;
248
+ while (_g1 < _g1_value.length) {
249
+ var val = _g1_value[_g1];
250
+ ++_g1;
251
+ var tmp = SourceHash.toHex(val.hash);
252
+ var val1 = val.ctime;
253
+ var tmp1 = HxOverrides.dateStr(new Date(val.ctime * 1000));
254
+ var this2 = val.baseDir;
255
+ var norm = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
256
+ var root = ("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm) : norm;
257
+ var tmp2 = (root.length == 1) ? this2.substring(1) : root.substring(1, root.length - 1) + this2;
258
+ var _g2 = [];
259
+ var _g3 = 0;
260
+ var _g4 = val.files;
261
+ while (_g3 < _g4.length) {
262
+ var file = _g4[_g3];
263
+ ++_g3;
264
+ var tmp3 = SourceHash.toHex(file.fileHash);
265
+ var this3 = file.filePath;
266
+ var norm1 = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
267
+ var root1 = ("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm1) : norm1;
268
+ var tmp4 = (root1.length == 1) ? this3.substring(1) : root1.substring(1, root1.length - 1) + this3;
269
+ var this4 = file.id;
270
+ var norm2 = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
271
+ var root2 = ("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm2) : norm2;
272
+ _g2.push({"fileHash": tmp3, "filePath": tmp4, "id": (root2.length == 1) ? this4.substring(1) : root2.substring(1, root2.length - 1) + this4});
273
+ };
274
+ _g.push({"hash": tmp, "ctime": val1, "ctimePretty": tmp1, "baseDir": tmp2, "files": _g2});
275
+ };
276
+ db[key] = _g;
277
+ };
278
+ Utils.saveContent(_gthis.dbFile, JSON.stringify(db, null, "\t")).then(function (_) {
279
+ Log.log(10, ...["FileCache DB saved."]);
280
+ }, function (err) {
281
+ Log.log(50, ...["FileCache DB save error.", err]);
282
+ });
283
+ }, 100);
284
+ }
285
+ static get __name__() {
286
+ return "whet.cache.FileCache"
287
+ }
288
+ static get __super__() {
289
+ return BaseCache
290
+ }
291
+ get __class__() {
292
+ return FileCache
293
+ }
294
+ }
295
+
@@ -0,0 +1,12 @@
1
+ import {BaseCache} from "./BaseCache"
2
+ import {AnyStone} from "../Stone"
3
+ import {Source} from "../Source"
4
+
5
+ export declare class MemoryCache extends BaseCache<AnyStone, Source> {
6
+ constructor(rootDir: string)
7
+ protected key(stone: AnyStone): AnyStone
8
+ protected value(source: Source): Promise<Source>
9
+ protected source(stone: AnyStone, value: Source): Promise<Source>
10
+ protected getExistingDirs(stone: AnyStone): string[]
11
+ protected getDirFor(value: Source): string
12
+ }
@@ -0,0 +1,58 @@
1
+ import {BaseCache} from "./BaseCache.js"
2
+ import {ObjectMap} from "../../haxe/ds/ObjectMap.js"
3
+ import {Register} from "../../genes/Register.js"
4
+
5
+ const $global = Register.$global
6
+
7
+ export const MemoryCache = Register.global("$hxClasses")["whet.cache.MemoryCache"] =
8
+ class MemoryCache extends Register.inherits(BaseCache) {
9
+ new(rootDir) {
10
+ super.new(rootDir, new ObjectMap());
11
+ }
12
+ key(stone) {
13
+ return stone;
14
+ }
15
+ value(source) {
16
+ return Promise.resolve(source);
17
+ }
18
+ source(stone, value) {
19
+ return Promise.resolve(value);
20
+ }
21
+ getExistingDirs(stone) {
22
+ var list = this.cache.inst.get(stone);
23
+ if (list != null) {
24
+ var result = new Array(list.length);
25
+ var _g = 0;
26
+ var _g1 = list.length;
27
+ while (_g < _g1) {
28
+ var i = _g++;
29
+ result[i] = list[i].tryDirPath();
30
+ };
31
+ var _g = [];
32
+ var _g1 = 0;
33
+ while (_g1 < result.length) {
34
+ var v = result[_g1];
35
+ ++_g1;
36
+ if (v != null) {
37
+ _g.push(v);
38
+ };
39
+ };
40
+ return _g;
41
+ } else {
42
+ return null;
43
+ };
44
+ }
45
+ getDirFor(value) {
46
+ return value.tryDirPath();
47
+ }
48
+ static get __name__() {
49
+ return "whet.cache.MemoryCache"
50
+ }
51
+ static get __super__() {
52
+ return BaseCache
53
+ }
54
+ get __class__() {
55
+ return MemoryCache
56
+ }
57
+ }
58
+
@@ -0,0 +1,4 @@
1
+
2
+ export type MaybeArray<T> = T | T[]
3
+
4
+ export const makeArray: <T>(maybe: MaybeArray<T>) => T[]
@@ -0,0 +1,25 @@
1
+ import {Register} from "../../genes/Register.js"
2
+
3
+ const $global = Register.$global
4
+
5
+ export const MaybeArray_Fields_ = Register.global("$hxClasses")["whet.magic._MaybeArray.MaybeArray_Fields_"] =
6
+ class MaybeArray_Fields_ {
7
+ static makeArray(maybe) {
8
+ if (((maybe) instanceof Array)) {
9
+ return maybe;
10
+ } else if (maybe == null) {
11
+ return [];
12
+ } else {
13
+ return [maybe];
14
+ };
15
+ }
16
+ static get __name__() {
17
+ return "whet.magic._MaybeArray.MaybeArray_Fields_"
18
+ }
19
+ get __class__() {
20
+ return MaybeArray_Fields_
21
+ }
22
+ }
23
+
24
+
25
+ export const makeArray = MaybeArray_Fields_.makeArray
@@ -0,0 +1,9 @@
1
+ import {Router, RoutePath} from "../route/Router"
2
+ import {BaseRouteType} from "./RouteType"
3
+
4
+ /**
5
+ * Anything that can be transformed into `Route`.
6
+ */
7
+ export type RoutePathType = Router | BaseRouteType[][]
8
+
9
+ export const makeRoutePath: (routerPathType: RoutePathType) => RoutePath[]
@@ -0,0 +1,48 @@
1
+ import {Router} from "../route/Router.js"
2
+ import {RouteType_Fields_} from "./RouteType.js"
3
+ import {Path} from "../../haxe/io/Path.js"
4
+ import {Register} from "../../genes/Register.js"
5
+ import {HxOverrides} from "../../HxOverrides.js"
6
+
7
+ const $global = Register.$global
8
+
9
+ export const RoutePathType_Fields_ = Register.global("$hxClasses")["whet.magic._RoutePathType.RoutePathType_Fields_"] =
10
+ class RoutePathType_Fields_ {
11
+ static makeRoutePath(routerPathType) {
12
+ if (((routerPathType) instanceof Router)) {
13
+ return routerPathType.routes;
14
+ };
15
+ if (!((routerPathType) instanceof Array)) {
16
+ throw new Error("RoutePath should be an array.");
17
+ };
18
+ var _g = [];
19
+ var _g1 = 0;
20
+ var _g2 = routerPathType;
21
+ while (_g1 < _g2.length) {
22
+ var item = _g2[_g1];
23
+ ++_g1;
24
+ if (!((item) instanceof Array)) {
25
+ throw new Error("RoutePath element should be an array.");
26
+ };
27
+ if (item.length < 2) {
28
+ throw new Error("RoutePath element should have at least 2 entries `[serveId, route]`.");
29
+ };
30
+ if (item.length > 3) {
31
+ throw new Error("RoutePath element should have at most 3 entries `[serveId, route, serveAs]`.");
32
+ };
33
+ var s = item[0];
34
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
35
+ _g.push({"routeUnder": (s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm, "route": RouteType_Fields_.makeRoute([item.slice(1)])});
36
+ };
37
+ return _g;
38
+ }
39
+ static get __name__() {
40
+ return "whet.magic._RoutePathType.RoutePathType_Fields_"
41
+ }
42
+ get __class__() {
43
+ return RoutePathType_Fields_
44
+ }
45
+ }
46
+
47
+
48
+ export const makeRoutePath = RoutePathType_Fields_.makeRoutePath
@@ -0,0 +1,12 @@
1
+ import {Route} from "../route/Route"
2
+ import {MaybeArray} from "./MaybeArray"
3
+ import {AnyStone} from "../Stone"
4
+
5
+ /**
6
+ * Anything that can be transformed into `Route`.
7
+ */
8
+ export type RouteType = MaybeArray<MaybeArray<BaseRouteType>>
9
+
10
+ export type BaseRouteType = string | AnyStone
11
+
12
+ export const makeRoute: (routeType: RouteType) => Route
@@ -0,0 +1,70 @@
1
+ import {Files} from "../stones/Files.js"
2
+ import {Route} from "../route/Route.js"
3
+ import {MaybeArray_Fields_} from "./MaybeArray.js"
4
+ import {Stone} from "../Stone.js"
5
+ import {SourceId} from "../SourceId.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 RouteType_Fields_ = Register.global("$hxClasses")["whet.magic._RouteType.RouteType_Fields_"] =
13
+ class RouteType_Fields_ {
14
+ static makeRoute(routeType) {
15
+ var _g = [];
16
+ var _g1 = 0;
17
+ var _g2 = MaybeArray_Fields_.makeArray(routeType);
18
+ while (_g1 < _g2.length) {
19
+ var tinner = MaybeArray_Fields_.makeArray(_g2[_g1++]);
20
+ if (tinner.length == 1) {
21
+ _g.push(RouteType_Fields_.getRoute(tinner[0]));
22
+ } else if (tinner.length == 2) {
23
+ if (typeof(tinner[1]) != "string") {
24
+ throw new Error("Array-defined route's second element should be path (a string).");
25
+ };
26
+ var tinner1 = tinner[0];
27
+ var s = tinner[1];
28
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
29
+ _g.push(RouteType_Fields_.getRoute(tinner1, (s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm));
30
+ };
31
+ };
32
+ return new Route(_g);
33
+ }
34
+ static getRoute(t, path) {
35
+ if (typeof(t) == "string") {
36
+ var tmp = new Files({"paths": [t]});
37
+ var tmp1;
38
+ if (path != null) {
39
+ tmp1 = path;
40
+ } else {
41
+ var norm = "/" + Path.normalize((t.charAt(0) == "/") ? HxOverrides.substr(t, 1, null) : t);
42
+ var p = (t.lastIndexOf("/") == t.length - 1) ? Path.addTrailingSlash(norm) : norm;
43
+ var s = Path.addTrailingSlash(Path.directory(p));
44
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
45
+ tmp1 = SourceId.relativeTo(p, (s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm);
46
+ };
47
+ return {"stone": tmp, "path": tmp1};
48
+ } else if (((t) instanceof Stone)) {
49
+ var tmp;
50
+ if (path != null) {
51
+ tmp = path;
52
+ } else {
53
+ var norm = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
54
+ tmp = ("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm) : norm;
55
+ };
56
+ return {"stone": t, "path": tmp};
57
+ } else {
58
+ throw new Error("Unsupported type for Route.");
59
+ };
60
+ }
61
+ static get __name__() {
62
+ return "whet.magic._RouteType.RouteType_Fields_"
63
+ }
64
+ get __class__() {
65
+ return RouteType_Fields_
66
+ }
67
+ }
68
+
69
+
70
+ export const makeRoute = RouteType_Fields_.makeRoute
@@ -0,0 +1,5 @@
1
+ import {AnyStone} from "../Stone"
2
+
3
+ export type StoneIdType = string | any | AnyStone
4
+
5
+ export const makeStoneId: (id: StoneIdType) => string
@@ -0,0 +1,32 @@
1
+ import {Stone} from "../Stone.js"
2
+ import {Boot} from "../../js/Boot.js"
3
+ import {Register} from "../../genes/Register.js"
4
+
5
+ const $global = Register.$global
6
+
7
+ export const StoneId_Fields_ = Register.global("$hxClasses")["whet.magic._StoneId.StoneId_Fields_"] =
8
+ class StoneId_Fields_ {
9
+ static makeStoneId(id) {
10
+ if (typeof(id) == "string") {
11
+ return id;
12
+ } else if (Boot.__instanceof(id, "$hxCoreType__Class")) {
13
+ return StoneId_Fields_.makeStoneIdFromClass(id);
14
+ } else if (((id) instanceof Stone)) {
15
+ return StoneId_Fields_.makeStoneIdFromClass(Boot.getClass(id));
16
+ } else {
17
+ throw new Error("Unsupported type for StoneId.");
18
+ };
19
+ }
20
+ static makeStoneIdFromClass(c) {
21
+ return c.__name__.split(".").pop();
22
+ }
23
+ static get __name__() {
24
+ return "whet.magic._StoneId.StoneId_Fields_"
25
+ }
26
+ get __class__() {
27
+ return StoneId_Fields_
28
+ }
29
+ }
30
+
31
+
32
+ export const makeStoneId = StoneId_Fields_.makeStoneId
@@ -0,0 +1,15 @@
1
+ import {RouteResult} from "./RouteResult"
2
+ import {AnyStone} from "../Stone"
3
+ import {SourceData} from "../Source"
4
+
5
+ export declare class Route {
6
+ constructor(routes: RouteData[])
7
+ protected routes: RouteData[]
8
+ list(): Promise<RouteResult[]>
9
+ getData(): Promise<SourceData[]>
10
+ }
11
+
12
+ export type RouteData = {
13
+ path: string,
14
+ stone: AnyStone
15
+ }
@@ -0,0 +1,81 @@
1
+ import {RouteResult} from "./RouteResult.js"
2
+ import {Path} from "../../haxe/io/Path.js"
3
+ import {Register} from "../../genes/Register.js"
4
+ import {HxOverrides} from "../../HxOverrides.js"
5
+
6
+ const $global = Register.$global
7
+
8
+ export const Route = Register.global("$hxClasses")["whet.route.Route"] =
9
+ class Route extends Register.inherits() {
10
+ new(routes) {
11
+ this.routes = routes;
12
+ }
13
+ list() {
14
+ var _g = [];
15
+ var _g1 = 0;
16
+ var _g2 = this.routes;
17
+ while (_g1 < _g2.length) {
18
+ var r = [_g2[_g1]];
19
+ ++_g1;
20
+ _g.push(r[0].stone.list().then((function (r) {
21
+ return function (list) {
22
+ var arr = [];
23
+ var this1 = r[0].path;
24
+ var norm = "/" + Path.normalize((this1.charAt(0) == "/") ? HxOverrides.substr(this1, 1, null) : this1);
25
+ var tmp = (this1.lastIndexOf("/") == this1.length - 1) ? Path.addTrailingSlash(norm) : norm;
26
+ var s = Path.addTrailingSlash(Path.directory(this1));
27
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
28
+ if (tmp == ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm)) {
29
+ var _g = 0;
30
+ while (_g < list.length) {
31
+ var path = list[_g];
32
+ ++_g;
33
+ arr.push(new RouteResult(path, path, r[0].stone));
34
+ };
35
+ } else {
36
+ var _g = 0;
37
+ while (_g < list.length) {
38
+ var path = list[_g];
39
+ ++_g;
40
+ if (path == r[0].path) {
41
+ var _g1 = r[0].stone;
42
+ var s = Path.withoutDirectory(path);
43
+ var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
44
+ arr.push(new RouteResult((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm, path, _g1));
45
+ };
46
+ };
47
+ };
48
+ return arr;
49
+ };
50
+ })(r)));
51
+ };
52
+ return Promise.all(_g).then(function (data) {
53
+ var _g = [];
54
+ var _g_current = 0;
55
+ while (_g_current < data.length) {
56
+ var x = Register.iter(data[_g_current++]);
57
+ while (x.hasNext()) _g.push(x.next());
58
+ };
59
+ return _g;
60
+ });
61
+ }
62
+ getData() {
63
+ return this.list().then(function (l) {
64
+ var result = new Array(l.length);
65
+ var _g = 0;
66
+ var _g1 = l.length;
67
+ while (_g < _g1) {
68
+ var i = _g++;
69
+ result[i] = l[i].get();
70
+ };
71
+ return Promise.all(result);
72
+ });
73
+ }
74
+ static get __name__() {
75
+ return "whet.route.Route"
76
+ }
77
+ get __class__() {
78
+ return Route
79
+ }
80
+ }
81
+