@oliversalzburg/js-utils 0.0.22-dev.3 → 0.0.22-dev.4
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.
- package/{array.d.ts → data/array.d.ts} +1 -1
- package/{array.js → data/array.js} +1 -1
- package/data/array.js.map +1 -0
- package/data/index.d.ts +1 -0
- package/data/index.js +1 -0
- package/data/index.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/log/index.d.ts +2 -0
- package/log/index.js +3 -0
- package/log/index.js.map +1 -0
- package/log/log.d.ts +11 -0
- package/log/log.js +2 -0
- package/log/log.js.map +1 -0
- package/log/report.d.ts +51 -0
- package/log/report.js +83 -0
- package/log/report.js.map +1 -0
- package/package.json +1 -1
- package/array.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../source/data/array.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAE/B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAY,KAAuB,EAAE,EAAE;IACjE,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE;QACrD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1B,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;QAClC,KAAK,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;KAC3B;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAY,CAAmB,EAAE,CAAmB,EAAE,EAAE;IAC/E,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAY,CAAmB,EAAE,CAAmB,EAAE,EAAE;IAChF,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAAqB,EACrB,YAAsC,EACtC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAqB,CAAC"}
|
package/data/index.d.ts
CHANGED
package/data/index.js
CHANGED
package/data/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/data/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/data/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from "./array.js";
|
|
2
1
|
export * from "./async.js";
|
|
3
2
|
export * from "./core.js";
|
|
4
3
|
export * from "./data/index.js";
|
|
@@ -6,6 +5,7 @@ export * from "./dom/index.js";
|
|
|
6
5
|
export * from "./error-serializer.js";
|
|
7
6
|
export * from "./errors/index.js";
|
|
8
7
|
export * from "./graphics/index.js";
|
|
8
|
+
export * from "./log/index.js";
|
|
9
9
|
export * from "./math/index.js";
|
|
10
10
|
export * from "./nil.js";
|
|
11
11
|
export * from "./random.js";
|
package/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from "./array.js";
|
|
2
1
|
export * from "./async.js";
|
|
3
2
|
export * from "./core.js";
|
|
4
3
|
export * from "./data/index.js";
|
|
@@ -6,6 +5,7 @@ export * from "./dom/index.js";
|
|
|
6
5
|
export * from "./error-serializer.js";
|
|
7
6
|
export * from "./errors/index.js";
|
|
8
7
|
export * from "./graphics/index.js";
|
|
8
|
+
export * from "./log/index.js";
|
|
9
9
|
export * from "./math/index.js";
|
|
10
10
|
export * from "./nil.js";
|
|
11
11
|
export * from "./random.js";
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
package/log/index.d.ts
ADDED
package/log/index.js
ADDED
package/log/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/log/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
|
package/log/log.d.ts
ADDED
package/log/log.js
ADDED
package/log/log.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../source/log/log.ts"],"names":[],"mappings":""}
|
package/log/report.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { TreeNode } from "../data/tree.js";
|
|
2
|
+
import { BareLogger } from "./log.js";
|
|
3
|
+
/**
|
|
4
|
+
* An entry of a {@linkcode Report}.
|
|
5
|
+
*/
|
|
6
|
+
export interface ReportEntry {
|
|
7
|
+
/**
|
|
8
|
+
* The message in the entry.
|
|
9
|
+
*/
|
|
10
|
+
message: string;
|
|
11
|
+
/**
|
|
12
|
+
* An optional key-value hash, that might have been
|
|
13
|
+
* provided with the entry.
|
|
14
|
+
*/
|
|
15
|
+
context: Record<string, unknown> | undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A hierarchical background report/log.
|
|
19
|
+
*/
|
|
20
|
+
export declare class Report extends TreeNode<Report> {
|
|
21
|
+
#private;
|
|
22
|
+
/**
|
|
23
|
+
* The ID of this report.
|
|
24
|
+
*/
|
|
25
|
+
readonly origin: string;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieve the message store.
|
|
28
|
+
* @returns The message store.
|
|
29
|
+
*/
|
|
30
|
+
get store(): Map<string, Array<ReportEntry>>;
|
|
31
|
+
/**
|
|
32
|
+
* Constructs a new report.
|
|
33
|
+
* @param origin - The ID of this report.
|
|
34
|
+
* @param parent - The paren report for this report.
|
|
35
|
+
* @throws {@linkcode InvalidOperationError} When the origin was already
|
|
36
|
+
* used by another report in this hierarchy.
|
|
37
|
+
*/
|
|
38
|
+
constructor(origin: string, parent?: Report | undefined);
|
|
39
|
+
/**
|
|
40
|
+
* Put an entry into the report.
|
|
41
|
+
* @param message - The message to add.
|
|
42
|
+
* @param context - An arbitrary key-value object to store with the message.
|
|
43
|
+
*/
|
|
44
|
+
log(message: string, context?: Record<string, unknown>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Prints the contents of the report.
|
|
47
|
+
* @param logger - A logger to use to print the report.
|
|
48
|
+
* @param depth - How deep to indent this part of the report.
|
|
49
|
+
*/
|
|
50
|
+
aggregate(logger: BareLogger, depth?: number): void;
|
|
51
|
+
}
|
package/log/report.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { TreeNode } from "../data/tree.js";
|
|
2
|
+
import { InvalidOperationError } from "../errors/InvalidOperationError.js";
|
|
3
|
+
import { indent } from "../string.js";
|
|
4
|
+
/**
|
|
5
|
+
* A hierarchical background report/log.
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line no-use-before-define
|
|
8
|
+
export class Report extends TreeNode {
|
|
9
|
+
/**
|
|
10
|
+
* The ID of this report.
|
|
11
|
+
*/
|
|
12
|
+
origin;
|
|
13
|
+
/**
|
|
14
|
+
* Our storage for all logged messages.
|
|
15
|
+
*/
|
|
16
|
+
#store = new Map();
|
|
17
|
+
/**
|
|
18
|
+
* Retrieve the message store.
|
|
19
|
+
* @returns The message store.
|
|
20
|
+
*/
|
|
21
|
+
get store() {
|
|
22
|
+
return this.parent?.store ?? this.#store;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Constructs a new report.
|
|
26
|
+
* @param origin - The ID of this report.
|
|
27
|
+
* @param parent - The paren report for this report.
|
|
28
|
+
* @throws {@linkcode InvalidOperationError} When the origin was already
|
|
29
|
+
* used by another report in this hierarchy.
|
|
30
|
+
*/
|
|
31
|
+
constructor(origin, parent) {
|
|
32
|
+
super(parent);
|
|
33
|
+
if (this.store.has(origin)) {
|
|
34
|
+
throw new InvalidOperationError(`The origin '${origin}' was already used in this report.`);
|
|
35
|
+
}
|
|
36
|
+
this.origin = origin;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves an entry of the store for the given origin.
|
|
40
|
+
* @param origin - The origin of the entry.
|
|
41
|
+
* @returns The store entry with that origin.
|
|
42
|
+
*/
|
|
43
|
+
#getStoreEntry(origin) {
|
|
44
|
+
if (!this.#store.has(origin)) {
|
|
45
|
+
this.#store.set(origin, new Array());
|
|
46
|
+
}
|
|
47
|
+
return this.#store.get(origin);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Put an entry into the report.
|
|
51
|
+
* @param message - The message to add.
|
|
52
|
+
* @param context - An arbitrary key-value object to store with the message.
|
|
53
|
+
*/
|
|
54
|
+
log(message, context) {
|
|
55
|
+
this.#getStoreEntry(this.origin)?.push({ message, context });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Prints the contents of the report.
|
|
59
|
+
* @param logger - A logger to use to print the report.
|
|
60
|
+
* @param depth - How deep to indent this part of the report.
|
|
61
|
+
*/
|
|
62
|
+
aggregate(logger, depth = 0) {
|
|
63
|
+
for (const [origin, records] of this.#store.entries()) {
|
|
64
|
+
if (origin !== this.origin) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
logger.log(indent(`${origin}`, depth));
|
|
68
|
+
for (const entry of records) {
|
|
69
|
+
logger.log(indent(` - ${entry.message}`, depth));
|
|
70
|
+
if (entry.context) {
|
|
71
|
+
logger.log(indent(JSON.stringify(entry.context, undefined, depth + 4), depth));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (this.children.size === 0) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
for (const child of this.children) {
|
|
79
|
+
child.aggregate(logger, depth + 1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../source/log/report.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAmBtC;;GAEG;AACH,gDAAgD;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M,CAAC,GAAG,MAAM,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;YACvC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE;gBAC3B,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;gBACjD,IAAI,KAAK,CAAC,OAAO,EAAE;oBACjB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;iBAChF;aACF;SACF;QAED,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,EAAE;YAC5B,OAAO;SACR;QAED,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;SACpC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
package/array.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"array.js","sourceRoot":"","sources":["../source/array.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAE9B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAY,KAAuB,EAAE,EAAE;IACjE,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE;QACrD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1B,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,WAAW,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