whet 0.0.5 → 0.0.8

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 (43) 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/NativeStackTrace.js +147 -0
  6. package/bin/whet/Log.js +3 -0
  7. package/bin/whet/Project.d.ts +5 -2
  8. package/bin/whet/Project.js +32 -9
  9. package/bin/whet/Source.d.ts +2 -2
  10. package/bin/whet/Source.js +21 -5
  11. package/bin/whet/SourceHash.d.ts +7 -1
  12. package/bin/whet/SourceHash.js +93 -7
  13. package/bin/whet/SourceId.d.ts +1 -0
  14. package/bin/whet/SourceId.js +37 -28
  15. package/bin/whet/Stone.d.ts +21 -5
  16. package/bin/whet/Stone.js +63 -18
  17. package/bin/whet/Utils.d.ts +8 -2
  18. package/bin/whet/Utils.js +25 -5
  19. package/bin/whet/Whet.js +4 -1
  20. package/bin/whet/cache/BaseCache.js +18 -17
  21. package/bin/whet/cache/CacheManager.d.ts +5 -0
  22. package/bin/whet/cache/CacheManager.js +21 -12
  23. package/bin/whet/cache/FileCache.js +83 -43
  24. package/bin/whet/magic/RoutePathType.js +10 -4
  25. package/bin/whet/magic/RouteType.d.ts +4 -3
  26. package/bin/whet/magic/RouteType.js +31 -13
  27. package/bin/whet/magic/StoneId.d.ts +1 -0
  28. package/bin/whet/magic/StoneId.js +11 -1
  29. package/bin/whet/route/Route.d.ts +5 -1
  30. package/bin/whet/route/Route.js +33 -13
  31. package/bin/whet/route/Router.js +27 -36
  32. package/bin/whet/stones/Files.js +25 -16
  33. package/bin/whet/stones/JsonStone.js +7 -6
  34. package/bin/whet/stones/RemoteFile.js +5 -7
  35. package/bin/whet/stones/Server.d.ts +1 -2
  36. package/bin/whet/stones/Server.js +29 -22
  37. package/bin/whet/stones/Zip.js +17 -11
  38. package/bin/whet/stones/haxe/HaxeBuild.d.ts +2 -2
  39. package/bin/whet/stones/haxe/HaxeBuild.js +42 -69
  40. package/bin/whet/stones/haxe/Hxml.js +39 -24
  41. package/bin/whet.d.ts +3 -0
  42. package/bin/whet.js +3 -0
  43. package/package.json +1 -1
@@ -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".length > 1 && SourceId_Fields_.startsWithSlash(".whet/cache.json")) ? HxOverrides.substr(".whet/cache.json", 1, null) : ".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.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : 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.length > 1 && SourceId_Fields_.startsWithSlash(s1)) ? HxOverrides.substr(s1, 1, null) : 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.length > 1 && SourceId_Fields_.startsWithSlash(s2)) ? HxOverrides.substr(s2, 1, null) : 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.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
84
+ s = StringTools.replace(s, "\\", "/");
85
+ idOverride = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
74
86
  } else {
75
87
  idOverride = null;
76
88
  };
