whet 0.0.3 → 0.0.6

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 (44) hide show
  1. package/bin/StringBuf.d.ts +13 -0
  2. package/bin/StringBuf.js +25 -0
  3. package/bin/haxe/CallStack.d.ts +41 -0
  4. package/bin/haxe/CallStack.js +96 -0
  5. package/bin/haxe/Log.d.ts +33 -0
  6. package/bin/haxe/Log.js +61 -0
  7. package/bin/haxe/NativeStackTrace.js +147 -0
  8. package/bin/whet/Log.js +3 -0
  9. package/bin/whet/Project.d.ts +1 -0
  10. package/bin/whet/Project.js +13 -8
  11. package/bin/whet/Source.d.ts +2 -2
  12. package/bin/whet/Source.js +20 -5
  13. package/bin/whet/SourceHash.d.ts +8 -1
  14. package/bin/whet/SourceHash.js +105 -7
  15. package/bin/whet/SourceId.d.ts +1 -0
  16. package/bin/whet/SourceId.js +37 -28
  17. package/bin/whet/Stone.d.ts +12 -2
  18. package/bin/whet/Stone.js +25 -13
  19. package/bin/whet/Utils.d.ts +8 -1
  20. package/bin/whet/Utils.js +56 -3
  21. package/bin/whet/Whet.js +5 -1
  22. package/bin/whet/cache/BaseCache.js +23 -20
  23. package/bin/whet/cache/CacheManager.d.ts +5 -0
  24. package/bin/whet/cache/CacheManager.js +22 -14
  25. package/bin/whet/cache/FileCache.js +89 -35
  26. package/bin/whet/magic/RoutePathType.js +10 -5
  27. package/bin/whet/magic/RouteType.d.ts +2 -2
  28. package/bin/whet/magic/RouteType.js +28 -14
  29. package/bin/whet/magic/StoneId.d.ts +1 -0
  30. package/bin/whet/magic/StoneId.js +11 -1
  31. package/bin/whet/route/Route.d.ts +5 -1
  32. package/bin/whet/route/Route.js +33 -14
  33. package/bin/whet/route/Router.js +27 -37
  34. package/bin/whet/stones/Files.js +25 -17
  35. package/bin/whet/stones/JsonStone.js +7 -7
  36. package/bin/whet/stones/RemoteFile.js +5 -8
  37. package/bin/whet/stones/Server.js +28 -19
  38. package/bin/whet/stones/Zip.js +17 -12
  39. package/bin/whet/stones/haxe/HaxeBuild.d.ts +3 -0
  40. package/bin/whet/stones/haxe/HaxeBuild.js +58 -16
  41. package/bin/whet/stones/haxe/Hxml.js +56 -34
  42. package/bin/whet.d.ts +2 -0
  43. package/bin/whet.js +2 -0
  44. package/package.json +1 -1
@@ -1,17 +1,18 @@
1
1
  import {MemoryCache} from "./MemoryCache.js"
2
2
  import {FileCache} from "./FileCache.js"
3
- import {CacheStrategy, DurabilityCheck} from "./Cache.js"
4
- import {RootDir, SourceId} from "../SourceId.js"
3
+ import {CacheStrategy, CacheDurability, DurabilityCheck} from "./Cache.js"
4
+ import {RootDir, SourceId_Fields_, SourceId} from "../SourceId.js"
5
5
  import {Log} from "../Log.js"
6
- import {Path} from "../../haxe/io/Path.js"
6
+ import * as Path from "path"
7
7
  import {Register} from "../../genes/Register.js"
8
- import {HxOverrides} from "../../HxOverrides.js"
8
+ import {StringTools} from "../../StringTools.js"
9
9
 
10
10
  const $global = Register.$global
11
11
 
12
12
  export const CacheManager = Register.global("$hxClasses")["whet.cache.CacheManager"] =
