@cutting/assert 0.1.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.
- package/.eslintrc.json +3 -0
- package/.turbo/turbo-build.log +14 -0
- package/.watchmanconfig +1 -0
- package/CHANGELOG.md +7 -0
- package/README.md +114 -0
- package/dist/esm/assert.d.ts +44 -0
- package/dist/esm/assert.d.ts.map +1 -0
- package/dist/esm/assert.js +62 -0
- package/dist/esm/assert.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/tsconfig.dist.tsbuildinfo +1 -0
- package/package.json +36 -0
- package/src/assert.test.ts +56 -0
- package/src/assert.ts +124 -0
- package/src/index.ts +1 -0
- package/tsconfig.dist.json +10 -0
- package/tsconfig.json +8 -0
- package/vitest.config.ts +13 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
> @cutting/assert@0.1.1 build /home/runner/work/cuttingedge/cuttingedge/packages/assert
|
|
3
|
+
> NODE_ENV=production devtools rollup
|
|
4
|
+
|
|
5
|
+
DEBUG using tsconfig.dist.json
|
|
6
|
+
START using input file index.ts for @cutting/assert
|
|
7
|
+
|
|
8
|
+
INFO Generating @cutting/assert bundle.
|
|
9
|
+
INFO writing index.min for @cutting/assert
|
|
10
|
+
INFO preserveModules is false
|
|
11
|
+
INFO writing index.js for @cutting/assert
|
|
12
|
+
DEBUG copying assets to /home/runner/work/cuttingedge/cuttingedge/packages/assert/dist
|
|
13
|
+
DONE finished building
|
|
14
|
+
|
package/.watchmanconfig
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# @cutting/assert
|
|
2
|
+
|
|
3
|
+
## Just the hard version of [fram-x/assert-ts](https://github.com/fram-x/assert-ts). I kept running into issues with the default export as described [here](https://github.com/fram-x/assert-ts/issues/23). I never used the soft version so I created a hard only version here.
|
|
4
|
+
|
|
5
|
+
Invariant and non-null/undefined assertions
|
|
6
|
+
|
|
7
|
+
- logs error and throws exception, and narrows type.
|
|
8
|
+
|
|
9
|
+
## Introduction
|
|
10
|
+
|
|
11
|
+
The purpose of this library is to make assumptions explicit, rather than just a comment or even worse just a thought while writing your code. This applies both to assumptions about conditions to be met or values not being null/undefined.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
To install the library into your project, run yarn or npm:
|
|
16
|
+
|
|
17
|
+
`yarn add @cutting/assert`
|
|
18
|
+
|
|
19
|
+
or
|
|
20
|
+
|
|
21
|
+
`npm i @cutting/assert`
|
|
22
|
+
|
|
23
|
+
or
|
|
24
|
+
|
|
25
|
+
`pnpm add @cutting/assert`
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
### Assert condition
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import assert from '@cutting/assert';
|
|
33
|
+
|
|
34
|
+
function transfer(fromId: string, toId: string, amount: number) {
|
|
35
|
+
// Throws error if not true
|
|
36
|
+
assert(amount > 0);
|
|
37
|
+
...
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Assert condition with more context info
|
|
43
|
+
|
|
44
|
+
To make it easier to find the cause of an assertion failure, you can provide more information, i.e. a custom message and any relevant properties.
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
import assert from '@cutting/assert';
|
|
48
|
+
|
|
49
|
+
function transfer(fromId: string, toId: string, amount: number) {
|
|
50
|
+
// Custom message and properties will be formatted into error message
|
|
51
|
+
assert(amount > 0, "Cannot transfer 0 or negative amounts", { fromId, toId, ammount });
|
|
52
|
+
...
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Assert non-null/undefined
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
import assert from '@cutting/assert';
|
|
61
|
+
|
|
62
|
+
function findAccount(id): Account | undefined { ... }
|
|
63
|
+
|
|
64
|
+
function transfer(fromnId: string, toId: string, amount: number) {
|
|
65
|
+
...
|
|
66
|
+
|
|
67
|
+
// Throws error if findAccount returns undefined
|
|
68
|
+
const fromAccount = assert(findAccount(fromId), "From account does not exist", { fromId});
|
|
69
|
+
|
|
70
|
+
// Type restriction: when a non-null/undefined assertion succeeds,
|
|
71
|
+
// type is restricted, e.g. to Account. Hence, no need for further testing of undefined/null
|
|
72
|
+
fromAccount.amount -= amount;
|
|
73
|
+
|
|
74
|
+
...
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Assert condition
|
|
80
|
+
|
|
81
|
+
Checks that a condition is true. If not, an error is thrown. By default, any message or properties provided will be formatted as part of the error's message. See below for custom configuration.
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
function assert(
|
|
85
|
+
condition: boolean,
|
|
86
|
+
message?: string,
|
|
87
|
+
props?: object | (() => object),
|
|
88
|
+
): asserts condition;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Assert non-null/undefined
|
|
92
|
+
|
|
93
|
+
Checks that a value is not null or undefined. If null or undefined, an error is thrown. When successful, the returned value's type is restricted to the expected type.
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
function assert<T>(
|
|
97
|
+
value: T | undefined | null,
|
|
98
|
+
message?: string,
|
|
99
|
+
props?: object | (() => object),
|
|
100
|
+
): T;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Configuration
|
|
104
|
+
|
|
105
|
+
The default configuration throws an Error with a message saying whether it was a condition or null/undefined check that failed and any custom message or properties formatted as part of the message.
|
|
106
|
+
|
|
107
|
+
Use `configureAssert` to customize this, providing an `AssertConfiguration` object with any of the following properties:
|
|
108
|
+
|
|
109
|
+
| Property | Description |
|
|
110
|
+
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
111
|
+
| formatter | To do custom formatting of error message `(failureType: FailureType, message?: string, props?: object) => string` |
|
|
112
|
+
| errorCreator | To create custom error objects `(failureType: FailureType, message?: string, props?: object) => Error` |
|
|
113
|
+
| errorReporter | To do custom reporting of assertion failures, e.g. report to backend `(failureType: FailureType, error: Error, message?: string, props?: object) => void` |
|
|
114
|
+
| warningReporter | To do custom reporting of soft assertion failures, e.g. report to backend `(failureType: FailureType, message?: string, props?: object) => void` |
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
declare enum FailureType {
|
|
2
|
+
Condition = "Condition",
|
|
3
|
+
NoValue = "NoValue"
|
|
4
|
+
}
|
|
5
|
+
type ErrorFormatter = (failureType: FailureType, message?: string, props?: object) => string;
|
|
6
|
+
type ErrorCreator = (failureType: FailureType, message?: string, props?: object) => Error;
|
|
7
|
+
type ErrorReporter = (failureType: FailureType, error: Error, message?: string, props?: object) => void;
|
|
8
|
+
type WarningReporter = (failureType: FailureType, message?: string, props?: object) => void;
|
|
9
|
+
export type AssertConfiguration = {
|
|
10
|
+
formatter?: ErrorFormatter;
|
|
11
|
+
errorCreator?: ErrorCreator;
|
|
12
|
+
errorReporter?: ErrorReporter;
|
|
13
|
+
warningReporter?: WarningReporter;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Customize formatting of assertion failure messages, creation of failure Errors and reporting of failures
|
|
17
|
+
* @param custom
|
|
18
|
+
*/
|
|
19
|
+
export declare function configureAssert(custom: AssertConfiguration): void;
|
|
20
|
+
/**
|
|
21
|
+
* For test purpose
|
|
22
|
+
*/
|
|
23
|
+
export declare function testResetConfiguration(): void;
|
|
24
|
+
interface Assert {
|
|
25
|
+
/**
|
|
26
|
+
* Verify that a condition is satisfied.
|
|
27
|
+
* @param condition Condition to be true
|
|
28
|
+
* @param message Error message
|
|
29
|
+
* @param props Any props relevant.
|
|
30
|
+
* @throws Throws exception if condition is false.
|
|
31
|
+
*/
|
|
32
|
+
(condition: boolean, message?: string, props?: object | (() => object)): asserts condition;
|
|
33
|
+
/**
|
|
34
|
+
* Verify that an optional value actually has a proper value in this context, i.e. not null or undefined.
|
|
35
|
+
* @param value Value to be verified
|
|
36
|
+
* @param message Error message
|
|
37
|
+
* @param props If message is a string id, format any matching key values into message. Props are also reported to dev team.
|
|
38
|
+
* @throws Throws exception if value is null or undefined
|
|
39
|
+
*/
|
|
40
|
+
<T>(value: T | undefined | null, message?: string, props?: object | (() => object)): T;
|
|
41
|
+
}
|
|
42
|
+
export declare const assert: Assert;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/assert.ts"],"names":[],"mappings":"AAAA,aAAK,WAAW;IACd,SAAS,cAAc;IACvB,OAAO,YAAY;CACpB;AAED,KAAK,cAAc,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAE7F,KAAK,YAAY,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,KAAK,CAAC;AAE1F,KAAK,aAAa,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAExG,KAAK,eAAe,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAE5F,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,CAAC;AAgCF;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CASjE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAED,UAAU,MAAM;IACd;;;;;;OAMG;IACH,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;IAE3F;;;;;;OAMG;IACH,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;CACxF;AAED,eAAO,MAAM,MAAM,EAAE,MA+BpB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var FailureType;
|
|
2
|
+
(function (FailureType) {
|
|
3
|
+
FailureType["Condition"] = "Condition";
|
|
4
|
+
FailureType["NoValue"] = "NoValue";
|
|
5
|
+
})(FailureType || (FailureType = {}));
|
|
6
|
+
const messageFormatter = (failureType, message, props) => {
|
|
7
|
+
const typeMap = {
|
|
8
|
+
[FailureType.Condition]: 'Assert condition failed',
|
|
9
|
+
[FailureType.NoValue]: 'Assert value not undefined/null failed',
|
|
10
|
+
};
|
|
11
|
+
const msg = typeMap[failureType] + (message ? `: ${message}` : '') + (props ? `: ${JSON.stringify(props)}` : '');
|
|
12
|
+
return msg;
|
|
13
|
+
};
|
|
14
|
+
const errorCreatorFactory = (formatter) => {
|
|
15
|
+
return (failureType, message, props) => new Error(formatter(failureType, message, props));
|
|
16
|
+
};
|
|
17
|
+
const defaultConfiguration = {
|
|
18
|
+
formatter: messageFormatter,
|
|
19
|
+
errorCreator: errorCreatorFactory(messageFormatter),
|
|
20
|
+
};
|
|
21
|
+
let configuration = defaultConfiguration;
|
|
22
|
+
/**
|
|
23
|
+
* Customize formatting of assertion failure messages, creation of failure Errors and reporting of failures
|
|
24
|
+
* @param custom
|
|
25
|
+
*/
|
|
26
|
+
export function configureAssert(custom) {
|
|
27
|
+
const newConfig = {
|
|
28
|
+
...configuration,
|
|
29
|
+
...custom,
|
|
30
|
+
};
|
|
31
|
+
newConfig.errorCreator = custom.errorCreator || errorCreatorFactory(newConfig.formatter);
|
|
32
|
+
configuration = newConfig;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* For test purpose
|
|
36
|
+
*/
|
|
37
|
+
export function testResetConfiguration() {
|
|
38
|
+
configuration = defaultConfiguration;
|
|
39
|
+
}
|
|
40
|
+
export const assert = (conditionOrValue, message, props) => {
|
|
41
|
+
if (typeof conditionOrValue === 'boolean') {
|
|
42
|
+
if (!conditionOrValue) {
|
|
43
|
+
const properties = typeof props === 'function' ? props() : props;
|
|
44
|
+
const error = configuration.errorCreator(FailureType.Condition, message, properties);
|
|
45
|
+
if (configuration.errorReporter) {
|
|
46
|
+
configuration.errorReporter(FailureType.Condition, error, message, properties);
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (typeof conditionOrValue === 'undefined' || conditionOrValue === null) {
|
|
53
|
+
const properties = typeof props === 'function' ? props() : props;
|
|
54
|
+
const error = configuration.errorCreator(FailureType.NoValue, message, properties);
|
|
55
|
+
if (configuration.errorReporter) {
|
|
56
|
+
configuration.errorReporter(FailureType.NoValue, error, message, properties);
|
|
57
|
+
}
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
return conditionOrValue;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/assert.ts"],"names":[],"mappings":"AAAA,IAAK,WAGJ;AAHD,WAAK,WAAW;IACd,sCAAuB,CAAA;IACvB,kCAAmB,CAAA;AACrB,CAAC,EAHI,WAAW,KAAX,WAAW,QAGf;AAwBD,MAAM,gBAAgB,GAAmB,CAAC,WAAwB,EAAE,OAAgB,EAAE,KAAc,EAAU,EAAE;IAC9G,MAAM,OAAO,GAAG;QACd,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,yBAAyB;QAClD,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,wCAAwC;KAChE,CAAC;IAEF,MAAM,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAEjH,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,CAAC,SAAyB,EAAgB,EAAE;IACtE,OAAO,CAAC,WAAwB,EAAE,OAAgB,EAAE,KAAc,EAAE,EAAE,CACpE,IAAI,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AACtD,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAA0B;IAClD,SAAS,EAAE,gBAAgB;IAC3B,YAAY,EAAE,mBAAmB,CAAC,gBAAgB,CAAC;CACpD,CAAC;AAEF,IAAI,aAAa,GAAG,oBAAoB,CAAC;AAEzC;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAA2B;IACzD,MAAM,SAAS,GAA0B;QACvC,GAAG,aAAa;QAChB,GAAG,MAAM;KACV,CAAC;IAEF,SAAS,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,mBAAmB,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAEzF,aAAa,GAAG,SAAS,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB;IACpC,aAAa,GAAG,oBAAoB,CAAC;AACvC,CAAC;AAsBD,MAAM,CAAC,MAAM,MAAM,GAAW,CAC5B,gBAAgD,EAChD,OAAgB,EAChB,KAA+B,EACrB,EAAE;IACZ,IAAI,OAAO,gBAAgB,KAAK,SAAS,EAAE,CAAC;QAC1C,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,MAAM,UAAU,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;YACjE,MAAM,KAAK,GAAG,aAAa,CAAC,YAAY,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;YAErF,IAAI,aAAa,CAAC,aAAa,EAAE,CAAC;gBAChC,aAAa,CAAC,aAAa,CAAC,WAAW,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;YACjF,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;QACD,OAAO;IACT,CAAC;IAED,IAAI,OAAO,gBAAgB,KAAK,WAAW,IAAI,gBAAgB,KAAK,IAAI,EAAE,CAAC;QACzE,MAAM,UAAU,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;QACjE,MAAM,KAAK,GAAG,aAAa,CAAC,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAEnF,IAAI,aAAa,CAAC,aAAa,EAAE,CAAC;YAChC,aAAa,CAAC,aAAa,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAC/E,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r;!function(r){r.Condition="Condition",r.NoValue="NoValue"}(r||(r={}));const o=(o,e,t)=>({[r.Condition]:"Assert condition failed",[r.NoValue]:"Assert value not undefined/null failed"}[o]+(e?`: ${e}`:"")+(t?`: ${JSON.stringify(t)}`:"")),e=r=>(o,e,t)=>new Error(r(o,e,t));let t={formatter:o,errorCreator:e(o)};function n(r){const o={...t,...r};o.errorCreator=r.errorCreator||e(o.formatter),t=o}const i=(o,e,n)=>{if("boolean"!=typeof o){if(null==o){const o="function"==typeof n?n():n,i=t.errorCreator(r.NoValue,e,o);throw t.errorReporter&&t.errorReporter(r.NoValue,i,e,o),i}return o}if(!o){const o="function"==typeof n?n():n,i=t.errorCreator(r.Condition,e,o);throw t.errorReporter&&t.errorReporter(r.Condition,i,e,o),i}};export{i as assert,n as configureAssert};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/assert.ts"],"sourcesContent":["enum FailureType {\n Condition = 'Condition',\n NoValue = 'NoValue',\n}\n\ntype ErrorFormatter = (failureType: FailureType, message?: string, props?: object) => string;\n\ntype ErrorCreator = (failureType: FailureType, message?: string, props?: object) => Error;\n\ntype ErrorReporter = (failureType: FailureType, error: Error, message?: string, props?: object) => void;\n\ntype WarningReporter = (failureType: FailureType, message?: string, props?: object) => void;\n\nexport type AssertConfiguration = {\n formatter?: ErrorFormatter;\n errorCreator?: ErrorCreator;\n errorReporter?: ErrorReporter;\n warningReporter?: WarningReporter;\n};\n\ntype RequiredConfiguration = {\n formatter: ErrorFormatter;\n errorCreator: ErrorCreator;\n errorReporter?: ErrorReporter;\n warningReporter?: WarningReporter;\n};\n\nconst messageFormatter: ErrorFormatter = (failureType: FailureType, message?: string, props?: object): string => {\n const typeMap = {\n [FailureType.Condition]: 'Assert condition failed',\n [FailureType.NoValue]: 'Assert value not undefined/null failed',\n };\n\n const msg = typeMap[failureType] + (message ? `: ${message}` : '') + (props ? `: ${JSON.stringify(props)}` : '');\n\n return msg;\n};\n\nconst errorCreatorFactory = (formatter: ErrorFormatter): ErrorCreator => {\n return (failureType: FailureType, message?: string, props?: object) =>\n new Error(formatter(failureType, message, props));\n};\n\nconst defaultConfiguration: RequiredConfiguration = {\n formatter: messageFormatter,\n errorCreator: errorCreatorFactory(messageFormatter),\n};\n\nlet configuration = defaultConfiguration;\n\n/**\n * Customize formatting of assertion failure messages, creation of failure Errors and reporting of failures\n * @param custom\n */\nexport function configureAssert(custom: AssertConfiguration): void {\n const newConfig: RequiredConfiguration = {\n ...configuration,\n ...custom,\n };\n\n newConfig.errorCreator = custom.errorCreator || errorCreatorFactory(newConfig.formatter);\n\n configuration = newConfig;\n}\n\n/**\n * For test purpose\n */\nexport function testResetConfiguration(): void {\n configuration = defaultConfiguration;\n}\n\ninterface Assert {\n /**\n * Verify that a condition is satisfied.\n * @param condition Condition to be true\n * @param message Error message\n * @param props Any props relevant.\n * @throws Throws exception if condition is false.\n */\n (condition: boolean, message?: string, props?: object | (() => object)): asserts condition;\n\n /**\n * Verify that an optional value actually has a proper value in this context, i.e. not null or undefined.\n * @param value Value to be verified\n * @param message Error message\n * @param props If message is a string id, format any matching key values into message. Props are also reported to dev team.\n * @throws Throws exception if value is null or undefined\n */\n <T>(value: T | undefined | null, message?: string, props?: object | (() => object)): T;\n}\n\nexport const assert: Assert = <T>(\n conditionOrValue: T | boolean | undefined | null,\n message?: string,\n props?: object | (() => object),\n): void | T => {\n if (typeof conditionOrValue === 'boolean') {\n if (!conditionOrValue) {\n const properties = typeof props === 'function' ? props() : props;\n const error = configuration.errorCreator(FailureType.Condition, message, properties);\n\n if (configuration.errorReporter) {\n configuration.errorReporter(FailureType.Condition, error, message, properties);\n }\n\n throw error;\n }\n return;\n }\n\n if (typeof conditionOrValue === 'undefined' || conditionOrValue === null) {\n const properties = typeof props === 'function' ? props() : props;\n const error = configuration.errorCreator(FailureType.NoValue, message, properties);\n\n if (configuration.errorReporter) {\n configuration.errorReporter(FailureType.NoValue, error, message, properties);\n }\n\n throw error;\n }\n\n return conditionOrValue;\n};\n"],"names":["FailureType","messageFormatter","failureType","message","props","Condition","NoValue","JSON","stringify","errorCreatorFactory","formatter","Error","configuration","errorCreator","configureAssert","custom","newConfig","assert","conditionOrValue","properties","error","errorReporter"],"mappings":"AAAA,IAAKA,GAAL,SAAKA,GACHA,EAAA,UAAA,YACAA,EAAA,QAAA,SACD,CAHD,CAAKA,IAAAA,EAGJ,CAAA,IAwBD,MAAMC,EAAmC,CAACC,EAA0BC,EAAkBC,KACpE,CACd,CAACJ,EAAYK,WAAY,0BACzB,CAACL,EAAYM,SAAU,0CAGLJ,IAAgBC,EAAU,KAAKA,IAAY,KAAOC,EAAQ,KAAKG,KAAKC,UAAUJ,KAAW,KAKzGK,EAAuBC,GACpB,CAACR,EAA0BC,EAAkBC,IAClD,IAAIO,MAAMD,EAAUR,EAAaC,EAASC,IAQ9C,IAAIQ,EALgD,CAClDF,UAAWT,EACXY,aAAcJ,EAAoBR,IAS9B,SAAUa,EAAgBC,GAC9B,MAAMC,EAAmC,IACpCJ,KACAG,GAGLC,EAAUH,aAAeE,EAAOF,cAAgBJ,EAAoBO,EAAUN,WAE9EE,EAAgBI,CAClB,CA6Ba,MAAAC,EAAiB,CAC5BC,EACAf,EACAC,KAEA,GAAgC,kBAArBc,EAAX,CAcA,GAAI,MAAOA,EAA+D,CACxE,MAAMC,EAA8B,mBAAVf,EAAuBA,IAAUA,EACrDgB,EAAQR,EAAcC,aAAab,EAAYM,QAASH,EAASgB,GAMvE,MAJIP,EAAcS,eAChBT,EAAcS,cAAcrB,EAAYM,QAASc,EAAOjB,EAASgB,GAG7DC,CACP,CAED,OAAOF,CAbN,CAXC,IAAKA,EAAkB,CACrB,MAAMC,EAA8B,mBAAVf,EAAuBA,IAAUA,EACrDgB,EAAQR,EAAcC,aAAab,EAAYK,UAAWF,EAASgB,GAMzE,MAJIP,EAAcS,eAChBT,EAAcS,cAAcrB,EAAYK,UAAWe,EAAOjB,EAASgB,GAG/DC,CACP,CAeoB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2021.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2022.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2023.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2021.string.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2022.array.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2022.error.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2022.object.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2022.string.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2023.array.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es2023.collection.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../node_modules/@types/react/global.d.ts","../../../node_modules/@types/prop-types/index.d.ts","../../../node_modules/@types/scheduler/tracing.d.ts","../../../node_modules/@types/react/index.d.ts","../../../node_modules/@types/react/jsx-runtime.d.ts","../src/assert.ts","../src/index.ts","../../../node_modules/@types/node/assert.d.ts","../../../node_modules/@types/node/assert/strict.d.ts","../../../node_modules/@types/node/globals.d.ts","../../../node_modules/@types/node/async_hooks.d.ts","../../../node_modules/@types/node/buffer.d.ts","../../../node_modules/@types/node/child_process.d.ts","../../../node_modules/@types/node/cluster.d.ts","../../../node_modules/@types/node/console.d.ts","../../../node_modules/@types/node/constants.d.ts","../../../node_modules/@types/node/crypto.d.ts","../../../node_modules/@types/node/dgram.d.ts","../../../node_modules/@types/node/diagnostics_channel.d.ts","../../../node_modules/@types/node/dns.d.ts","../../../node_modules/@types/node/dns/promises.d.ts","../../../node_modules/@types/node/domain.d.ts","../../../node_modules/@types/node/dom-events.d.ts","../../../node_modules/@types/node/events.d.ts","../../../node_modules/@types/node/fs.d.ts","../../../node_modules/@types/node/fs/promises.d.ts","../../../node_modules/@types/node/http.d.ts","../../../node_modules/@types/node/http2.d.ts","../../../node_modules/@types/node/https.d.ts","../../../node_modules/@types/node/inspector.d.ts","../../../node_modules/@types/node/module.d.ts","../../../node_modules/@types/node/net.d.ts","../../../node_modules/@types/node/os.d.ts","../../../node_modules/@types/node/path.d.ts","../../../node_modules/@types/node/perf_hooks.d.ts","../../../node_modules/@types/node/process.d.ts","../../../node_modules/@types/node/punycode.d.ts","../../../node_modules/@types/node/querystring.d.ts","../../../node_modules/@types/node/readline.d.ts","../../../node_modules/@types/node/readline/promises.d.ts","../../../node_modules/@types/node/repl.d.ts","../../../node_modules/@types/node/stream.d.ts","../../../node_modules/@types/node/stream/promises.d.ts","../../../node_modules/@types/node/stream/consumers.d.ts","../../../node_modules/@types/node/stream/web.d.ts","../../../node_modules/@types/node/string_decoder.d.ts","../../../node_modules/@types/node/test.d.ts","../../../node_modules/@types/node/timers.d.ts","../../../node_modules/@types/node/timers/promises.d.ts","../../../node_modules/@types/node/tls.d.ts","../../../node_modules/@types/node/trace_events.d.ts","../../../node_modules/@types/node/tty.d.ts","../../../node_modules/@types/node/url.d.ts","../../../node_modules/@types/node/util.d.ts","../../../node_modules/@types/node/v8.d.ts","../../../node_modules/@types/node/vm.d.ts","../../../node_modules/@types/node/wasi.d.ts","../../../node_modules/@types/node/worker_threads.d.ts","../../../node_modules/@types/node/zlib.d.ts","../../../node_modules/@types/node/globals.global.d.ts","../../../node_modules/@types/node/index.d.ts","../node_modules/@cutting/useful-types/global.d.ts"],"fileInfos":[{"version":"f33e5332b24c3773e930e212cbb8b6867c8ba3ec4492064ea78e55a524d57450","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","26f2f787e82c4222710f3b676b4d83eb5ad0a72fa7b746f03449e7a026ce5073","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","1c0cdb8dc619bc549c3e5020643e7cf7ae7940058e8c7e5aefa5871b6d86f44b",{"version":"21e41a76098aa7a191028256e52a726baafd45a925ea5cf0222eb430c96c1d83","affectsGlobalScope":true},{"version":"138fb588d26538783b78d1e3b2c2cc12d55840b97bf5e08bca7f7a174fbe2f17","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"e0275cd0e42990dc3a16f0b7c8bca3efe87f1c8ad404f80c6db1c7c0b828c59f","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"49ed889be54031e1044af0ad2c603d627b8bda8b50c1a68435fe85583901d072","affectsGlobalScope":true},{"version":"e93d098658ce4f0c8a0779e6cab91d0259efb88a318137f686ad76f8410ca270","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"ec0104fee478075cb5171e5f4e3f23add8e02d845ae0165bfa3f1099241fa2aa","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"acae90d417bee324b1372813b5a00829d31c7eb670d299cd7f8f9a648ac05688","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"51e547984877a62227042850456de71a5c45e7fe86b7c975c6e68896c86fa23b","affectsGlobalScope":true},{"version":"62a4966981264d1f04c44eb0f4b5bdc3d81c1a54725608861e44755aa24ad6a5","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"86a34c7a13de9cabc43161348f663624b56871ed80986e41d214932ddd8d6719","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"08a58483392df5fcc1db57d782e87734f77ae9eab42516028acbfe46f29a3ef7","affectsGlobalScope":true},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true},{"version":"13f6e6380c78e15e140243dc4be2fa546c287c6d61f4729bc2dd7cf449605471","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},{"version":"0bd5e7096c7bc02bf70b2cc017fc45ef489cb19bd2f32a71af39ff5787f1b56a","affectsGlobalScope":true},"9ed09d4538e25fc79cefc5e7b5bfbae0464f06d2984f19da009f85d13656c211","b1bf87add0ccfb88472cd4c6013853d823a7efb791c10bb7a11679526be91eda",{"version":"7e3e6aab4fe52daa91a7ee0f368ad9a5e1d4420a7f48c12a46820c80fbbfebcb","affectsGlobalScope":true},"2879a055439b6c0c0132a1467120a0f85b56b5d735c973ad235acd958b1b5345",{"version":"d58b6ad87b60170f9681fe4083cad7700bcab9070c93673b908dc6b1983c1510","signature":"0ce55cc15a65cb9a2b00f7d642e924ff505b8f07017dbaa4e278b41bbfb641ca"},"d9649af94d695b460add313a79df1633854af63845a6db4b00910884f71230fc","efc7d584a33fe3422847783d228f315c4cd1afe74bd7cf8e3f0e4c1125129fef","7394959e5a741b185456e1ef5d64599c36c60a323207450991e7a42e08911419",{"version":"a14ed46fa3f5ffc7a8336b497cd07b45c2084213aaca933a22443fcb2eef0d07","affectsGlobalScope":true},"cce1f5f86974c1e916ec4a8cab6eec9aa8e31e8148845bf07fbaa8e1d97b1a2c",{"version":"e2eb1ce13a9c0fa7ab62c63909d81973ef4b707292667c64f1e25e6e53fa7afa","affectsGlobalScope":true},"16d74fe4d8e183344d3beb15d48b123c5980ff32ff0cc8c3b96614ddcdf9b239","7b43160a49cf2c6082da0465876c4a0b164e160b81187caeb0a6ca7a281e85ba",{"version":"41fb2a1c108fbf46609ce5a451b7ec78eb9b5ada95fd5b94643e4b26397de0b3","affectsGlobalScope":true},"a40826e8476694e90da94aa008283a7de50d1dafd37beada623863f1901cb7fb","91073e48c8e2833110f328848b2c298425bd596a332107f248de6f28b2311f5e","bd3f5d05b6b5e4bfcea7739a45f3ffb4a7f4a3442ba7baf93e0200799285b8f1","4c775c2fccabf49483c03cd5e3673f87c1ffb6079d98e7b81089c3def79e29c6","8806ae97308ef26363bd7ec8071bca4d07fb575f905ee3d8a91aff226df6d618","af5bf1db6f1804fb0069039ae77a05d60133c77a2158d9635ea27b6bb2828a8f","b7fe70be794e13d1b7940e318b8770cd1fb3eced7707805318a2e3aaac2c3e9e",{"version":"2c71199d1fc83bf17636ad5bf63a945633406b7b94887612bba4ef027c662b3e","affectsGlobalScope":true},{"version":"7ae9dc7dbb58cd843065639707815df85c044babaa0947116f97bdb824d07204","affectsGlobalScope":true},"7aae1df2053572c2cfc2089a77847aadbb38eedbaa837a846c6a49fb37c6e5bd","313a0b063f5188037db113509de1b934a0e286f14e9479af24fada241435e707","f1ace2d2f98429e007d017c7a445efad2aaebf8233135abdb2c88b8c0fef91ab","87ef1a23caa071b07157c72077fa42b86d30568f9dc9e31eed24d5d14fc30ba8","396a8939b5e177542bdf9b5262b4eee85d29851b2d57681fa9d7eae30e225830","21773f5ac69ddf5a05636ba1f50b5239f4f2d27e4420db147fc2f76a5ae598ac",{"version":"1b6d2b76e8a526c7e26f96df0f4fb49510b281597dbf95225c231781fa2d1614","affectsGlobalScope":true},"a5fe4cc622c3bf8e09ababde5f4096ceac53163eefcd95e9cd53f062ff9bb67a","45b1053e691c5af9bfe85060a3e1542835f8d84a7e6e2e77ca305251eda0cb3c","0f05c06ff6196958d76b865ae17245b52d8fe01773626ac3c43214a2458ea7b7",{"version":"ae5507fc333d637dec9f37c6b3f4d423105421ea2820a64818de55db85214d66","affectsGlobalScope":true},{"version":"9335b283875185dc274fe8ad30989fdfc5bd9772efbe1d6e4ec72044a3f1a46a","affectsGlobalScope":true},"8abd0566d2854c4bd1c5e48e05df5c74927187f1541e6770001d9637ac41542e","54e854615c4eafbdd3fd7688bd02a3aafd0ccf0e87c98f79d3e9109f047ce6b8","d8dba11dc34d50cb4202de5effa9a1b296d7a2f4a029eec871f894bddfb6430d","8b71dd18e7e63b6f991b511a201fad7c3bf8d1e0dd98acb5e3d844f335a73634","01d8e1419c84affad359cc240b2b551fb9812b450b4d3d456b64cda8102d4f60","8221b00f271cf7f535a8eeec03b0f80f0929c7a16116e2d2df089b41066de69b","269929a24b2816343a178008ac9ae9248304d92a8ba8e233055e0ed6dbe6ef71","93452d394fdd1dc551ec62f5042366f011a00d342d36d50793b3529bfc9bd633","f8c87b19eae111f8720b0345ab301af8d81add39621b63614dfc2d15fd6f140a","831c22d257717bf2cbb03afe9c4bcffc5ccb8a2074344d4238bf16d3a857bb12",{"version":"f325631e35c2bc4815911085c55e21109b7c500d8e467524252363bd859f6e50","affectsGlobalScope":true},{"version":"7052b7b0c3829df3b4985bab2fd74531074b4835d5a7b263b75c82f0916ad62f","affectsGlobalScope":true},"aa34c3aa493d1c699601027c441b9664547c3024f9dbab1639df7701d63d18fa","eefcdf86cefff36e5d87de36a3638ab5f7d16c2b68932be4a72c14bb924e43c1","7c651f8dce91a927ab62925e73f190763574c46098f2b11fb8ddc1b147a6709a","7440ab60f4cb031812940cc38166b8bb6fbf2540cfe599f87c41c08011f0c1df",{"version":"4d0405568cf6e0ff36a4861c4a77e641366feaefa751600b0a4d12a5e8f730a8","affectsGlobalScope":true},{"version":"f5b5dc128973498b75f52b1b8c2d5f8629869104899733ae485100c2309b4c12","affectsGlobalScope":true},"e393915d3dc385e69c0e2390739c87b2d296a610662eb0b1cb85224e55992250","79bad8541d5779c85e82a9fb119c1fe06af77a71cc40f869d62ad379473d4b75","8013f6c4d1632da8f1c4d3d702ae559acccd0f1be05360c31755f272587199c9",{"version":"629d20681ca284d9e38c0a019f647108f5fe02f9c59ac164d56f5694fc3faf4d","affectsGlobalScope":true},"e7dbf5716d76846c7522e910896c5747b6df1abd538fee8f5291bdc843461795",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"b510d0a18e3db42ac9765d26711083ec1e8b4e21caaca6dc4d25ae6e8623f447",{"version":"91512354f8ca683a0a760d8f7e4ecaa2418b58b0a007d864ba0013751f484a78","affectsGlobalScope":true}],"root":[67,68],"options":{"checkJs":false,"composite":true,"declaration":true,"declarationMap":true,"downlevelIteration":true,"esModuleInterop":true,"jsx":4,"module":7,"noFallthroughCasesInSwitch":true,"noUnusedLocals":true,"outDir":"./esm","removeComments":false,"rootDir":"../src","skipLibCheck":true,"sourceMap":true,"strict":true,"target":9},"fileIdsList":[[69],[72],[73,78,106],[74,85,86,93,103,114],[74,75,85,93],[76,115],[77,78,86,94],[78,103,111],[79,81,85,93],[72,80],[81,82],[85],[83,85],[72,85],[85,86,87,103,114],[85,86,87,100,103,106],[73,119],[81,85,88,93,103,114],[85,86,88,89,93,103,111,114],[88,90,103,111,114],[69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121],[85,91],[92,114,119],[81,85,93,103],[94],[95],[72,96],[97,113,119],[98],[99],[85,100,101],[100,102,115,117],[73,85,103,104,105,106],[73,103,105],[103,104],[106],[107],[72,103],[85,109,110],[109,110],[78,93,103,111],[112],[93,113],[73,88,99,114],[78,115],[103,116],[92,117],[118],[73,78,85,87,96,103,114,117,119],[103,120],[62,63,64],[65],[66],[66,67]],"referencedMap":[[69,1],[70,1],[72,2],[73,3],[74,4],[75,5],[76,6],[77,7],[78,8],[79,9],[80,10],[81,11],[82,11],[84,12],[83,13],[85,14],[86,15],[87,16],[71,17],[88,18],[89,19],[90,20],[122,21],[91,22],[92,23],[93,24],[94,25],[95,26],[96,27],[97,28],[98,29],[99,30],[100,31],[101,31],[102,32],[103,33],[105,34],[104,35],[106,36],[107,37],[108,38],[109,39],[110,40],[111,41],[112,42],[113,43],[114,44],[115,45],[116,46],[117,47],[118,48],[119,49],[120,50],[65,51],[66,52],[67,53],[68,54]],"exportedModulesMap":[[69,1],[70,1],[72,2],[73,3],[74,4],[75,5],[76,6],[77,7],[78,8],[79,9],[80,10],[81,11],[82,11],[84,12],[83,13],[85,14],[86,15],[87,16],[71,17],[88,18],[89,19],[90,20],[122,21],[91,22],[92,23],[93,24],[94,25],[95,26],[96,27],[97,28],[98,29],[99,30],[100,31],[101,31],[102,32],[103,33],[105,34],[104,35],[106,36],[107,37],[108,38],[109,39],[110,40],[111,41],[112,42],[113,43],[114,44],[115,45],[116,46],[117,47],[118,48],[119,49],[120,50],[65,51],[66,52],[68,54]],"semanticDiagnosticsPerFile":[60,61,11,13,12,2,14,15,16,17,18,19,20,21,3,4,22,26,23,24,25,27,28,29,5,30,31,32,33,6,37,34,35,36,38,7,39,44,45,40,41,42,43,8,49,46,47,48,50,9,51,52,53,56,54,55,57,58,10,1,59,69,70,72,73,74,75,76,77,78,79,80,81,82,84,83,85,86,87,71,121,88,89,90,122,91,92,93,94,95,96,97,98,99,100,101,102,103,105,104,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,63,62,65,66,64,123,67,68],"latestChangedDtsFile":"./esm/index.d.ts"},"version":"5.3.3"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cutting/assert",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/dagda1/cuttingedge.git"
|
|
8
|
+
},
|
|
9
|
+
"types": "dist/esm/index.d.ts",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@typescript-eslint/parser": "6.16.0",
|
|
14
|
+
"@typescript-eslint/eslint-plugin": "6.16.0",
|
|
15
|
+
"eslint": "8.56.0",
|
|
16
|
+
"typescript": "5.3.3",
|
|
17
|
+
"@cutting/devtools": "4.63.5",
|
|
18
|
+
"@cutting/eslint-config": "4.45.3",
|
|
19
|
+
"@cutting/tsconfig": "4.40.4",
|
|
20
|
+
"@cutting/useful-types": "4.40.2"
|
|
21
|
+
},
|
|
22
|
+
"volta": {
|
|
23
|
+
"extends": "../../package.json"
|
|
24
|
+
},
|
|
25
|
+
"module": "dist/esm/index.js",
|
|
26
|
+
"exports": {
|
|
27
|
+
"types": "./dist/esm/index.d.ts",
|
|
28
|
+
"import": "./dist/esm/index.js"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "NODE_ENV=production devtools rollup",
|
|
32
|
+
"lint": "eslint ./src/**/*.ts --fix",
|
|
33
|
+
"test": "NODE_ENV=test vitest",
|
|
34
|
+
"test:ci": "CI=true pnpm test"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, beforeAll, it, expect } from 'vitest';
|
|
2
|
+
import { assert, configureAssert } from './assert';
|
|
3
|
+
const logHistory: string[] = [];
|
|
4
|
+
const log = (msg: string) => logHistory.push(msg);
|
|
5
|
+
|
|
6
|
+
describe('assert', () => {
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
configureAssert({
|
|
9
|
+
errorReporter: (failureType, error, message, props) => {
|
|
10
|
+
log(`ERROR: ${failureType}, ${error}, ${message}: ${props}`);
|
|
11
|
+
},
|
|
12
|
+
warningReporter: (failureType, message, props) => {
|
|
13
|
+
log(`WARNING: ${failureType}, ${message}: ${props}`);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('assert', () => {
|
|
19
|
+
it('assert true should not fail', () => {
|
|
20
|
+
expect(() => assert(true)).not.toThrowError();
|
|
21
|
+
});
|
|
22
|
+
it('assert false should fail', () => {
|
|
23
|
+
expect(() => assert(false)).toThrowError();
|
|
24
|
+
});
|
|
25
|
+
it('assert undefiined should fail', () => {
|
|
26
|
+
expect(() => assert(undefined)).toThrowError();
|
|
27
|
+
});
|
|
28
|
+
it('assert null should fail', () => {
|
|
29
|
+
expect(() => assert(null)).toThrowError();
|
|
30
|
+
});
|
|
31
|
+
it('assert an empty string should not fail', () => {
|
|
32
|
+
expect(() => assert('')).not.toThrowError();
|
|
33
|
+
});
|
|
34
|
+
it('assert a non-empty string should not fail', () => {
|
|
35
|
+
expect(() => assert('string')).not.toThrowError();
|
|
36
|
+
});
|
|
37
|
+
it('assert an empty array should not fail', () => {
|
|
38
|
+
expect(() => assert([])).not.toThrowError();
|
|
39
|
+
});
|
|
40
|
+
it('assert a non-empty array should not fail', () => {
|
|
41
|
+
expect(() => assert([5])).not.toThrowError();
|
|
42
|
+
});
|
|
43
|
+
it('assert an empty object should not fail', () => {
|
|
44
|
+
expect(() => assert({})).not.toThrowError();
|
|
45
|
+
});
|
|
46
|
+
it('assert a non-empty object should not fail', () => {
|
|
47
|
+
expect(() => assert({ n: 5 })).not.toThrowError();
|
|
48
|
+
});
|
|
49
|
+
it('assert 0 should not fail', () => {
|
|
50
|
+
expect(() => assert(0)).not.toThrowError();
|
|
51
|
+
});
|
|
52
|
+
it('assert 1 should not fail', () => {
|
|
53
|
+
expect(() => assert(1)).not.toThrowError();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
package/src/assert.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
enum FailureType {
|
|
2
|
+
Condition = 'Condition',
|
|
3
|
+
NoValue = 'NoValue',
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
type ErrorFormatter = (failureType: FailureType, message?: string, props?: object) => string;
|
|
7
|
+
|
|
8
|
+
type ErrorCreator = (failureType: FailureType, message?: string, props?: object) => Error;
|
|
9
|
+
|
|
10
|
+
type ErrorReporter = (failureType: FailureType, error: Error, message?: string, props?: object) => void;
|
|
11
|
+
|
|
12
|
+
type WarningReporter = (failureType: FailureType, message?: string, props?: object) => void;
|
|
13
|
+
|
|
14
|
+
export type AssertConfiguration = {
|
|
15
|
+
formatter?: ErrorFormatter;
|
|
16
|
+
errorCreator?: ErrorCreator;
|
|
17
|
+
errorReporter?: ErrorReporter;
|
|
18
|
+
warningReporter?: WarningReporter;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type RequiredConfiguration = {
|
|
22
|
+
formatter: ErrorFormatter;
|
|
23
|
+
errorCreator: ErrorCreator;
|
|
24
|
+
errorReporter?: ErrorReporter;
|
|
25
|
+
warningReporter?: WarningReporter;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const messageFormatter: ErrorFormatter = (failureType: FailureType, message?: string, props?: object): string => {
|
|
29
|
+
const typeMap = {
|
|
30
|
+
[FailureType.Condition]: 'Assert condition failed',
|
|
31
|
+
[FailureType.NoValue]: 'Assert value not undefined/null failed',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const msg = typeMap[failureType] + (message ? `: ${message}` : '') + (props ? `: ${JSON.stringify(props)}` : '');
|
|
35
|
+
|
|
36
|
+
return msg;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const errorCreatorFactory = (formatter: ErrorFormatter): ErrorCreator => {
|
|
40
|
+
return (failureType: FailureType, message?: string, props?: object) =>
|
|
41
|
+
new Error(formatter(failureType, message, props));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const defaultConfiguration: RequiredConfiguration = {
|
|
45
|
+
formatter: messageFormatter,
|
|
46
|
+
errorCreator: errorCreatorFactory(messageFormatter),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
let configuration = defaultConfiguration;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Customize formatting of assertion failure messages, creation of failure Errors and reporting of failures
|
|
53
|
+
* @param custom
|
|
54
|
+
*/
|
|
55
|
+
export function configureAssert(custom: AssertConfiguration): void {
|
|
56
|
+
const newConfig: RequiredConfiguration = {
|
|
57
|
+
...configuration,
|
|
58
|
+
...custom,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
newConfig.errorCreator = custom.errorCreator || errorCreatorFactory(newConfig.formatter);
|
|
62
|
+
|
|
63
|
+
configuration = newConfig;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* For test purpose
|
|
68
|
+
*/
|
|
69
|
+
export function testResetConfiguration(): void {
|
|
70
|
+
configuration = defaultConfiguration;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface Assert {
|
|
74
|
+
/**
|
|
75
|
+
* Verify that a condition is satisfied.
|
|
76
|
+
* @param condition Condition to be true
|
|
77
|
+
* @param message Error message
|
|
78
|
+
* @param props Any props relevant.
|
|
79
|
+
* @throws Throws exception if condition is false.
|
|
80
|
+
*/
|
|
81
|
+
(condition: boolean, message?: string, props?: object | (() => object)): asserts condition;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Verify that an optional value actually has a proper value in this context, i.e. not null or undefined.
|
|
85
|
+
* @param value Value to be verified
|
|
86
|
+
* @param message Error message
|
|
87
|
+
* @param props If message is a string id, format any matching key values into message. Props are also reported to dev team.
|
|
88
|
+
* @throws Throws exception if value is null or undefined
|
|
89
|
+
*/
|
|
90
|
+
<T>(value: T | undefined | null, message?: string, props?: object | (() => object)): T;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const assert: Assert = <T>(
|
|
94
|
+
conditionOrValue: T | boolean | undefined | null,
|
|
95
|
+
message?: string,
|
|
96
|
+
props?: object | (() => object),
|
|
97
|
+
): void | T => {
|
|
98
|
+
if (typeof conditionOrValue === 'boolean') {
|
|
99
|
+
if (!conditionOrValue) {
|
|
100
|
+
const properties = typeof props === 'function' ? props() : props;
|
|
101
|
+
const error = configuration.errorCreator(FailureType.Condition, message, properties);
|
|
102
|
+
|
|
103
|
+
if (configuration.errorReporter) {
|
|
104
|
+
configuration.errorReporter(FailureType.Condition, error, message, properties);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (typeof conditionOrValue === 'undefined' || conditionOrValue === null) {
|
|
113
|
+
const properties = typeof props === 'function' ? props() : props;
|
|
114
|
+
const error = configuration.errorCreator(FailureType.NoValue, message, properties);
|
|
115
|
+
|
|
116
|
+
if (configuration.errorReporter) {
|
|
117
|
+
configuration.errorReporter(FailureType.NoValue, error, message, properties);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return conditionOrValue;
|
|
124
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { configureAssert, assert } from './assert';
|
package/tsconfig.json
ADDED
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import react from '@vitejs/plugin-react';
|
|
2
|
+
import { defineConfig } from 'vitest/config';
|
|
3
|
+
|
|
4
|
+
// https://vitejs.dev/config/
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [react()],
|
|
7
|
+
test: {
|
|
8
|
+
globals: true,
|
|
9
|
+
environment: 'jsdom',
|
|
10
|
+
setupFiles: '@cutting/devtools/setuptests',
|
|
11
|
+
css: true,
|
|
12
|
+
},
|
|
13
|
+
});
|