@oliversalzburg/js-utils 0.0.22-dev.3 → 0.0.22-dev.5

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.
@@ -1,4 +1,4 @@
1
- import { ConstructorOf } from "./core.js";
1
+ import { ConstructorOf } from "../core.js";
2
2
  /**
3
3
  * Places the items in the array in random order.
4
4
  * @param array - The array to shuffle.
@@ -1,4 +1,4 @@
1
- import { is } from "./nil.js";
1
+ import { is } from "../nil.js";
2
2
  /**
3
3
  * Places the items in the array in random order.
4
4
  * @param array - The array to shuffle.
@@ -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
@@ -1 +1,2 @@
1
+ export * from "./array.js";
1
2
  export * from "./tree.js";
package/data/index.js CHANGED
@@ -1,2 +1,3 @@
1
+ export * from "./array.js";
1
2
  export * from "./tree.js";
2
3
  //# sourceMappingURL=index.js.map
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,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,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,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
@@ -0,0 +1,2 @@
1
+ export * from "./log.js";
2
+ export * from "./report.js";
package/log/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./log.js";
2
+ export * from "./report.js";
3
+ //# sourceMappingURL=index.js.map
@@ -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
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Describes the most simple logger.
3
+ * @group Logging
4
+ */
5
+ export interface BareLogger {
6
+ /**
7
+ * Logs a message.
8
+ * @param message - The message to log.
9
+ * @param args - Additional arguments to log.
10
+ */
11
+ log(message: string, ...args: Array<unknown>): void;
12
+ }
package/log/log.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=log.js.map
package/log/log.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../../source/log/log.ts"],"names":[],"mappings":""}
@@ -0,0 +1,53 @@
1
+ import { TreeNode } from "../data/tree.js";
2
+ import { BareLogger } from "./log.js";
3
+ /**
4
+ * An entry of a {@linkcode Report}.
5
+ * @group Logging
6
+ */
7
+ export interface ReportEntry {
8
+ /**
9
+ * The message in the entry.
10
+ */
11
+ message: string;
12
+ /**
13
+ * An optional key-value hash, that might have been
14
+ * provided with the entry.
15
+ */
16
+ context: Record<string, unknown> | undefined;
17
+ }
18
+ /**
19
+ * A hierarchical background report/log.
20
+ * @group Logging
21
+ */
22
+ export declare class Report extends TreeNode<Report> {
23
+ #private;
24
+ /**
25
+ * The ID of this report.
26
+ */
27
+ readonly origin: string;
28
+ /**
29
+ * Retrieve the message store.
30
+ * @returns The message store.
31
+ */
32
+ get store(): Map<string, Array<ReportEntry>>;
33
+ /**
34
+ * Constructs a new report.
35
+ * @param origin - The ID of this report.
36
+ * @param parent - The paren report for this report.
37
+ * @throws {@linkcode InvalidOperationError} When the origin was already
38
+ * used by another report in this hierarchy.
39
+ */
40
+ constructor(origin: string, parent?: Report | undefined);
41
+ /**
42
+ * Put an entry into the report.
43
+ * @param message - The message to add.
44
+ * @param context - An arbitrary key-value object to store with the message.
45
+ */
46
+ log(message: string, context?: Record<string, unknown>): void;
47
+ /**
48
+ * Prints the contents of the report.
49
+ * @param logger - A logger to use to print the report.
50
+ * @param depth - How deep to indent this part of the report.
51
+ */
52
+ aggregate(logger: BareLogger, depth?: number): void;
53
+ }
package/log/report.js ADDED
@@ -0,0 +1,84 @@
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
+ * @group Logging
7
+ */
8
+ // eslint-disable-next-line no-use-before-define
9
+ export class Report extends TreeNode {
10
+ /**
11
+ * The ID of this report.
12
+ */
13
+ origin;
14
+ /**
15
+ * Our storage for all logged messages.
16
+ */
17
+ #store = new Map();
18
+ /**
19
+ * Retrieve the message store.
20
+ * @returns The message store.
21
+ */
22
+ get store() {
23
+ return this.parent?.store ?? this.#store;
24
+ }
25
+ /**
26
+ * Constructs a new report.
27
+ * @param origin - The ID of this report.
28
+ * @param parent - The paren report for this report.
29
+ * @throws {@linkcode InvalidOperationError} When the origin was already
30
+ * used by another report in this hierarchy.
31
+ */
32
+ constructor(origin, parent) {
33
+ super(parent);
34
+ if (this.store.has(origin)) {
35
+ throw new InvalidOperationError(`The origin '${origin}' was already used in this report.`);
36
+ }
37
+ this.origin = origin;
38
+ }
39
+ /**
40
+ * Retrieves an entry of the store for the given origin.
41
+ * @param origin - The origin of the entry.
42
+ * @returns The store entry with that origin.
43
+ */
44
+ #getStoreEntry(origin) {
45
+ if (!this.#store.has(origin)) {
46
+ this.#store.set(origin, new Array());
47
+ }
48
+ return this.#store.get(origin);
49
+ }
50
+ /**
51
+ * Put an entry into the report.
52
+ * @param message - The message to add.
53
+ * @param context - An arbitrary key-value object to store with the message.
54
+ */
55
+ log(message, context) {
56
+ this.#getStoreEntry(this.origin)?.push({ message, context });
57
+ }
58
+ /**
59
+ * Prints the contents of the report.
60
+ * @param logger - A logger to use to print the report.
61
+ * @param depth - How deep to indent this part of the report.
62
+ */
63
+ aggregate(logger, depth = 0) {
64
+ for (const [origin, records] of this.#store.entries()) {
65
+ if (origin !== this.origin) {
66
+ continue;
67
+ }
68
+ logger.log(indent(`${origin}`, depth));
69
+ for (const entry of records) {
70
+ logger.log(indent(` - ${entry.message}`, depth));
71
+ if (entry.context) {
72
+ logger.log(indent(JSON.stringify(entry.context, undefined, depth + 4), depth));
73
+ }
74
+ }
75
+ }
76
+ if (this.children.size === 0) {
77
+ return;
78
+ }
79
+ for (const child of this.children) {
80
+ child.aggregate(logger, depth + 1);
81
+ }
82
+ }
83
+ }
84
+ //# 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;AAoBtC;;;GAGG;AACH,gDAAgD;AAChD,MAAM,OAAO,MAAO,SAAQ,QAAgB;IAC1C;;OAEG;IACM,MAAM,CAAS;IACxB;;OAEG;IACH,MAAM,GAAG,IAAI,GAAG,EAA8B,CAAC;IAE/C;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC;IAC3C,CAAC;IAED;;;;;;OAMG;IACH,YAAY,MAAc,EAAE,MAA2B;QACrD,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAC1B,MAAM,IAAI,qBAAqB,CAAC,eAAe,MAAM,oCAAoC,CAAC,CAAC;SAC5F;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,MAAc;QAC3B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM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CAAC;SACpC;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@oliversalzburg/js-utils",
4
- "version": "0.0.22-dev.3",
4
+ "version": "0.0.22-dev.5",
5
5
  "license": "MIT",
6
6
  "author": "Oliver Salzburg <oliver.salzburg@gmail.com>",
7
7
  "repository": {
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,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;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