@@ -99,23 +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
- var invalidPath1;
103
- if (value.files.length == 1) {
104
- var norm = "/" + Path.normalize((_g1.charAt(0) == "/") ? HxOverrides.substr(_g1, 1, null) : _g1);
105
- var invalidPath2 = (_g1.lastIndexOf("/") == _g1.length - 1) ? Path.addTrailingSlash(norm) : norm;
106
- var s = Path.addTrailingSlash(Path.directory(_g1));
107
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
108
- invalidPath1 = invalidPath2 != ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm);
109
- } else {
110
- invalidPath1 = false;
111
- };
112
- if (invalidPath1) {
114
+ if (value.files.length == 1 && !SourceId_Fields_.endsWithSlash(_g1)) {
113
115
  invalidPath = value.files[0].filePath != _g1;
114
116
  } else {
115
117
  var value1 = value.baseDir;
116
- var s = Path.addTrailingSlash(Path.directory(_g1));
117
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
118
- 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.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
120
+ s = StringTools.replace(s, "\\", "/");
121
+ invalidPath = value1 != ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
119
122
  };
120
123
  if (invalidPath) {
121
124
  return Promise.resolve(null);
@@ -128,7 +131,11 @@ class FileCache extends Register.inherits(BaseCache) {
128
131
  return function (res, rej) {
129
132
  var this1 = file[0].filePath;
130
133
  var root = _gthis.rootDir;
131
- 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) {
132
139
  return function (sourceData) {
133
140
  if (sourceData == null || !stone.ignoreFileHash && !SourceHash.equals(sourceData.hash, file[0].fileHash)) {
134
141
  rej("Wrong hash.");
@@ -190,10 +197,16 @@ class FileCache extends Register.inherits(BaseCache) {
190
197
  return function (res, rej) {
191
198
  var this1 = file[0].filePath;
192
199
  var root = _gthis.rootDir;
193
- 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)}]);
194
204
  var this1 = file[0].filePath;
195
205
  var root = _gthis.rootDir;
196
- Fs.unlink((root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1, (function (file) {
206
+ if (this1.charAt(0) != "/") {
207
+ throw new Error("Badly formed SourceId.");
208
+ };
209
+ Fs.unlink(Path.posix.join(".", root, ".", this1), (function (file) {
197
210
  return function (err) {
198
211
  if (err != null) {
199
212
  Log.log(50, ...["Error deleting file.", {"file": file[0], "error": err}]);
@@ -209,20 +222,32 @@ class FileCache extends Register.inherits(BaseCache) {
209
222
  return new Promise(function (res, rej) {
210
223
  var this1 = value.baseDir;
211
224
  var root = _gthis.rootDir;
212
- 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) {
213
229
  if (err != null) {
214
230
  var this1 = value.baseDir;
215
231
  var root = _gthis.rootDir;
216
- Log.log(50, ...["Error reading directory", {"dir": (root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1, "error": err}]);
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}]);
217
236
  res(null);
218
237
  } else if (files.length == 0) {
219
238
  var this1 = value.baseDir;
220
239
  var root = _gthis.rootDir;
221
- 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) {
222
244
  if (err != null) {
223
245
  var this1 = value.baseDir;
224
246
  var root = _gthis.rootDir;
225
- Log.log(50, ...["Error removing directory.", {"dir": (root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1, "error": err}]);
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}]);
226
251
  };
227
252
  res(null);
228
253
  });
@@ -266,9 +291,14 @@ class FileCache extends Register.inherits(BaseCache) {
266
291
  var val1 = val.ctime;
267
292
  var tmp1 = HxOverrides.dateStr(new Date(val.ctime * 1000));
268
293
  var this2 = val.baseDir;
269
- var norm = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
270
- var root = ("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm) : norm;
271
- var tmp2 = (root.length == 1) ? this2.substring(1) : root.substring(1, root.length - 1) + this2;
294
+ var s = "/";
295
+ s = Path.posix.normalize(("/".length > 1 && SourceId_Fields_.startsWithSlash("/")) ? HxOverrides.substr("/", 1, null) : "/");
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);
272
302
  var _g2 = [];
273
303
  var _g3 = 0;
274
304
  var _g4 = val.files;
@@ -277,13 +307,23 @@ class FileCache extends Register.inherits(BaseCache) {
277
307
  ++_g3;
278
308
  var tmp3 = SourceHash.toHex(file.fileHash);
279
309
  var this3 = file.filePath;
280
- var norm1 = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
281
- var root1 = ("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm1) : norm1;
282
- var tmp4 = (root1.length == 1) ? this3.substring(1) : root1.substring(1, root1.length - 1) + this3;
310
+ var s1 = "/";
311
+ s1 = Path.posix.normalize(("/".length > 1 && SourceId_Fields_.startsWithSlash("/")) ? HxOverrides.substr("/", 1, null) : "/");
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);
283
318
  var this4 = file.id;
284
- var norm2 = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
285
- var root2 = ("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm2) : norm2;
286
- _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(("/".length > 1 && SourceId_Fields_.startsWithSlash("/")) ? HxOverrides.substr("/", 1, null) : "/");
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)});
287
327
  };
288
328
  _g.push({"hash": tmp, "ctime": val1, "ctimePretty": tmp1, "baseDir": tmp2, "files": _g2});
289
329
  };
@@ -1,7 +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"
7
+ import {StringTools} from "../../StringTools.js"
5
8
  import {HxOverrides} from "../../HxOverrides.js"
6
9
 
7
10
  const $global = Register.$global
@@ -28,11 +31,14 @@ class RoutePathType_Fields_ {
28
31
  throw new Error("RoutePath element should have at least 2 entries `[serveId, route]`.");
29
32
  };
30
33
  if (item.length > 3) {
31
- throw new Error("RoutePath element should have at most 3 entries `[serveId, route, serveAs]`.");
34
+ throw new Error("RoutePath element should have at most 3 entries `[serveId, route, filter]`.");
32
35
  };
33
36
  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)])});
37
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
38
+ s = StringTools.replace(s, "\\", "/");
39
+ var tmp = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
40
+ var _g3 = item.slice(1);
41
+ _g.push({"routeUnder": tmp, "route": (_g3.length == 1) ? (((item[1]) instanceof Route)) ? item[1] : RouteType_Fields_.makeRoute([_g3]) : RouteType_Fields_.makeRoute([_g3])});
36
42
  };
37
43
  return _g;
38
44
  }
@@ -1,12 +1,13 @@
1
- import {Route} from "../route/Route"
1
+ import {RouteResult} from "../route/RouteResult"
2
+ import {Route, RouteData} from "../route/Route"
2
3
  import {MaybeArray} from "./MaybeArray"
3
4
  import {AnyStone} from "../Stone"
4
5
 
5
6
  /**
6
7
  * Anything that can be transformed into `Route`.
7
8
  */
8
- export type RouteType = MaybeArray<MaybeArray<BaseRouteType>>
9
+ export type RouteType = Route | MaybeArray<MaybeArray<BaseRouteType>>
9
10
 
10
- export type BaseRouteType = string | AnyStone
11
+ export type BaseRouteType = RouteResult | string | AnyStone
11
12
 
12
13
  export const makeRoute: (routeType: RouteType) => Route
@@ -1,10 +1,13 @@
1
1
  import {Files} from "../stones/Files.js"
2
+ import {RouteResult} from "../route/RouteResult.js"
2
3
  import {Route} from "../route/Route.js"
3
4
  import {MaybeArray_Fields_} from "./MaybeArray.js"
4
5
  import {Stone} from "../Stone.js"
5
- import {SourceId} from "../SourceId.js"
6
- import {Path} from "../../haxe/io/Path.js"
6
+ import {SourceId_Fields_, SourceId} from "../SourceId.js"
7
+ import * as Path from "path"
7
8
  import {Register} from "../../genes/Register.js"
9
+ import {StringTools} from "../../StringTools.js"
10
+ import {Std} from "../../Std.js"
8
11
  import {HxOverrides} from "../../HxOverrides.js"
9
12
 
10
13
  const $global = Register.$global
@@ -12,6 +15,13 @@ const $global = Register.$global
12
15
  export const RouteType_Fields_ = Register.global("$hxClasses")["whet.magic._RouteType.RouteType_Fields_"] =
13
16
  class RouteType_Fields_ {
14
17
  static makeRoute(routeType) {
18
+ if (((routeType) instanceof Route)) {
19
+ return routeType;
20
+ } else {
21
+ return new Route(routeType);
22
+ };
23
+ }
24
+ static makeRouteRoutes(routeType) {
15
25
  var _g = [];
16
26
  var _g1 = 0;
17
27
  var _g2 = MaybeArray_Fields_.makeArray(routeType);
@@ -25,11 +35,12 @@ class RouteType_Fields_ {
25
35
  };
26
36
  var tinner1 = tinner[0];
27
37
  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));
38
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
39
+ s = StringTools.replace(s, "\\", "/");
40
+ _g.push(RouteType_Fields_.getRoute(tinner1, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s));
30
41
  };
31
42
  };
