shelving 1.93.0 → 1.93.1

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.
@@ -2,8 +2,11 @@
2
2
  * Thrown if the program receives a value it didn't expect.
3
3
  *
4
4
  * @param message Message that explains why the thing happened.
5
- * @param ...received One or more additional details that appears in a ` (received X, Y, Z)` part of the message.
5
+ * @param received The value that made the assertion fail.
6
+ * @param expected The value that made the assertion fail.
6
7
  */
7
8
  export declare class AssertionError extends Error {
8
- constructor(message?: string, ...received: unknown[]);
9
+ readonly received: unknown;
10
+ readonly expected: unknown;
11
+ constructor(message?: string, ...receivedExpected: readonly [received?: unknown, expected?: unknown]);
9
12
  }
@@ -1,13 +1,20 @@
1
- import { debug } from "../util/debug.js";
1
+ import { debug, indent } from "../util/debug.js";
2
2
  /**
3
3
  * Thrown if the program receives a value it didn't expect.
4
4
  *
5
5
  * @param message Message that explains why the thing happened.
6
- * @param ...received One or more additional details that appears in a ` (received X, Y, Z)` part of the message.
6
+ * @param received The value that made the assertion fail.
7
+ * @param expected The value that made the assertion fail.
7
8
  */
8
9
  export class AssertionError extends Error {
9
- constructor(message = "Failed assertion", ...received) {
10
- super(received.length ? `${message} (received ${received.map(debug).join(", ")})` : message);
10
+ constructor(message = "Failed assertion", ...receivedExpected) {
11
+ super(receivedExpected.length >= 2 //
12
+ ? `${message}\nReceived:${indent(debug(receivedExpected[0]))}\nExpected:${indent(debug(receivedExpected[0]))}`
13
+ : receivedExpected.length >= 1
14
+ ? `${message}\nReceived:${indent(debug(receivedExpected[0]))}`
15
+ : message);
16
+ this.received = receivedExpected[0];
17
+ this.expected = receivedExpected[1];
11
18
  }
12
19
  }
13
20
  AssertionError.prototype.name = "AssertionError";
@@ -1,3 +1,4 @@
1
+ import { indent } from "../util/debug.js";
1
2
  import { getProp } from "../util/object.js";
2
3
  import { mapDictionary } from "../util/transform.js";
3
4
  import { Feedback } from "./Feedback.js";
@@ -8,7 +9,8 @@ export class Feedbacks extends Feedback {
8
9
  return mapDictionary(this.feedbacks, getProp, "message");
9
10
  }
10
11
  constructor(feedbacks, value) {
11
- super("Invalid format", value);
12
+ super(`${Object.entries(feedbacks).map(_mapMessages).join("\n")}`, value);
12
13
  this.feedbacks = feedbacks;
13
14
  }
14
15
  }
16
+ const _mapMessages = ([name, { message }]) => `${name}:${indent(message)}`;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.93.0",
14
+ "version": "1.93.1",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
package/util/assert.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Assert a boolean condition is true. */
2
- export declare function assert(condition: unknown, ...received: unknown[]): asserts condition;
2
+ export declare function assert(condition: unknown, ...receivedExpected: [received?: unknown, expected?: unknown]): asserts condition;
3
3
  /** Assert two values are equal. */
4
4
  export declare function assertEqual<T>(left: T | unknown, right: T): asserts left is T;
5
5
  /** Assert two values are equal. */
package/util/assert.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { AssertionError } from "../error/AssertionError.js";
2
2
  /** Assert a boolean condition is true. */
3
- export function assert(condition, ...received) {
3
+ export function assert(condition, ...receivedExpected) {
4
4
  if (!condition)
5
- throw new AssertionError(`Must assert`, ...received);
5
+ throw new AssertionError(`Must assert`, ...receivedExpected);
6
6
  }
7
7
  /** Assert two values are equal. */
8
8
  export function assertEqual(left, right) {
package/util/debug.d.ts CHANGED
@@ -14,3 +14,5 @@ export declare function debugSet(value: ImmutableSet, depth?: number): string;
14
14
  export declare function debugMap(value: ImmutableMap, depth?: number): string;
15
15
  /** Debug an object. */
16
16
  export declare function debugObject(value: object, depth?: number): string;
17
+ /** If a string is multiline, push it onto the next line and prepend a tab to each line.. */
18
+ export declare function indent(str: string): string;
package/util/debug.js CHANGED
@@ -75,3 +75,8 @@ export function debugObject(value, depth = 1) {
75
75
  : "";
76
76
  return `${name ? `${name} ` : ""}${entries ? `{\n\t${entries}\n}` : "{}"}`;
77
77
  }
78
+ /** If a string is multiline, push it onto the next line and prepend a tab to each line.. */
79
+ export function indent(str) {
80
+ const lines = str.split("\n");
81
+ return lines.length > 1 ? `\n${lines.join("\n\t")}` : ` ${str}`;
82
+ }