whet 0.1.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/bin/genes/util/EsMap.d.ts +1 -0
  2. package/bin/genes/util/EsMap.js +3 -0
  3. package/bin/haxe/Constraints.d.ts +1 -0
  4. package/bin/haxe/ds/IntMap.d.ts +6 -0
  5. package/bin/haxe/ds/IntMap.js +25 -0
  6. package/bin/haxe/ds/Vector.d.ts +2 -0
  7. package/bin/minimatch/MinimatchOptions.d.ts +28 -0
  8. package/bin/whet/Log.js +3 -0
  9. package/bin/whet/Project.d.ts +13 -0
  10. package/bin/whet/Project.js +26 -0
  11. package/bin/whet/Stone.d.ts +23 -0
  12. package/bin/whet/Stone.js +162 -7
  13. package/bin/whet/Whet.d.ts +1 -1
  14. package/bin/whet/Whet.js +68 -1
  15. package/bin/whet/cache/BaseCache.d.ts +7 -0
  16. package/bin/whet/cache/BaseCache.js +103 -7
  17. package/bin/whet/cache/CacheManager.d.ts +5 -0
  18. package/bin/whet/cache/CacheManager.js +97 -7
  19. package/bin/whet/cache/FileCache.d.ts +1 -0
  20. package/bin/whet/cache/FileCache.js +4 -0
  21. package/bin/whet/cache/MemoContext.d.ts +17 -0
  22. package/bin/whet/cache/MemoContext.js +35 -0
  23. package/bin/whet/magic/RoutePathType.js +5 -5
  24. package/bin/whet/profiler/Profiler.d.ts +65 -0
  25. package/bin/whet/profiler/Profiler.js +351 -0
  26. package/bin/whet/profiler/Span.d.ts +90 -0
  27. package/bin/whet/profiler/Span.js +56 -0
  28. package/bin/whet/profiler/SpanRecorder.d.ts +20 -0
  29. package/bin/whet/profiler/SpanRecorder.js +63 -0
  30. package/bin/whet/profiler/SpanStats.d.ts +15 -0
  31. package/bin/whet/profiler/SpanStats.js +49 -0
  32. package/bin/whet/route/Router.d.ts +5 -0
  33. package/bin/whet/route/Router.js +47 -33
  34. package/bin/whet/stones/Files.d.ts +5 -0
  35. package/bin/whet/stones/Files.js +20 -0
  36. package/bin/whet/stones/StoneFactory.d.ts +55 -0
  37. package/bin/whet/stones/StoneFactory.js +116 -0
  38. package/bin/whet.d.ts +2 -0
  39. package/bin/whet.js +1 -0
  40. package/package.json +2 -2
  41. package/bin/haxe/Log.d.ts +0 -33
  42. package/bin/haxe/Log.js +0 -61
  43. package/bin/pino_pretty/PrettyOptions.d.ts +0 -98
  44. package/bin/pino_pretty/default_/MessageFormatFunc.d.ts +0 -2
  45. package/bin/pino_pretty/default_/Prettifier.d.ts +0 -2
  46. package/bin/whet/extern/Minimatch.d.ts +0 -77
  47. package/bin/whet/stones/Server.d.ts +0 -59
  48. package/bin/whet/stones/Server.js +0 -261