13
13
  class CacheManager extends Register.inherits() {
14
14
  new(project) {
15
+ this.defaultFileStrategy = CacheStrategy.InFile(CacheDurability.Any([CacheDurability.LimitCountByLastUse(1), CacheDurability.All([CacheDurability.MaxAge(86400), CacheDurability.LimitCountByLastUse(5)])]), DurabilityCheck.AllOnUse);
15
16
  this.fileCache = null;
16
17
  this.memCache = null;
17
18
  this.defaultStrategy = CacheStrategy.None;
@@ -21,7 +22,7 @@ class CacheManager extends Register.inherits() {
21
22
  }
22
23
  getSource(stone) {
23
24
  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
+ Log.log(10, ...["Determining cache status.", {"stone": stone, "strategy": Register.global("$hxEnums")[e.__enum__].__constructs__[e._hx_index]._hx_name}]);
25
26
  var _g = stone.cacheStrategy;
26
27
  switch (_g._hx_index) {
27
28
  case 0:
@@ -52,8 +53,9 @@ class CacheManager extends Register.inherits() {
52
53
  */
53
54
  getDir(stone, hash) {
54
55
  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;
56
+ s = Path.posix.normalize(s);
57
+ s = StringTools.replace(s, "\\", "/");
58
+ var baseDir = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
57
59
  var tmp;
58
60
  switch (stone.cacheStrategy._hx_index) {
59
61
  case 0:
@@ -67,11 +69,15 @@ class CacheManager extends Register.inherits() {
67
69
 
68
70
  };
69
71
  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
+ var s = ".temp/";
73
+ s = Path.posix.normalize(".temp/");
74
+ s = StringTools.replace(s, "\\", "/");
75
+ baseDir = SourceId.getPutInDir(baseDir, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
72
76
  };
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);
77
+ var s = ".whet/";
78
+ s = Path.posix.normalize(".whet/");
79
+ s = StringTools.replace(s, "\\", "/");
80
+ baseDir = SourceId.getPutInDir(baseDir, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
75
81
  var id;
76
82
  var _g = stone.cacheStrategy;
77
83
  switch (_g._hx_index) {
@@ -85,9 +91,11 @@ class CacheManager extends Register.inherits() {
85
91
  id = this.fileCache.getUniqueDir(stone, baseDir, hash);
86
92
  break
87
93
  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;
94
+ var _g1 = _g.path;
95
+ var s = _g1.substring(0, _g1.lastIndexOf("/") + 1);
96
+ s = Path.posix.normalize(s);
97
+ s = StringTools.replace(s, "\\", "/");
98
+ id = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
91
99
  break
92
100
 
93
101
  };
@@ -1,12 +1,14 @@
1
1
  import {BaseCache} from "./BaseCache.js"
2
2
  import {Utils} from "../Utils.js"
3
+ import {SourceId_Fields_} from "../SourceId.js"
3
4
  import {SourceHash} from "../SourceHash.js"
4
5
  import {SourceData, Source} from "../Source.js"
5
6
  import {Log} from "../Log.js"
6
- import {Path} from "../../haxe/io/Path.js"
7
+ import * as Path from "path"
7
8
  import {StringMap} from "../../haxe/ds/StringMap.js"
8
9
  import {Register} from "../../genes/Register.js"
9
10
  import * as Fs from "fs"
11
+ import {StringTools} from "../../StringTools.js"
10
12
  import {Reflect as Reflect__1} from "../../Reflect.js"
11
13
  import {Lambda} from "../../Lambda.js"
12
14
  import {HxOverrides} from "../../HxOverrides.js"
@@ -18,9 +20,14 @@ class FileCache extends Register.inherits(BaseCache) {
18
20
  new(rootDir) {
19
21
  this.flushQueued = false;
20
22
  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;
23
+ var s = ".whet/cache.json";
24
+ s = Path.posix.normalize(".whet/cache.json");
25
+ s = StringTools.replace(s, "\\", "/");
26
+ var this1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
27
+ if (this1.charAt(0) != "/") {
28
+ throw new Error("Badly formed SourceId.");
29
+ };
30
+ this.dbFile = Path.posix.join(".", rootDir, ".", this1);
24
31
  try {
25
32
  var db = JSON.parse(Fs.readFileSync(this.dbFile, {"encoding": "utf-8"}));
26
33
  var _g_keys = Reflect__1.fields(db);
@@ -37,8 +44,9 @@ class FileCache extends Register.inherits(BaseCache) {
37
44
  var tmp = SourceHash.fromHex(val.hash);
38
45
  var val1 = val.ctime;
39
46
  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;
47
+ s = Path.posix.normalize(s);
48
+ s = StringTools.replace(s, "\\", "/");
49
+ var tmp1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
42
50
  var _g2 = [];
43
51
  var _g3 = 0;
44
52
  var _g4 = val.files;
@@ -47,11 +55,13 @@ class FileCache extends Register.inherits(BaseCache) {
47
55
  ++_g3;
48
56
  var tmp2 = SourceHash.fromHex(file.fileHash);
49
57
  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;
58
+ s1 = Path.posix.normalize(s1);
59
+ s1 = StringTools.replace(s1, "\\", "/");
60
+ var tmp3 = (SourceId_Fields_.startsWithSlash(s1)) ? s1 : "/" + s1;
52
61
  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});
62
+ s2 = Path.posix.normalize(s2);
63
+ s2 = StringTools.replace(s2, "\\", "/");
64
+ _g2.push({"fileHash": tmp2, "filePath": tmp3, "id": (SourceId_Fields_.startsWithSlash(s2)) ? s2 : "/" + s2});
55
65
  };
56
66
  _g.push({"hash": tmp, "ctime": val1, "baseDir": tmp1, "files": _g2});
57
67
  };
@@ -67,10 +77,12 @@ class FileCache extends Register.inherits(BaseCache) {
67
77
  var idOverride;
68
78
  var _g = source.origin.cacheStrategy;
69
79
  if (_g._hx_index == 3) {
80
+ var _g1 = _g.path;
70
81
  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;
82
+ var s = _g1.substring(_g1.lastIndexOf("/"));
83
+ s = Path.posix.normalize(s);
84
+ s = StringTools.replace(s, "\\", "/");
85
+ idOverride = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
74
86
  } else {
75
87
  idOverride = null;
76
88
  };
@@ -99,13 +111,14 @@ class FileCache extends Register.inherits(BaseCache) {
99
111
  if (_g._hx_index == 3) {
100
112
  var _g1 = _g.path;
101
113
  var invalidPath;
102
- if (value.files.length == 1) {
114
+ if (value.files.length == 1 && !SourceId_Fields_.endsWithSlash(_g1)) {
103
115
  invalidPath = value.files[0].filePath != _g1;
104
116
  } else {
105
117
  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);
118
+ var s = _g1.substring(0, _g1.lastIndexOf("/") + 1);
119
+ s = Path.posix.normalize(s);
120
+ s = StringTools.replace(s, "\\", "/");
121
+ invalidPath = value1 != ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
109
122
  };
110
123
  if (invalidPath) {
111
124
  return Promise.resolve(null);
@@ -118,7 +131,11 @@ class FileCache extends Register.inherits(BaseCache) {
118
131
  return function (res, rej) {
119
132
  var this1 = file[0].filePath;
120
133
  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) {
134
+ if (this1.charAt(0) != "/") {
135
+ throw new Error("Badly formed SourceId.");
136
+ };
137
+ var path = Path.posix.join(".", root, ".", this1);
138
+ SourceData.fromFile(file[0].id, path, file[0].filePath).then((function (file) {
122
139
  return function (sourceData) {
123
140
  if (sourceData == null || !stone.ignoreFileHash && !SourceHash.equals(sourceData.hash, file[0].fileHash)) {
124
141
  rej("Wrong hash.");
@@ -180,17 +197,23 @@ class FileCache extends Register.inherits(BaseCache) {
180
197
  return function (res, rej) {
181
198
  var this1 = file[0].filePath;
182
199
  var root = _gthis.rootDir;
183
- Log.log(20, ...["Deleting file.", {"path": (root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1}]);
200
+ if (this1.charAt(0) != "/") {
201
+ throw new Error("Badly formed SourceId.");
202
+ };
203
+ Log.log(20, ...["Deleting file.", {"path": Path.posix.join(".", root, ".", this1)}]);
184
204
  var this1 = file[0].filePath;
185
205
  var root = _gthis.rootDir;
186
- Fs.unlink((root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1, (function () {
206
+ if (this1.charAt(0) != "/") {
207
+ throw new Error("Badly formed SourceId.");
208
+ };
209
+ Fs.unlink(Path.posix.join(".", root, ".", this1), (function (file) {
187
210
  return function (err) {
188
211
  if (err != null) {
189
- Log.log(50, ...[err]);
212
+ Log.log(50, ...["Error deleting file.", {"file": file[0], "error": err}]);
190
213
  };
191
214
  res(null);
192
215
  };
193
- })());
216
+ })(file));
194
217
  };
195
218
  })([_g2[_g1++]])));
196
219
  return Promise.all(_g);
@@ -199,16 +222,32 @@ class FileCache extends Register.inherits(BaseCache) {
199
222
  return new Promise(function (res, rej) {
200
223
  var this1 = value.baseDir;
201
224
  var root = _gthis.rootDir;
202
- Fs.readdir((root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1, function (err, files) {
225
+ if (this1.charAt(0) != "/") {
226
+ throw new Error("Badly formed SourceId.");
227
+ };
228
+ Fs.readdir(Path.posix.join(".", root, ".", this1), function (err, files) {
203
229
  if (err != null) {
204
- Log.log(50, ...[err]);
230
+ var this1 = value.baseDir;
231
+ var root = _gthis.rootDir;
232
+ if (this1.charAt(0) != "/") {
233
+ throw new Error("Badly formed SourceId.");
234
+ };
235
+ Log.log(50, ...["Error reading directory", {"dir": Path.posix.join(".", root, ".", this1), "error": err}]);
205
236
  res(null);
206
237
  } else if (files.length == 0) {
207
238
  var this1 = value.baseDir;
208
239
  var root = _gthis.rootDir;
209
- Fs.rmdir((root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1, function (err) {
240
+ if (this1.charAt(0) != "/") {
241
+ throw new Error("Badly formed SourceId.");
242
+ };
243
+ Fs.rmdir(Path.posix.join(".", root, ".", this1), function (err) {
210
244
  if (err != null) {
211
- Log.log(50, ...[err]);
245
+ var this1 = value.baseDir;
246
+ var root = _gthis.rootDir;
247
+ if (this1.charAt(0) != "/") {
248
+ throw new Error("Badly formed SourceId.");
249
+ };
250
+ Log.log(50, ...["Error removing directory.", {"dir": Path.posix.join(".", root, ".", this1), "error": err}]);
212
251
  };
213
252
  res(null);
214
253
  });
@@ -252,9 +291,14 @@ class FileCache extends Register.inherits(BaseCache) {
252
291
  var val1 = val.ctime;
253
292
  var tmp1 = HxOverrides.dateStr(new Date(val.ctime * 1000));
254
293
  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;
294
+ var s = "/";
295
+ s = Path.posix.normalize("/");
296
+ s = StringTools.replace(s, "\\", "/");
297
+ var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
298
+ if (this2.charAt(0) != "/") {
299
+ throw new Error("Badly formed SourceId.");
300
+ };
301
+ var tmp2 = Path.posix.join(".", root, ".", this2);
258
302
  var _g2 = [];
259
303
  var _g3 = 0;
260
304
  var _g4 = val.files;
@@ -263,13 +307,23 @@ class FileCache extends Register.inherits(BaseCache) {
263
307
  ++_g3;
264
308
  var tmp3 = SourceHash.toHex(file.fileHash);
265
309
  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;
310
+ var s1 = "/";
311
+ s1 = Path.posix.normalize("/");
312
+ s1 = StringTools.replace(s1, "\\", "/");
313
+ var root1 = (SourceId_Fields_.startsWithSlash(s1)) ? s1 : "/" + s1;
314
+ if (this3.charAt(0) != "/") {
315
+ throw new Error("Badly formed SourceId.");
316
+ };
317
+ var tmp4 = Path.posix.join(".", root1, ".", this3);
269
318
  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});
319
+ var s2 = "/";
320
+ s2 = Path.posix.normalize("/");
321
+ s2 = StringTools.replace(s2, "\\", "/");
322
+ var root2 = (SourceId_Fields_.startsWithSlash(s2)) ? s2 : "/" + s2;
323
+ if (this4.charAt(0) != "/") {
324
+ throw new Error("Badly formed SourceId.");
325
+ };
326
+ _g2.push({"fileHash": tmp3, "filePath": tmp4, "id": Path.posix.join(".", root2, ".", this4)});
273
327
  };
274
328
  _g.push({"hash": tmp, "ctime": val1, "ctimePretty": tmp1, "baseDir": tmp2, "files": _g2});
275
329
  };
@@ -1,8 +1,10 @@
1
1
  import {Router} from "../route/Router.js"
2
+ import {Route} from "../route/Route.js"
2
3
  import {RouteType_Fields_} from "./RouteType.js"
3
- import {Path} from "../../haxe/io/Path.js"
4
+ import {SourceId_Fields_} from "../SourceId.js"
5
+ import * as Path from "path"
4
6
  import {Register} from "../../genes/Register.js"
5
- import {HxOverrides} from "../../HxOverrides.js"
7
+ import {StringTools} from "../../StringTools.js"
6
8
 
7
9
  const $global = Register.$global
8
10
 
@@ -28,11 +30,14 @@ class RoutePathType_Fields_ {
28
30
  throw new Error("RoutePath element should have at least 2 entries `[serveId, route]`.");
29
31
  };
30
32
  if (item.length > 3) {
31
- throw new Error("RoutePath element should have at most 3 entries `[serveId, route, serveAs]`.");
33
+ throw new Error("RoutePath element should have at most 3 entries `[serveId, route, filter]`.");
32
34
  };
33
35
  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
+ s = Path.posix.normalize(s);
37
+ s = StringTools.replace(s, "\\", "/");
38
+ var tmp = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
39
+ var _g3 = item.slice(1);
40
+ _g.push({"routeUnder": tmp, "route": (_g3.length == 1) ? (((item[1]) instanceof Route)) ? item[1] : RouteType_Fields_.makeRoute([_g3]) : RouteType_Fields_.makeRoute([_g3])});
36
41
  };
37
42
  return _g;
38
43
  }
@@ -1,11 +1,11 @@
1
- import {Route} from "../route/Route"
1
+ import {Route, RouteData} from "../route/Route"
2
2
  import {MaybeArray} from "./MaybeArray"
3
3
  import {AnyStone} from "../Stone"
4
4
 
5
5
  /**
6
6
  * Anything that can be transformed into `Route`.
7
7
  */
8
- export type RouteType = MaybeArray<MaybeArray<BaseRouteType>>
8
+ export type RouteType = Route | MaybeArray<MaybeArray<BaseRouteType>>
9
9
 
10
10
  export type BaseRouteType = string | AnyStone
11
11
 
@@ -2,16 +2,24 @@ import {Files} from "../stones/Files.js"
2
2
  import {Route} from "../route/Route.js"
3
3
  import {MaybeArray_Fields_} from "./MaybeArray.js"
4
4
  import {Stone} from "../Stone.js"
5
- import {SourceId} from "../SourceId.js"
6
- import {Path} from "../../haxe/io/Path.js"
5
+ import {SourceId_Fields_, SourceId} from "../SourceId.js"
6
+ import * as Path from "path"
7
7
  import {Register} from "../../genes/Register.js"
8
- import {HxOverrides} from "../../HxOverrides.js"
8
+ import {StringTools} from "../../StringTools.js"
9
+ import {Std} from "../../Std.js"
9
10
 
10
11
  const $global = Register.$global
11
12
 
12
13
  export const RouteType_Fields_ = Register.global("$hxClasses")["whet.magic._RouteType.RouteType_Fields_"] =
13
14
  class RouteType_Fields_ {
14
15
  static makeRoute(routeType) {
16
+ if (((routeType) instanceof Route)) {
17
+ return routeType;
18
+ } else {
19
+ return new Route(routeType);
20
+ };
21
+ }
22
+ static makeRouteRoutes(routeType) {
15
23
  var _g = [];
16
24
  var _g1 = 0;
17
25
  var _g2 = MaybeArray_Fields_.makeArray(routeType);
@@ -25,11 +33,12 @@ class RouteType_Fields_ {
25
33
  };
26
34
  var tinner1 = tinner[0];
27
35
  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));
36
+ s = Path.posix.normalize(s);
37
+ s = StringTools.replace(s, "\\", "/");
38
+ _g.push(RouteType_Fields_.getRoute(tinner1, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s));
30
39
  };
31
40
  };
32
- return new Route(_g);
41
+ return _g;
33
42
  }
34
43
  static getRoute(t, path) {
35
44
  if (typeof(t) == "string") {
@@ -38,11 +47,14 @@ class RouteType_Fields_ {
38
47
  if (path != null) {
39
48
  tmp1 = path;
40
49
  } 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);
50
+ var s = t;
51
+ s = Path.posix.normalize(s);
52
+ s = StringTools.replace(s, "\\", "/");
53
+ var p = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
54
+ var s = p.substring(0, p.lastIndexOf("/") + 1);
55
+ s = Path.posix.normalize(s);
56
+ s = StringTools.replace(s, "\\", "/");
57
+ tmp1 = SourceId.relativeTo(p, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
46
58
  };
47
59
  return {"stone": tmp, "path": tmp1};
48
60
  } else if (((t) instanceof Stone)) {
@@ -50,12 +62,14 @@ class RouteType_Fields_ {
50
62
  if (path != null) {
51
63
  tmp = path;
52
64
  } else {
53
- var norm = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
54
- tmp = ("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm) : norm;
65
+ var s = "/";
66
+ s = Path.posix.normalize("/");
67
+ s = StringTools.replace(s, "\\", "/");
68
+ tmp = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
55
69
  };
56
70
  return {"stone": t, "path": tmp};
57
71
  } else {
58
- throw new Error("Unsupported type for Route.");
72
+ throw new Error("Unsupported type for Route. Expected String or Stone, but got " + Std.string(t.constructor?.name) + ".");
59
73
  };
60
74
  }
61
75
  static get __name__() {
@@ -3,3 +3,4 @@ import {AnyStone} from "../Stone"
3
3
  export type StoneIdType = string | any | AnyStone
4
4
 
5
5
  export const makeStoneId: (id: StoneIdType) => string
6
+ export const getTypeName: (stone: AnyStone) => string
@@ -12,7 +12,7 @@ class StoneId_Fields_ {
12
12
  } else if (Boot.__instanceof(id, "$hxCoreType__Class")) {
13
13
  return StoneId_Fields_.makeStoneIdFromClass(id);
14
14
  } else if (((id) instanceof Stone)) {
15
- return StoneId_Fields_.makeStoneIdFromClass(Boot.getClass(id));
15
+ return id.constructor.name;
16
16
  } else {
17
17
  throw new Error("Unsupported type for StoneId.");
18
18
  };
@@ -20,6 +20,15 @@ class StoneId_Fields_ {
20
20
  static makeStoneIdFromClass(c) {
21
21
  return c.__name__.split(".").pop();
22
22
  }
23
+ static getTypeName(stone) {
24
+ var c = Boot.getClass(stone);
25
+ var name = c.__name__;
26
+ if (name != "whet.Stone") {
27
+ return name;
28
+ } else {
29
+ return stone.constructor.name;
30
+ };
31
+ }
23
32
  static get __name__() {
24
33
  return "whet.magic._StoneId.StoneId_Fields_"
25
34
  }
@@ -30,3 +39,4 @@ class StoneId_Fields_ {
30
39
 
31
40
 
32
41
  export const makeStoneId = StoneId_Fields_.makeStoneId
42
+ export const getTypeName = StoneId_Fields_.getTypeName
@@ -1,10 +1,14 @@
1
1
  import {RouteResult} from "./RouteResult"
2
+ import {RouteType} from "../magic/RouteType"
2
3
  import {AnyStone} from "../Stone"
4
+ import {SourceHash} from "../SourceHash"
3
5
  import {SourceData} from "../Source"
4
6
 
5
7
  export declare class Route {
6
- constructor(routes: RouteData[])
8
+ constructor(route: RouteType)
7
9
  protected routes: RouteData[]
10
+ add(r: RouteType): Route
11
+ getHash(): Promise<SourceHash>
8
12
  list(): Promise<RouteResult[]>
9
13
  getData(): Promise<SourceData[]>
10
14
  }
@@ -1,14 +1,36 @@
1
1
  import {RouteResult} from "./RouteResult.js"
2
- import {Path} from "../../haxe/io/Path.js"
2
+ import {RouteType_Fields_} from "../magic/RouteType.js"
3
+ import {SourceId_Fields_, SourceId} from "../SourceId.js"
4
+ import {SourceHash} from "../SourceHash.js"
5
+ import * as Path from "path"
3
6
  import {Register} from "../../genes/Register.js"
4
- import {HxOverrides} from "../../HxOverrides.js"
7
+ import {StringTools} from "../../StringTools.js"
5
8
 
6
9
  const $global = Register.$global
7
10
 
8
11
  export const Route = Register.global("$hxClasses")["whet.route.Route"] =
9
12
  class Route extends Register.inherits() {
10
- new(routes) {
11
- this.routes = routes;
13
+ new(route) {
14
+ this.routes = (((route) instanceof Route)) ? route.routes.slice() : RouteType_Fields_.makeRouteRoutes(route);
15
+ }
16
+ add(r) {
17
+ var _g = 0;
18
+ var _g1 = RouteType_Fields_.makeRoute(r).routes;
19
+ while (_g < _g1.length) this.routes.push(_g1[_g++]);
20
+ return this;
21
+ }
22
+ getHash() {
23
+ var _this = this.routes;
24
+ var result = new Array(_this.length);
25
+ var _g = 0;
26
+ var _g1 = _this.length;
27
+ while (_g < _g1) {
28
+ var i = _g++;
29
+ result[i] = _this[i].stone.getHash();
30
+ };
31
+ return Promise.all(result).then(function (hashes) {
32
+ return SourceHash.merge(...hashes);
33
+ });
12
34
  }
13
35
  list() {
14
36
  var _g = [];
@@ -20,17 +42,13 @@ class Route extends Register.inherits() {
20
42
  _g.push(r[0].stone.list().then((function (r) {
21
43
  return function (list) {
22
44
  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)) {
45
+ if (SourceId_Fields_.endsWithSlash(r[0].path)) {
29
46
  var _g = 0;
30
47
  while (_g < list.length) {
31
48
  var path = list[_g];
32
49
  ++_g;
33
- arr.push(new RouteResult(path, path, r[0].stone));
50
+ var _g1 = r[0].stone;
51
+ arr.push(new RouteResult(SourceId.relativeTo(path, r[0].path), path, _g1));
34
52
  };
35
53
  } else {
36
54
  var _g = 0;
@@ -39,9 +57,10 @@ class Route extends Register.inherits() {
39
57
  ++_g;
40
58
  if (path == r[0].path) {
41
59
  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));
60
+ var s = path.substring(path.lastIndexOf("/"));
61
+ s = Path.posix.normalize(s);
62
+ s = StringTools.replace(s, "\\", "/");
63
+ arr.push(new RouteResult((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, path, _g1));
45
64
  };
46
65
  };
47
66
  };