whet 0.1.1 → 0.2.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.
@@ -0,0 +1,49 @@
1
+ import {StringMap} from "../../haxe/ds/StringMap.js"
2
+ import {Register} from "../../genes/Register.js"
3
+
4
+ const $global = Register.$global
5
+
6
+ export const SpanStats = Register.global("$hxClasses")["whet.profiler.SpanStats"] =
7
+ class SpanStats extends Register.inherits() {
8
+ [Register.new]() {
9
+ this.data = new StringMap();
10
+ }
11
+ getEstimate(stoneId, op) {
12
+ let entry = this.data.inst.get("" + stoneId + ":" + op);
13
+ if (entry != null) {
14
+ return entry.lastDuration;
15
+ } else {
16
+ return 0;
17
+ };
18
+ }
19
+ update(stoneId, op, duration) {
20
+ let key = "" + stoneId + ":" + op;
21
+ let entry = this.data.inst.get(key);
22
+ if (entry == null) {
23
+ this.data.inst.set(key, {"lastDuration": duration, "totalDuration": duration, "count": 1});
24
+ } else {
25
+ entry.lastDuration = duration;
26
+ entry.totalDuration += duration;
27
+ entry.count++;
28
+ };
29
+ }
30
+ getSummary() {
31
+ let result = {};
32
+ let this1 = this.data;
33
+ let _g_keys = this1.keys();
34
+ while (_g_keys.hasNext()) {
35
+ let key = _g_keys.next();
36
+ let _g_value = this1.get(key);
37
+ result[key] = {"lastDuration": _g_value.lastDuration, "avgDuration": _g_value.totalDuration / _g_value.count, "count": _g_value.count};
38
+ };
39
+ return result;
40
+ }
41
+ static get __name__() {
42
+ return "whet.profiler.SpanStats"
43
+ }
44
+ get __class__() {
45
+ return SpanStats
46
+ }
47
+ }
48
+ SpanStats.prototype.data = null;
49
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whet",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "NodeJS based assets management and project tooling library.",
5
5
  "scripts": {
6
6
  "devinit": "npx dts2hx commander pino-pretty minimatch --modular --noLibWrap",
@@ -27,7 +27,7 @@
27
27
  "homepage": "https://github.com/Antriel/whet#readme",
28
28
  "dependencies": {
29
29
  "commander": "^14.0.3",
30
- "minimatch": "^10.2.2",
30
+ "minimatch": "^10.2.4",
31
31
  "pino-pretty": "^13.1.3"
32
32
  },
33
33
  "devDependencies": {
package/bin/haxe/Log.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import {PosInfos} from "./PosInfos"
2
-
3
- /**
4
- Log primarily provides the `trace()` method, which is invoked upon a call to
5
- `trace()` in Haxe code.
6
- */
7
- export declare class Log {
8
-
9
- /**
10
- Format the output of `trace` before printing it.
11
- */
12
- static formatOutput(v: any, infos: PosInfos): string
13
-
14
- /**
15
- Outputs `v` in a platform-dependent way.
16
-
17
- The second parameter `infos` is injected by the compiler and contains
18
- information about the position where the `trace()` call was made.
19
-
20
- This method can be rebound to a custom function:
21
-
22
- var oldTrace = haxe.Log.trace; // store old function
23
- haxe.Log.trace = function(v, ?infos) {
24
- // handle trace
25
- }
26
- ...
27
- haxe.Log.trace = oldTrace;
28
-
29
- If it is bound to null, subsequent calls to `trace()` will cause an
30
- exception.
31
- */
32
- static trace(v: any, infos?: null | PosInfos): void
33
- }
package/bin/haxe/Log.js DELETED
@@ -1,61 +0,0 @@
1
- import {Register} from "../genes/Register.js"
2
- import {Std} from "../Std.js"
3
-
4
- const $global = Register.$global
5
-
6
- /**
7
- Log primarily provides the `trace()` method, which is invoked upon a call to
8
- `trace()` in Haxe code.
9
- */
10
- export const Log = Register.global("$hxClasses")["haxe.Log"] =
11
- class Log {
12
-
13
- /**
14
- Format the output of `trace` before printing it.
15
- */
16
- static formatOutput(v, infos) {
17
- let str = Std.string(v);
18
- if (infos == null) {
19
- return str;
20
- };
21
- let pstr = infos.fileName + ":" + infos.lineNumber;
22
- if (infos.customParams != null) {
23
- let _g = 0;
24
- let _g1 = infos.customParams;
25
- while (_g < _g1.length) str += ", " + Std.string(_g1[_g++]);
26
- };
27
- return pstr + ": " + str;
28
- }
29
-
30
- /**
31
- Outputs `v` in a platform-dependent way.
32
-
33
- The second parameter `infos` is injected by the compiler and contains
34
- information about the position where the `trace()` call was made.
35
-
36
- This method can be rebound to a custom function:
37
-
38
- var oldTrace = haxe.Log.trace; // store old function
39
- haxe.Log.trace = function(v, ?infos) {
40
- // handle trace
41
- }
42
- ...
43
- haxe.Log.trace = oldTrace;
44
-
45
- If it is bound to null, subsequent calls to `trace()` will cause an
46
- exception.
47
- */
48
- static trace(v, infos) {
49
- let str = Log.formatOutput(v, infos);
50
- if (typeof(console) != "undefined" && console.log != null) {
51
- console.log(str);
52
- };
53
- }
54
- static get __name__() {
55
- return "haxe.Log"
56
- }
57
- get __class__() {
58
- return Log
59
- }
60
- }
61
-
@@ -1,98 +0,0 @@
1
- import {Prettifier} from "./default_/Prettifier"
2
-
3
- export type PrettyOptions = {
4
- /**
5
- Opens the file with the 'a' flag.
6
- */
7
- append?: null | boolean,
8
- /**
9
- If set to true, will add color information to the formatted output message.
10
- */
11
- colorize?: null | boolean,
12
- /**
13
- Appends carriage return and line feed, instead of just a line feed, to the formatted log line.
14
- */
15
- crlf?: null | boolean,
16
- /**
17
- Provides the ability to add a custom prettify function for specific log properties.
18
- `customPrettifiers` is an object, where keys are log properties that will be prettified
19
- and value is the prettify function itself.
20
- For example, if a log line contains a query property, you can specify a prettifier for it:
21
- */
22
- customPrettifiers?: null | {[key: string]: Prettifier},
23
- /**
24
- The file, file descriptor, or stream to write to. Defaults to 1 (stdout).
25
- */
26
- destination?: null | any,
27
- /**
28
- Define the log keys that are associated with error like objects.
29
- */
30
- errorLikeObjectKeys?: null | string[],
31
- /**
32
- When formatting an error object, display this list of properties.
33
- The list should be a comma separated list of properties.
34
- */
35
- errorProps?: null | string,
36
- /**
37
- Hide objects from output (but not error object).
38
- */
39
- hideObject?: null | boolean,
40
- /**
41
- Ignore one or several keys.
42
- Will be overridden by the option include if include is presented.
43
- */
44
- ignore?: null | string,
45
- /**
46
- Include one or several keys.
47
- */
48
- include?: null | string,
49
- /**
50
- If set to true, it will print the name of the log level as the first field in the log line.
51
- */
52
- levelFirst?: null | boolean,
53
- /**
54
- Define the key that contains the level of the log.
55
- */
56
- levelKey?: null | string,
57
- /**
58
- Output the log level using the specified label.
59
- */
60
- levelLabel?: null | string,
61
- /**
62
- Format output of message, e.g. {level} - {pid} will output message: INFO - 1123
63
- */
64
- messageFormat?: null | any,
65
- /**
66
- The key in the JSON object to use as the highlighted message.
67
- */
68
- messageKey?: null | string,
69
- /**
70
- The minimum log level to include in the output.
71
- */
72
- minimumLevel?: null | any,
73
- /**
74
- Ensure directory for destination file exists.
75
- */
76
- mkdir?: null | boolean,
77
- /**
78
- Print each log message on a single line (errors will still be multi-line).
79
- */
80
- singleLine?: null | boolean,
81
- /**
82
- Makes messaging synchronous.
83
- */
84
- sync?: null | boolean,
85
- /**
86
- The key in the JSON object to use for timestamp display.
87
- */
88
- timestampKey?: null | string,
89
- /**
90
- Translate the epoch time value into a human readable date and time string. This flag also can set the format
91
- string to apply when translating the date to human readable format. For a list of available pattern letters
92
- see the {@link https://www.npmjs.com/package/dateformat|dateformat documentation}.
93
- - The default format is `yyyy-mm-dd HH:MM:ss.l o` in UTC.
94
- - Requires a `SYS:` prefix to translate time to the local system's timezone. Use the shortcut `SYS:standard`
95
- to translate time to `yyyy-mm-dd HH:MM:ss.l o` in system timezone.
96
- */
97
- translateTime?: null | any
98
- }
@@ -1,2 +0,0 @@
1
-
2
- export type MessageFormatFunc = ((log: {[key: string]: any}, messageKey: string, levelLabel: string) => string)
@@ -1,2 +0,0 @@
1
-
2
- export type Prettifier = ((inputData: any) => string)
@@ -1,77 +0,0 @@
1
-
2
- export type IOptions = {
3
- /**
4
- Dump a ton of stuff to stderr.
5
- */
6
- debug?: null | boolean,
7
- /**
8
- Allow patterns to match filenames starting with a period,
9
- even if the pattern does not explicitly have a period in that spot.
10
-
11
- Note that by default, `'a/**' + '/b'` will **not** match `a/.d/b`, unless `dot` is set.
12
- */
13
- dot?: null | boolean,
14
- /**
15
- Returns from negate expressions the same as if they were not negated.
16
- (Ie, true on a hit, false on a miss.)
17
- */
18
- flipNegate?: null | boolean,
19
- /**
20
- If set, then patterns without slashes will be matched
21
- against the basename of the path if it contains slashes. For example,
22
- `a?b` would match the path `/xyz/123/acb`, but not `/xyz/acb/123`.
23
- */
24
- matchBase?: null | boolean,
25
- /**
26
- Do not expand `{a,b}` and `{1..3}` brace sets.
27
- */
28
- nobrace?: null | boolean,
29
- /**
30
- Perform a case-insensitive match.
31
- */
32
- nocase?: null | boolean,
33
- /**
34
- Suppress the behavior of treating `#` at the start of a pattern as a comment.
35
- */
36
- nocomment?: null | boolean,
37
- /**
38
- Disable "extglob" style patterns like `+(a|b)`.
39
- */
40
- noext?: null | boolean,
41
- /**
42
- Disable `**` matching against multiple folder names.
43
- */
44
- noglobstar?: null | boolean,
45
- /**
46
- Suppress the behavior of treating a leading `!` character as negation.
47
- */
48
- nonegate?: null | boolean,
49
- /**
50
- When a match is not found by `minimatch.match`,
51
- return a list containing the pattern itself if this option is set.
52
- Otherwise, an empty list is returned if there are no matches.
53
- */
54
- nonull?: null | boolean,
55
- /**
56
- Compare a partial path to a pattern. As long as the parts of the path that
57
- are present are not contradicted by the pattern, it will be treated as a
58
- match. This is useful in applications where you're walking through a
59
- folder structure, and don't yet have the full path, but want to ensure that
60
- you do not walk down paths that can never be a match.
61
- */
62
- partial?: null | boolean,
63
- /**
64
- Use `\\` as a path separator _only_, and _never_ as an escape
65
- character. If set, all `\\` characters are replaced with `/` in
66
- the pattern. Note that this makes it **impossible** to match
67
- against paths containing literal glob pattern characters, but
68
- allows matching with patterns constructed using `path.join()` and
69
- `path.resolve()` on Windows platforms, mimicking the (buggy!)
70
- behavior of earlier versions on Windows. Please use with
71
- caution, and be mindful of the caveat about Windows paths
72
-
73
- For legacy reasons, this is also set if
74
- `options.allowWindowsEscape` is set to the exact value `false`.
75
- */
76
- windowsPathsNoEscape?: null | boolean
77
- }
@@ -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
-