32
- return new Route(_g);
43
+ return _g;
33
44
  }
34
45
  static getRoute(t, path) {
35
46
  if (typeof(t) == "string") {
@@ -38,11 +49,14 @@ class RouteType_Fields_ {
38
49
  if (path != null) {
39
50
  tmp1 = path;
40
51
  } 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);
52
+ var s = t;
53
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
54
+ s = StringTools.replace(s, "\\", "/");
55
+ var p = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
56
+ var s = p.substring(0, p.lastIndexOf("/") + 1);
57
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
58
+ s = StringTools.replace(s, "\\", "/");
59
+ tmp1 = SourceId.relativeTo(p, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
46
60
  };
47
61
  return {"stone": tmp, "path": tmp1};
48
62
  } else if (((t) instanceof Stone)) {
@@ -50,12 +64,16 @@ class RouteType_Fields_ {
50
64
  if (path != null) {
51
65
  tmp = path;
52
66
  } else {
53
- var norm = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
54
- tmp = ("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm) : norm;
67
+ var s = "/";
68
+ s = Path.posix.normalize(("/".length > 1 && SourceId_Fields_.startsWithSlash("/")) ? HxOverrides.substr("/", 1, null) : "/");
69
+ s = StringTools.replace(s, "\\", "/");
70
+ tmp = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
55
71
  };
56
72
  return {"stone": t, "path": tmp};
73
+ } else if (((t) instanceof RouteResult)) {
74
+ return {"stone": t.source, "path": t.sourceId};
57
75
  } else {
58
- throw new Error("Unsupported type for Route.");
76
+ throw new Error("Unsupported type for Route. Expected String, Stone or RouteResult, but got " + Std.string(t.constructor?.name) + ".");
59
77
  };
60
78
  }
61
79
  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,37 @@
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"
7
+ import {StringTools} from "../../StringTools.js"
4
8
  import {HxOverrides} from "../../HxOverrides.js"
5
9
 
6
10
  const $global = Register.$global
7
11
 
8
12
  export const Route = Register.global("$hxClasses")["whet.route.Route"] =
9
13
  class Route extends Register.inherits() {
10
- new(routes) {
11
- this.routes = routes;
14
+ new(route) {
15
+ this.routes = (((route) instanceof Route)) ? route.routes.slice() : RouteType_Fields_.makeRouteRoutes(route);
16
+ }
17
+ add(r) {
18
+ var _g = 0;
19
+ var _g1 = RouteType_Fields_.makeRoute(r).routes;
20
+ while (_g < _g1.length) this.routes.push(_g1[_g++]);
21
+ return this;
22
+ }
23
+ getHash() {
24
+ var _this = this.routes;
25
+ var result = new Array(_this.length);
26
+ var _g = 0;
27
+ var _g1 = _this.length;
28
+ while (_g < _g1) {
29
+ var i = _g++;
30
+ result[i] = _this[i].stone.getHash();
31
+ };
32
+ return Promise.all(result).then(function (hashes) {
33
+ return SourceHash.merge(...hashes);
34
+ });
12
35
  }
13
36
  list() {
14
37
  var _g = [];
@@ -20,17 +43,13 @@ class Route extends Register.inherits() {
20
43
  _g.push(r[0].stone.list().then((function (r) {
21
44
  return function (list) {
22
45
  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)) {
46
+ if (SourceId_Fields_.endsWithSlash(r[0].path)) {
29
47
  var _g = 0;
30
48
  while (_g < list.length) {
31
49
  var path = list[_g];
32
50
  ++_g;
33
- arr.push(new RouteResult(path, path, r[0].stone));
51
+ var _g1 = r[0].stone;
52
+ arr.push(new RouteResult(SourceId.relativeTo(path, r[0].path), path, _g1));
34
53
  };
35
54
  } else {
36
55
  var _g = 0;
@@ -39,9 +58,10 @@ class Route extends Register.inherits() {
39
58
  ++_g;
40
59
  if (path == r[0].path) {
41
60
  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));
61
+ var s = path.substring(path.lastIndexOf("/"));
62
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
63
+ s = StringTools.replace(s, "\\", "/");
64
+ arr.push(new RouteResult((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, path, _g1));
45
65
  };
46
66
  };
47
67
  };
@@ -1,10 +1,10 @@
1
1
  import {RoutePathType_Fields_} from "../magic/RoutePathType.js"
2
2
  import {Utils} from "../Utils.js"
3
- import {SourceId} from "../SourceId.js"
3
+ import {SourceId_Fields_, SourceId} from "../SourceId.js"
4
4
  import {SourceHash} from "../SourceHash.js"
5
- import * as Path__1 from "path"
6
- import {Path} from "../../haxe/io/Path.js"
5
+ import * as Path from "path"
7
6
  import {Register} from "../../genes/Register.js"
7
+ import {StringTools} from "../../StringTools.js"
8
8
  import {HxOverrides} from "../../HxOverrides.js"
9
9
 
10
10
  const $global = Register.$global
@@ -26,16 +26,13 @@ class Router extends Register.inherits() {
26
26
  */
27
27
  find(id, firstOnly) {
28
28
  var _gthis = this;
29
- var sourceId;
30
- var norm = "/" + Path.normalize((id.charAt(0) == "/") ? HxOverrides.substr(id, 1, null) : id);
31
- sourceId = (id.lastIndexOf("/") == id.length - 1) ? Path.addTrailingSlash(norm) : norm;
29
+ var s = id;
30
+ s = Path.posix.normalize((id.length > 1 && SourceId_Fields_.startsWithSlash(id)) ? HxOverrides.substr(id, 1, null) : id);
31
+ s = StringTools.replace(s, "\\", "/");
32
+ var sourceId = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
32
33
  return new Promise(function (res, rej) {
33
34
  if (firstOnly == null) {
34
- var norm = "/" + Path.normalize((sourceId.charAt(0) == "/") ? HxOverrides.substr(sourceId, 1, null) : sourceId);
35
- var firstOnly1 = (sourceId.lastIndexOf("/") == sourceId.length - 1) ? Path.addTrailingSlash(norm) : norm;
36
- var s = Path.addTrailingSlash(Path.directory(sourceId));
37
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
38
- firstOnly = firstOnly1 != ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm);
35
+ firstOnly = !SourceId_Fields_.endsWithSlash(sourceId);
39
36
  };
40
37
  var result = [];
41
38
  var _g = [];
@@ -46,31 +43,23 @@ class Router extends Register.inherits() {
46
43
  ++_g1;
47
44
  _g.push(path[0].route.list().then((function (path) {
48
45
  return function (list) {
49
- var this1 = path[0].routeUnder;
50
- var norm = "/" + Path.normalize((this1.charAt(0) == "/") ? HxOverrides.substr(this1, 1, null) : this1);
51
- var tmp = (this1.lastIndexOf("/") == this1.length - 1) ? Path.addTrailingSlash(norm) : norm;
52
- var s = Path.addTrailingSlash(Path.directory(this1));
53
- var norm = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
54
- if (tmp == ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm) : norm)) {
46
+ if (SourceId_Fields_.endsWithSlash(path[0].routeUnder)) {
55
47
  var _g = 0;
56
48
  while (_g < list.length) {
57
49
  var item = list[_g];
58
50
  ++_g;
59
51
  item.serveId = SourceId.getPutInDir(item.serveId, path[0].routeUnder);
60
- var norm = "/" + Path.normalize((sourceId.charAt(0) == "/") ? HxOverrides.substr(sourceId, 1, null) : sourceId);
61
- var tmp = (sourceId.lastIndexOf("/") == sourceId.length - 1) ? Path.addTrailingSlash(norm) : norm;
62
- var s = Path.addTrailingSlash(Path.directory(sourceId));
63
- var norm1 = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
64
- if (tmp == ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm1) : norm1)) {
52
+ if (SourceId_Fields_.endsWithSlash(sourceId)) {
65
53
  var rel = SourceId.relativeTo(item.serveId, sourceId);
66
54
  if (rel != null) {
67
55
  item.serveId = rel;
68
56
  result.push(item);
69
57
  };
70
58
  } else if (sourceId == item.serveId) {
71
- var s1 = Path.withoutDirectory(sourceId);
72
- var norm2 = "/" + Path.normalize((s1.charAt(0) == "/") ? HxOverrides.substr(s1, 1, null) : s1);
73
- item.serveId = (s1.lastIndexOf("/") == s1.length - 1) ? Path.addTrailingSlash(norm2) : norm2;
59
+ var s = sourceId.substring(sourceId.lastIndexOf("/"));
60
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
61
+ s = StringTools.replace(s, "\\", "/");
62
+ item.serveId = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
74
63
  result.push(item);
75
64
  };
76
65
  };
@@ -80,20 +69,17 @@ class Router extends Register.inherits() {
80
69
  var item = list[_g];
81
70
  ++_g;
82
71
  item.serveId = path[0].routeUnder;
83
- var norm = "/" + Path.normalize((sourceId.charAt(0) == "/") ? HxOverrides.substr(sourceId, 1, null) : sourceId);
84
- var tmp = (sourceId.lastIndexOf("/") == sourceId.length - 1) ? Path.addTrailingSlash(norm) : norm;
85
- var s = Path.addTrailingSlash(Path.directory(sourceId));
86
- var norm1 = "/" + Path.normalize((s.charAt(0) == "/") ? HxOverrides.substr(s, 1, null) : s);
87
- if (tmp == ((s.lastIndexOf("/") == s.length - 1) ? Path.addTrailingSlash(norm1) : norm1)) {
72
+ if (SourceId_Fields_.endsWithSlash(sourceId)) {
88
73
  var rel = SourceId.relativeTo(item.serveId, sourceId);
89
74
  if (rel != null) {
90
75
  item.serveId = rel;
91
76
  result.push(item);
92
77
  };
93
78
  } else if (sourceId == item.serveId) {
94
- var s1 = Path.withoutDirectory(sourceId);
95
- var norm2 = "/" + Path.normalize((s1.charAt(0) == "/") ? HxOverrides.substr(s1, 1, null) : s1);
96
- item.serveId = (s1.lastIndexOf("/") == s1.length - 1) ? Path.addTrailingSlash(norm2) : norm2;
79
+ var s = sourceId.substring(sourceId.lastIndexOf("/"));
80
+ s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
81
+ s = StringTools.replace(s, "\\", "/");
82
+ item.serveId = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
97
83
  result.push(item);
98
84
  };
99
85
  };
@@ -178,9 +164,14 @@ class Router extends Register.inherits() {
178
164
  ++_g1;
179
165
  var saveInto1 = saveInto;
180
166
  var this1 = r.serveId;
181
- var norm = "/" + Path.normalize(("/".charAt(0) == "/") ? HxOverrides.substr("/", 1, null) : "/");
182
- var root = ("/".lastIndexOf("/") == "/".length - 1) ? Path.addTrailingSlash(norm) : norm;
183
- var p = [Path__1.join(saveInto1, (root.length == 1) ? this1.substring(1) : root.substring(1, root.length - 1) + this1)];
167
+ var s = "/";
168
+ s = Path.posix.normalize(("/".length > 1 && SourceId_Fields_.startsWithSlash("/")) ? HxOverrides.substr("/", 1, null) : "/");
169
+ s = StringTools.replace(s, "\\", "/");
170
+ var root = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
171
+ if (this1.charAt(0) != "/") {
172
+ throw new Error("Badly formed SourceId.");
173
+ };
174
+ var p = [Path.join(saveInto1, Path.posix.join(".", root, ".", this1))];
184
175
  _g.push(r.get().then((function (p) {
185
176
  return function (src) {
186
177
  return Utils.saveBytes(p[0], src.data);