@@ -1,59 +0,0 @@
1
- import {Router} from "../route/Router"
2
- import {StoneIdType} from "../magic/StoneId"
3
- import {MaybeArray} from "../magic/MaybeArray"
4
- import {CacheStrategy} from "../cache/Cache"
5
- import {Stone, AnyStone} from "../Stone"
6
- import {SourceHash} from "../SourceHash"
7
- import {SourceData} from "../Source"
8
- import {Project} from "../Project"
9
- import {IncomingMessage, ServerResponse} from "http"
10
-
11
- export declare class Server extends Stone<ServerConfig> {
12
- constructor(config: ServerConfig)
13
- readonly router: Router
14
- protected get_router(): Router
15
- routeDynamic: (arg0: string) => Promise<SourceData>
16
- protected generate(hash: SourceHash): Promise<SourceData[]>
17
-
18
- /**
19
- Starts a static server hosting attached resources.
20
- */
21
- serve(): void
22
- protected initConfig(): void
23
- protected addCommands(): void
24
- protected handler(req: IncomingMessage, res: ServerResponse): void
25
- }
26
-
27
- export type ServerConfig = {
28
- /**
29
- * Defaults to `project.cache.defaultStrategy`.
30
- * **Do not modify after initialization – it is ignored.**
31
- * After stone is initialized, change `stone.cacheStrategy` directly.
32
- */
33
- cacheStrategy?: null | CacheStrategy,
34
- /**
35
- * Registers another stone(s) as dependency of this one. Useful for external processes
36
- * that use a source of some stone, but don't go via Whet to get it.
37
- * Use with combination of `setAbsolutePath` on the dependency, so that the external process
38
- * can rely on a fixed path.
39
- * Will make sure the cached file is up to date when generating this stone.
40
- * Hash of the dependency is automatically combined with hash generated by this stone. There's no
41
- * need to add it manually.
42
- * Do not create cyclic dependencies!
43
- */
44
- dependencies?: null | MaybeArray<AnyStone>,
45
- headers?: null | {[key: string]: string},
46
- /**
47
- Defaults to the Stone's class name.
48
- */
49
- id?: null | StoneIdType,
50
- /**
51
- Defaults to 7000.
52
- */
53
- port: number,
54
- /**
55
- Defaults to the last instanced project.
56
- */
57
- project?: null | Project,
58
- router: Router
59
- }
@@ -1,261 +0,0 @@
1
- import {Whet_Fields_} from "../Whet.js"
2
- import {Stone} from "../Stone.js"
3
- import {Log} from "../Log.js"
4
- import * as Path from "path"
5
- import Mime from "mime"
6
- import * as Http from "http"
7
- import {Register} from "../../genes/Register.js"
8
- import {Std} from "../../Std.js"
9
- import {Reflect as Reflect__1} from "../../Reflect.js"
10
- import {Lambda} from "../../Lambda.js"
11
-
12
- const $global = Register.$global
13
-
14
- export const Server = Register.global("$hxClasses")["whet.stones.Server"] =
15
- class Server extends Register.inherits(Stone) {
16
- new(config) {
17
- this.routeDynamic = null;
18
- super.new(config);
19
- }
20
- get router() {
21
- return this.get_router()
22
- }
23
- get_router() {
24
- return this.config.router;
25
- }
26
- generate(hash) {
27
- throw new Error("Does not generate.");
28
- }
29
-
30
- /**
31
- Starts a static server hosting attached resources.
32
- */
33
- serve() {
34
- let server = Http.createServer(Register.bind(this, this.handler));
35
- let nextRetry = 500;
36
- let _gthis = this;
37
- server.on("error", function (err) {
38
- Log.log(50, ...["Failed to open a server. Retrying in " + nextRetry + "ms.", {"error": err}]);
39
- global.setTimeout(function () {
40
- server.listen(_gthis.config.port);
41
- }, nextRetry);
42
- nextRetry *= 2;
43
- return nextRetry;
44
- });
45
- server.listen(this.config.port, function () {
46
- Log.log(30, ...["Started web server.", {"port": _gthis.config.port}]);
47
- });
48
- }
49
- initConfig() {
50
- super.initConfig();
51
- if (this.config.port == null) {
52
- this.config.port = 7000;
53
- };
54
- }
55
- addCommands() {
56
- let _gthis = this;
57
- this.project.addCommand("serve", this).option("-p, --port <port>", "server port", "" + this.config.port).action(function (...args) {
58
- if (args[0].port != null) {
59
- _gthis.config.port = Std.parseInt(args[0].port);
60
- };
61
- _gthis.serve();
62
- return null;
63
- });
64
- }
65
- handler(req, res) {
66
- Log.log(30, ...["Handling request.", {"url": req.url, "method": req.method}]);
67
- let searchIndex = req.url.indexOf("?");
68
- let id = decodeURI((searchIndex > 0 ? req.url.substring(0,searchIndex) : req.url));
69
- if (id.charCodeAt(0) == 47) {
70
- id = id.substring(1);
71
- };
72
- let _gthis = this;
73
- switch (req.method) {
74
- case "GET":
75
- let isDirOrNoExt = id.length == 0 || id.charCodeAt(id.length - 1) == 47 || Path.posix.extname(id) == "";
76
- let queryPromise;
77
- if (isDirOrNoExt) {
78
- let searchPattern = id.length == 0 || id.charCodeAt(id.length - 1) == 47;
79
- queryPromise = this.config.router.get((searchPattern) ? id + "**" : id + "/**");
80
- } else {
81
- queryPromise = Promise.resolve([]);
82
- };
83
- queryPromise.then(function (dirResults) {
84
- if (isDirOrNoExt && dirResults.length == 1) {
85
- id = dirResults[0].serveId;
86
- } else if (isDirOrNoExt) {
87
- if (!req.url.substring(0, (searchIndex > 0) ? searchIndex : req.url.length).endsWith("/")) {
88
- let redirectUrl = (searchIndex > 0) ? req.url.substring(0, searchIndex) + "/" + req.url.substring(searchIndex) : req.url + "/";
89
- res.writeHead(301, "Moved Permanently", {"Location": redirectUrl});
90
- res.end();
91
- return;
92
- };
93
- if (id.length == 0 || id.charCodeAt(id.length - 1) == 47) {
94
- let id1 = id;
95
- let dir = id1.substring(0, id1.lastIndexOf("/") + 1);
96
- id = Path.posix.join((dir.length == 0) ? "./" : dir, "index.html");
97
- } else if (Path.posix.extname(id) == "") {
98
- id = "" + id + "/index.html";
99
- };
100
- };
101
- _gthis.config.router.get(id).then(function (routeResult) {
102
- let sourcePromise = (routeResult.length > 0) ? routeResult[0].get() : (_gthis.routeDynamic != null) ? _gthis.routeDynamic(id) : Promise.resolve(null);
103
- return sourcePromise.then(function (source) {
104
- if (source == null) {
105
- res.writeHead(404, "File not found.");
106
- res.end();
107
- return;
108
- };
109
- let headers = {"Content-Type": Mime.getType(Path.posix.extname(id).toLowerCase()), "Last-Modified": new Date(source.source.ctime * 1000).toUTCString(), "Content-Length": Std.string(source.data.length), "Cache-Control": "no-store, no-cache"};
110
- if (_gthis.config.headers != null) {
111
- let access = _gthis.config.headers;
112
- let _g_keys = Reflect__1.fields(access);
113
- let _g_index = 0;
114
- while (_g_index < _g_keys.length) {
115
- let key = _g_keys[_g_index++];
116
- headers[key] = access[key];
117
- };
118
- };
119
- res.writeHead(200, headers);
120
- res.write(source.data, "binary");
121
- res.end();
122
- })["catch"](function (e) {
123
- Log.log(40, ...["Server error.", {"error": e}]);
124
- res.writeHead(500, "Error happened.", _gthis.config.headers);
125
- if (((e) instanceof Error)) {
126
- res.write(e.stack, "utf-8");
127
- } else {
128
- res.write(Std.string(e), "utf-8");
129
- };
130
- res.end();
131
- });
132
- })["catch"](function (e) {
133
- Log.log(40, ...["Server error.", {"error": e}]);
134
- res.writeHead(500, "Error happened.", _gthis.config.headers);
135
- if (((e) instanceof Error)) {
136
- res.write(e.stack, "utf-8");
137
- } else {
138
- res.write(Std.string(e), "utf-8");
139
- };
140
- res.end();
141
- });
142
- })["catch"](function (e) {
143
- Log.log(40, ...["Server error.", {"error": e}]);
144
- res.writeHead(500, "Error happened.", _gthis.config.headers);
145
- if (((e) instanceof Error)) {
146
- res.write(e.stack, "utf-8");
147
- } else {
148
- res.write(Std.string(e), "utf-8");
149
- };
150
- res.end();
151
- });
152
- break
153
- case "OPTIONS":
154
- res.writeHead(200, this.config.headers);
155
- res.end();
156
- break
157
- case "POST":
158
- let stoneId = Path.posix.join(".", "./", ".", id);
159
- let stone = Lambda.find(this.project.stones, function (s) {
160
- return s.id == stoneId;
161
- });
162
- if (stone == null) {
163
- let e = "Could not find stone with such id.";
164
- Log.log(40, ...["Server error.", {"error": e}]);
165
- res.writeHead(500, "Error happened.", _gthis.config.headers);
166
- if (((e) instanceof Error)) {
167
- res.write(e.stack, "utf-8");
168
- } else {
169
- res.write(Std.string(e), "utf-8");
170
- };
171
- res.end();
172
- } else {
173
- let body = "";
174
- req.on("data", function (chunk) {
175
- body += chunk;
176
- return body;
177
- });
178
- req.on("end", function () {
179
- let request = JSON.parse(body);
180
- if (request.config != null) {
181
- let _g = 0;
182
- let _g1 = Reflect__1.fields(stone.config);
183
- while (_g < _g1.length) {
184
- let field = _g1[_g];
185
- ++_g;
186
- stone.config[field] = Reflect__1.field(request.config, field);
187
- };
188
- };
189
- if (request.getSource) {
190
- stone.getSource().then(function (src) {
191
- let resJson = {};
192
- let _g = 0;
193
- let _g1 = src.data;
194
- while (_g < _g1.length) {
195
- let data = _g1[_g];
196
- ++_g;
197
- resJson[data.id] = data.data.toString("base64");
198
- };
199
- res.writeHead(200, _gthis.config.headers);
200
- res.write(JSON.stringify(resJson), "utf-8");
201
- res.end();
202
- })["catch"](function (e) {
203
- Log.log(40, ...["Server error.", {"error": e}]);
204
- res.writeHead(500, "Error happened.", _gthis.config.headers);
205
- if (((e) instanceof Error)) {
206
- res.write(e.stack, "utf-8");
207
- } else {
208
- res.write(Std.string(e), "utf-8");
209
- };
210
- res.end();
211
- });
212
- } else {
213
- res.writeHead(200, _gthis.config.headers);
214
- res.end();
215
- };
216
- });
217
- };
218
- break
219
- case "PUT":
220
- let cmd = [Path.posix.join(".", "./", ".", id)];
221
- let body = "";
222
- req.on("data", function (chunk) {
223
- body += chunk;
224
- return body;
225
- });
226
- req.on("end", function () {
227
- if (body != "") {
228
- cmd.push(body);
229
- };
230
- return Whet_Fields_.executeCommand(cmd).then(function (_) {
231
- res.writeHead(200, _gthis.config.headers);
232
- res.end();
233
- })["catch"](function (e) {
234
- Log.log(40, ...["Server error.", {"error": e}]);
235
- res.writeHead(500, "Error happened.", _gthis.config.headers);
236
- if (((e) instanceof Error)) {
237
- res.write(e.stack, "utf-8");
238
- } else {
239
- res.write(Std.string(e), "utf-8");
240
- };
241
- res.end();
242
- });
243
- });
244
- break
245
- default:
246
- res.writeHead(400, "Unsupported method.");
247
- res.end();
248
-
249
- };
250
- }
251
- static get __name__() {
252
- return "whet.stones.Server"
253
- }
254
- static get __super__() {
255
- return Stone
256
- }
257
- get __class__() {
258
- return Server
259
- }
260
- }
261
-