@davidsouther/jiffies 2.2.4 → 2.3.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.
- package/LICENSE +1 -1
- package/lib/cjs/assert.d.ts +2 -2
- package/lib/cjs/awaitable.d.ts +1 -1
- package/lib/cjs/components/button_bar.d.ts +2 -2
- package/lib/cjs/components/inline_edit.d.ts +2 -2
- package/lib/cjs/components/logger.d.ts +1 -1
- package/lib/cjs/components/select.d.ts +4 -7
- package/lib/cjs/components/test.d.ts +1 -1
- package/lib/cjs/components/virtual_scroll.d.ts +6 -4
- package/lib/cjs/context.d.ts +5 -9
- package/lib/cjs/debounce.d.ts +1 -1
- package/lib/cjs/diff.d.ts +2 -2
- package/lib/cjs/display.d.ts +1 -1
- package/lib/cjs/dom/css/border.d.ts +2 -2
- package/lib/cjs/dom/css/constants.d.ts +3 -3
- package/lib/cjs/dom/css/core.d.ts +1 -1
- package/lib/cjs/dom/css/fstyle.d.ts +2 -2
- package/lib/cjs/dom/css/sizing.d.ts +2 -2
- package/lib/cjs/dom/dom.d.ts +8 -8
- package/lib/cjs/dom/fc.d.ts +8 -12
- package/lib/cjs/dom/form/form.d.ts +5 -6
- package/lib/cjs/dom/html.d.ts +112 -113
- package/lib/cjs/dom/observable.d.ts +1 -1
- package/lib/cjs/dom/provide.d.ts +1 -1
- package/lib/cjs/dom/router/router.d.ts +2 -2
- package/lib/cjs/dom/svg.d.ts +64 -64
- package/lib/cjs/dom/types/css.d.ts +10 -32
- package/lib/cjs/dom/types/html.d.ts +4 -6
- package/lib/cjs/equal.d.ts +8 -5
- package/lib/cjs/flags.d.ts +1 -1
- package/lib/cjs/fs.d.ts +3 -3
- package/lib/cjs/fs_node.d.ts +1 -1
- package/lib/cjs/lock.d.ts +1 -1
- package/lib/cjs/log.d.ts +9 -9
- package/lib/cjs/observable/event.d.ts +2 -2
- package/lib/cjs/observable/observable.d.ts +37 -35
- package/lib/cjs/result.d.ts +21 -21
- package/lib/cjs/safe.d.ts +1 -1
- package/lib/cjs/scope/describe.d.ts +4 -4
- package/lib/cjs/scope/display/console.d.ts +1 -1
- package/lib/cjs/scope/display/dom.d.ts +2 -2
- package/lib/cjs/scope/display/junit.d.ts +1 -1
- package/lib/cjs/scope/execute.d.ts +2 -2
- package/lib/cjs/scope/index.d.ts +3 -3
- package/lib/cjs/scope/scope.d.ts +3 -3
- package/lib/cjs/scope/state.d.ts +1 -1
- package/lib/cjs/server/http/apps.d.ts +1 -1
- package/lib/cjs/server/http/css.d.ts +1 -1
- package/lib/cjs/server/http/index.d.ts +4 -9
- package/lib/cjs/server/http/response.d.ts +3 -3
- package/lib/cjs/server/http/sitemap.d.ts +1 -1
- package/lib/cjs/server/http/static.d.ts +1 -1
- package/lib/cjs/server/http/typescript.d.ts +1 -1
- package/lib/cjs/test_all.d.ts +9 -9
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/assert.d.ts +2 -2
- package/lib/esm/awaitable.d.ts +1 -1
- package/lib/esm/components/button_bar.d.ts +2 -2
- package/lib/esm/components/inline_edit.d.ts +2 -2
- package/lib/esm/components/logger.d.ts +1 -1
- package/lib/esm/components/select.d.ts +3 -3
- package/lib/esm/components/test.d.ts +1 -1
- package/lib/esm/components/virtual_scroll.d.ts +6 -4
- package/lib/esm/context.d.ts +5 -9
- package/lib/esm/debounce.d.ts +1 -2
- package/lib/esm/diff.d.ts +2 -2
- package/lib/esm/display.d.ts +1 -1
- package/lib/esm/dom/css/border.d.ts +2 -2
- package/lib/esm/dom/css/constants.d.ts +3 -3
- package/lib/esm/dom/css/core.d.ts +1 -1
- package/lib/esm/dom/css/fstyle.d.ts +2 -2
- package/lib/esm/dom/css/sizing.d.ts +2 -2
- package/lib/esm/dom/dom.d.ts +8 -8
- package/lib/esm/dom/fc.d.ts +8 -12
- package/lib/esm/dom/form/form.d.ts +5 -6
- package/lib/esm/dom/html.d.ts +112 -113
- package/lib/esm/dom/observable.d.ts +1 -1
- package/lib/esm/dom/provide.d.ts +1 -1
- package/lib/esm/dom/router/router.d.ts +2 -2
- package/lib/esm/dom/svg.d.ts +64 -64
- package/lib/esm/dom/types/css.d.ts +10 -32
- package/lib/esm/dom/types/html.d.ts +4 -6
- package/lib/esm/equal.d.ts +8 -5
- package/lib/esm/flags.d.ts +1 -1
- package/lib/esm/fs.d.ts +3 -3
- package/lib/esm/fs_node.d.ts +1 -1
- package/lib/esm/lock.d.ts +1 -1
- package/lib/esm/log.d.ts +9 -9
- package/lib/esm/observable/event.d.ts +2 -2
- package/lib/esm/observable/observable.d.ts +37 -35
- package/lib/esm/result.d.ts +21 -21
- package/lib/esm/safe.d.ts +1 -1
- package/lib/esm/scope/describe.d.ts +4 -4
- package/lib/esm/scope/display/console.d.ts +1 -1
- package/lib/esm/scope/display/dom.d.ts +2 -2
- package/lib/esm/scope/display/junit.d.ts +1 -1
- package/lib/esm/scope/execute.d.ts +2 -2
- package/lib/esm/scope/index.d.ts +3 -3
- package/lib/esm/scope/scope.d.ts +3 -3
- package/lib/esm/scope/state.d.ts +1 -1
- package/lib/esm/server/http/apps.d.ts +1 -1
- package/lib/esm/server/http/css.d.ts +1 -1
- package/lib/esm/server/http/index.d.ts +4 -9
- package/lib/esm/server/http/response.d.ts +3 -3
- package/lib/esm/server/http/sitemap.d.ts +1 -1
- package/lib/esm/server/http/static.d.ts +1 -1
- package/lib/esm/server/http/typescript.d.ts +1 -1
- package/lib/esm/test_all.d.ts +9 -9
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -9
- package/src/assert.ts +5 -5
- package/src/components/button_bar.ts +28 -30
- package/src/components/inline_edit.ts +8 -7
- package/src/components/logger.ts +6 -6
- package/src/components/select.ts +7 -7
- package/src/components/test.ts +5 -0
- package/src/components/virtual_scroll.test.ts +9 -6
- package/src/components/virtual_scroll.ts +29 -24
- package/src/context.test.ts +4 -4
- package/src/context.ts +16 -11
- package/src/debounce.ts +9 -3
- package/src/diff.test.ts +4 -4
- package/src/diff.ts +14 -16
- package/src/dom/css/border.ts +11 -11
- package/src/dom/css/core.ts +1 -1
- package/src/dom/css/fstyle.ts +4 -4
- package/src/dom/css/sizing.ts +1 -1
- package/src/dom/dom.ts +57 -47
- package/src/dom/fc.test.ts +8 -8
- package/src/dom/fc.ts +32 -35
- package/src/dom/form/form.app.ts +9 -9
- package/src/dom/form/form.ts +25 -16
- package/src/dom/form/index.html +3 -2
- package/src/dom/html.test.ts +12 -10
- package/src/dom/html.ts +2 -3
- package/src/dom/observable.test.ts +6 -6
- package/src/dom/observable.ts +2 -2
- package/src/dom/provide.ts +1 -1
- package/src/dom/router/link.ts +3 -3
- package/src/dom/router/router.ts +5 -5
- package/src/dom/svg.ts +7 -6
- package/src/dom/test.ts +3 -0
- package/src/dom/types/css.ts +43 -61
- package/src/dom/types/html.ts +2 -4
- package/src/dom/xml.ts +2 -2
- package/src/equal.test.ts +3 -3
- package/src/equal.ts +27 -14
- package/src/flags.test.ts +2 -2
- package/src/flags.ts +2 -2
- package/src/fs.test.ts +5 -5
- package/src/fs.ts +26 -20
- package/src/fs_node.ts +4 -4
- package/src/fs_win.test.ts +1 -1
- package/src/generator.test.ts +4 -3
- package/src/generator.ts +1 -1
- package/src/hooks/_notes +4 -1
- package/src/index.html +7 -7
- package/src/lock.test.ts +4 -4
- package/src/lock.ts +8 -7
- package/src/log.ts +28 -18
- package/src/observable/event.ts +7 -7
- package/src/observable/observable.test.ts +3 -3
- package/src/observable/observable.ts +71 -52
- package/src/result.test.ts +7 -10
- package/src/result.ts +51 -47
- package/src/safe.ts +1 -1
- package/src/scope/describe.ts +12 -11
- package/src/scope/display/console.ts +4 -4
- package/src/scope/display/dom.ts +9 -9
- package/src/scope/display/junit.ts +21 -24
- package/src/scope/execute.ts +17 -12
- package/src/scope/expect.ts +22 -22
- package/src/scope/fix.ts +10 -7
- package/src/scope/index.ts +3 -3
- package/src/scope/scope.ts +2 -2
- package/src/scope/state.ts +2 -2
- package/src/server/http/apps.ts +5 -5
- package/src/server/http/css.ts +10 -26
- package/src/server/http/index.ts +30 -24
- package/src/server/http/response.ts +12 -5
- package/src/server/http/sitemap.ts +8 -8
- package/src/server/http/static.ts +9 -6
- package/src/server/http/typescript.ts +25 -25
- package/src/server/main.ts +7 -4
- package/src/test.mjs +8 -8
- package/src/test_all.ts +16 -13
- package/src/transpile.mjs +6 -18
- package/build/pico.css +0 -2466
- package/build/pico.css.map +0 -1
- package/lib/cjs/assert.js +0 -46
- package/lib/cjs/awaitable.js +0 -2
- package/lib/cjs/case.js +0 -9
- package/lib/cjs/components/button_bar.js +0 -29
- package/lib/cjs/components/inline_edit.js +0 -51
- package/lib/cjs/components/logger.js +0 -27
- package/lib/cjs/components/select.js +0 -6
- package/lib/cjs/components/test.js +0 -7
- package/lib/cjs/components/virtual_scroll.js +0 -102
- package/lib/cjs/components/virtual_scroll.test.js +0 -22
- package/lib/cjs/context.js +0 -48
- package/lib/cjs/context.test.js +0 -48
- package/lib/cjs/debounce.js +0 -12
- package/lib/cjs/diff.js +0 -58
- package/lib/cjs/diff.test.js +0 -41
- package/lib/cjs/display.js +0 -16
- package/lib/cjs/dom/css/border.js +0 -33
- package/lib/cjs/dom/css/constants.js +0 -31
- package/lib/cjs/dom/css/core.js +0 -31
- package/lib/cjs/dom/css/fstyle.js +0 -36
- package/lib/cjs/dom/css/sizing.js +0 -14
- package/lib/cjs/dom/dom.js +0 -110
- package/lib/cjs/dom/fc.js +0 -39
- package/lib/cjs/dom/fc.test.js +0 -23
- package/lib/cjs/dom/form/form.app.js +0 -27
- package/lib/cjs/dom/form/form.js +0 -49
- package/lib/cjs/dom/form/form.test.js +0 -1
- package/lib/cjs/dom/html.js +0 -119
- package/lib/cjs/dom/html.test.js +0 -60
- package/lib/cjs/dom/observable.js +0 -10
- package/lib/cjs/dom/observable.test.js +0 -35
- package/lib/cjs/dom/provide.js +0 -12
- package/lib/cjs/dom/router/link.js +0 -7
- package/lib/cjs/dom/router/router.js +0 -55
- package/lib/cjs/dom/svg.js +0 -69
- package/lib/cjs/dom/test.js +0 -13
- package/lib/cjs/dom/types/css.js +0 -24
- package/lib/cjs/dom/types/dom.js +0 -1
- package/lib/cjs/dom/types/html.js +0 -2
- package/lib/cjs/dom/xml.js +0 -8
- package/lib/cjs/equal.js +0 -48
- package/lib/cjs/equal.test.js +0 -22
- package/lib/cjs/flags.js +0 -52
- package/lib/cjs/flags.test.js +0 -37
- package/lib/cjs/fs.js +0 -235
- package/lib/cjs/fs.test.js +0 -86
- package/lib/cjs/fs_node.js +0 -50
- package/lib/cjs/fs_win.test.js +0 -10
- package/lib/cjs/generator.js +0 -14
- package/lib/cjs/generator.test.js +0 -26
- package/lib/cjs/is_browser.js +0 -4
- package/lib/cjs/loader-register.d.mts +0 -1
- package/lib/cjs/loader-register.d.ts +0 -1
- package/lib/cjs/loader-register.js +0 -4
- package/lib/cjs/loader-register.mjs +0 -4
- package/lib/cjs/loader.d.mts +0 -23
- package/lib/cjs/loader.mjs +0 -41
- package/lib/cjs/lock.js +0 -27
- package/lib/cjs/lock.test.js +0 -18
- package/lib/cjs/log.js +0 -98
- package/lib/cjs/observable/event.js +0 -61
- package/lib/cjs/observable/observable.js +0 -363
- package/lib/cjs/observable/observable.test.js +0 -65
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/range.js +0 -11
- package/lib/cjs/result.js +0 -80
- package/lib/cjs/result.test.js +0 -78
- package/lib/cjs/safe.js +0 -14
- package/lib/cjs/scope/describe.js +0 -73
- package/lib/cjs/scope/display/console.js +0 -25
- package/lib/cjs/scope/display/dom.js +0 -30
- package/lib/cjs/scope/display/junit.js +0 -21
- package/lib/cjs/scope/execute.js +0 -91
- package/lib/cjs/scope/expect.js +0 -110
- package/lib/cjs/scope/fix.js +0 -26
- package/lib/cjs/scope/index.js +0 -15
- package/lib/cjs/scope/scope.js +0 -2
- package/lib/cjs/scope/state.js +0 -12
- package/lib/cjs/server/http/apps.js +0 -27
- package/lib/cjs/server/http/css.js +0 -54
- package/lib/cjs/server/http/index.js +0 -77
- package/lib/cjs/server/http/response.js +0 -45
- package/lib/cjs/server/http/sitemap.js +0 -46
- package/lib/cjs/server/http/static.js +0 -25
- package/lib/cjs/server/http/typescript.js +0 -44
- package/lib/cjs/server/main.js +0 -14
- package/lib/cjs/test.mjs +0 -28
- package/lib/cjs/test_all.js +0 -30
- package/lib/cjs/transpile.mjs +0 -22
- package/lib/esm/assert.js +0 -38
- package/lib/esm/awaitable.js +0 -1
- package/lib/esm/case.js +0 -5
- package/lib/esm/components/button_bar.js +0 -27
- package/lib/esm/components/inline_edit.js +0 -48
- package/lib/esm/components/logger.js +0 -22
- package/lib/esm/components/select.js +0 -3
- package/lib/esm/components/test.js +0 -3
- package/lib/esm/components/virtual_scroll.js +0 -94
- package/lib/esm/components/virtual_scroll.test.js +0 -20
- package/lib/esm/context.js +0 -43
- package/lib/esm/context.test.js +0 -46
- package/lib/esm/debounce.js +0 -8
- package/lib/esm/diff.js +0 -54
- package/lib/esm/diff.test.js +0 -39
- package/lib/esm/display.js +0 -11
- package/lib/esm/dom/css/border.js +0 -27
- package/lib/esm/dom/css/constants.js +0 -28
- package/lib/esm/dom/css/core.js +0 -24
- package/lib/esm/dom/css/fstyle.js +0 -32
- package/lib/esm/dom/css/sizing.js +0 -10
- package/lib/esm/dom/dom.js +0 -104
- package/lib/esm/dom/fc.js +0 -35
- package/lib/esm/dom/fc.test.js +0 -21
- package/lib/esm/dom/form/form.app.js +0 -23
- package/lib/esm/dom/form/form.js +0 -34
- package/lib/esm/dom/form/form.test.js +0 -1
- package/lib/esm/dom/html.js +0 -114
- package/lib/esm/dom/html.test.js +0 -58
- package/lib/esm/dom/observable.js +0 -6
- package/lib/esm/dom/observable.test.js +0 -33
- package/lib/esm/dom/provide.js +0 -7
- package/lib/esm/dom/router/link.js +0 -3
- package/lib/esm/dom/router/router.js +0 -52
- package/lib/esm/dom/svg.js +0 -65
- package/lib/esm/dom/test.js +0 -9
- package/lib/esm/dom/types/css.js +0 -23
- package/lib/esm/dom/types/dom.js +0 -1
- package/lib/esm/dom/types/html.js +0 -1
- package/lib/esm/dom/xml.js +0 -4
- package/lib/esm/equal.js +0 -41
- package/lib/esm/equal.test.js +0 -20
- package/lib/esm/flags.js +0 -48
- package/lib/esm/flags.test.js +0 -35
- package/lib/esm/fs.js +0 -226
- package/lib/esm/fs.test.js +0 -84
- package/lib/esm/fs_node.js +0 -45
- package/lib/esm/fs_win.test.js +0 -8
- package/lib/esm/generator.js +0 -10
- package/lib/esm/generator.test.js +0 -24
- package/lib/esm/is_browser.js +0 -1
- package/lib/esm/loader-register.d.mts +0 -1
- package/lib/esm/loader-register.mjs +0 -2
- package/lib/esm/loader.d.mts +0 -23
- package/lib/esm/loader.mjs +0 -36
- package/lib/esm/lock.js +0 -23
- package/lib/esm/lock.test.js +0 -16
- package/lib/esm/log.js +0 -88
- package/lib/esm/observable/event.js +0 -46
- package/lib/esm/observable/observable.js +0 -343
- package/lib/esm/observable/observable.test.js +0 -63
- package/lib/esm/range.js +0 -7
- package/lib/esm/result.js +0 -65
- package/lib/esm/result.test.js +0 -76
- package/lib/esm/safe.js +0 -10
- package/lib/esm/scope/describe.js +0 -60
- package/lib/esm/scope/display/console.js +0 -21
- package/lib/esm/scope/display/dom.js +0 -26
- package/lib/esm/scope/display/junit.js +0 -17
- package/lib/esm/scope/execute.js +0 -85
- package/lib/esm/scope/expect.js +0 -104
- package/lib/esm/scope/fix.js +0 -22
- package/lib/esm/scope/index.js +0 -3
- package/lib/esm/scope/scope.js +0 -1
- package/lib/esm/scope/state.js +0 -8
- package/lib/esm/server/http/apps.js +0 -23
- package/lib/esm/server/http/css.js +0 -50
- package/lib/esm/server/http/index.js +0 -73
- package/lib/esm/server/http/response.js +0 -40
- package/lib/esm/server/http/sitemap.js +0 -42
- package/lib/esm/server/http/static.js +0 -21
- package/lib/esm/server/http/typescript.js +0 -40
- package/lib/esm/server/main.js +0 -12
- package/lib/esm/test.mjs +0 -26
- package/lib/esm/test_all.js +0 -28
- package/lib/esm/transpile.mjs +0 -18
- package/src/components/test.js +0 -3
- package/src/loader-register.mjs +0 -3
- package/src/loader.mjs +0 -46
package/src/lock.test.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { lock } from "./lock.ts";
|
|
2
|
+
import { describe, expect, it } from "./scope/index.ts";
|
|
3
3
|
|
|
4
4
|
describe("Lock", () => {
|
|
5
|
-
it("prevents reentry",
|
|
5
|
+
it("prevents reentry", () => {
|
|
6
6
|
let count = 0;
|
|
7
|
-
const inc = lock(
|
|
7
|
+
const inc = lock(() => {
|
|
8
8
|
if (count > 4) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
package/src/lock.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const locks = new WeakSet<
|
|
1
|
+
const locks = new WeakSet<CallableFunction>();
|
|
2
2
|
|
|
3
|
-
export function lock(fn:
|
|
4
|
-
|
|
5
|
-
let ret
|
|
3
|
+
export function lock<CF extends (...args: unknown[]) => unknown>(fn: CF): CF {
|
|
4
|
+
const lockingFn = (...args: unknown[]): ReturnType<CF> => {
|
|
5
|
+
let ret: ReturnType<CF>;
|
|
6
6
|
let ex = null;
|
|
7
7
|
if (!locks.has(fn)) {
|
|
8
8
|
locks.add(fn);
|
|
9
9
|
try {
|
|
10
|
-
ret = fn(...args)
|
|
10
|
+
ret = fn(...args) as ReturnType<CF>;
|
|
11
11
|
} catch (e) {
|
|
12
12
|
ex = e;
|
|
13
13
|
}
|
|
@@ -15,8 +15,9 @@ export function lock(fn: Function): Function {
|
|
|
15
15
|
locks.delete(fn);
|
|
16
16
|
if (ex !== null) {
|
|
17
17
|
throw ex;
|
|
18
|
-
} else {
|
|
19
|
-
return ret;
|
|
20
18
|
}
|
|
19
|
+
// @ts-expect-error 2454 can't track ret's assignment
|
|
20
|
+
return ret;
|
|
21
21
|
};
|
|
22
|
+
return lockingFn as CF;
|
|
22
23
|
}
|
package/src/log.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Display, display } from "./display.ts";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
(message: Display, data?: {}): void;
|
|
5
|
-
}
|
|
3
|
+
export type Log = (message: Display, data?: object) => void;
|
|
6
4
|
|
|
7
5
|
export interface Logger {
|
|
6
|
+
logAt: (level: number, prefix: string, fn?: (logLine: string) => void) => Log;
|
|
8
7
|
level: number;
|
|
9
8
|
format: <
|
|
10
9
|
D extends {
|
|
@@ -13,11 +12,12 @@ export interface Logger {
|
|
|
13
12
|
level: number;
|
|
14
13
|
message: string;
|
|
15
14
|
source: string;
|
|
16
|
-
}
|
|
15
|
+
},
|
|
17
16
|
>(
|
|
18
|
-
data: D
|
|
17
|
+
data: D,
|
|
19
18
|
) => string;
|
|
20
19
|
console: Console;
|
|
20
|
+
default: (logLine: string) => void;
|
|
21
21
|
debug: Log;
|
|
22
22
|
info: Log;
|
|
23
23
|
warn: Log;
|
|
@@ -46,7 +46,8 @@ export const LEVELS: Record<string, number> = {
|
|
|
46
46
|
|
|
47
47
|
export function getLogLevel(level = ""): number {
|
|
48
48
|
return (
|
|
49
|
-
LEVELS[level.toLowerCase()] ??
|
|
49
|
+
LEVELS[level.toLowerCase()] ??
|
|
50
|
+
(!Number.isNaN(+level) ? Number(level) : LEVEL.INFO)
|
|
50
51
|
);
|
|
51
52
|
}
|
|
52
53
|
|
|
@@ -78,9 +79,9 @@ type LoggerFormatFn = <
|
|
|
78
79
|
level: number;
|
|
79
80
|
message: string;
|
|
80
81
|
source: string;
|
|
81
|
-
}
|
|
82
|
+
},
|
|
82
83
|
>(
|
|
83
|
-
data: D
|
|
84
|
+
data: D,
|
|
84
85
|
) => string;
|
|
85
86
|
|
|
86
87
|
export function getLogger(
|
|
@@ -88,28 +89,37 @@ export function getLogger(
|
|
|
88
89
|
args: LoggerFormatFn | { format?: LoggerFormatFn; console?: Console } = {
|
|
89
90
|
format: JSON.stringify,
|
|
90
91
|
console,
|
|
91
|
-
}
|
|
92
|
+
},
|
|
92
93
|
): Logger {
|
|
93
94
|
if (args instanceof Function) {
|
|
94
95
|
args = { format: args };
|
|
95
96
|
}
|
|
97
|
+
const defaultLog = (logLine: string): void => {
|
|
98
|
+
logger.console.info(logLine);
|
|
99
|
+
};
|
|
96
100
|
const logAt =
|
|
97
|
-
(
|
|
98
|
-
|
|
101
|
+
(
|
|
102
|
+
level: number,
|
|
103
|
+
prefix: string,
|
|
104
|
+
fn: (logLine: string) => void = defaultLog,
|
|
105
|
+
): Log =>
|
|
106
|
+
(message: Display, data?: object) =>
|
|
99
107
|
level >= (logger.level ?? LEVEL.SILENT)
|
|
100
108
|
? fn(
|
|
101
|
-
logger.format
|
|
109
|
+
logger.format?.({
|
|
102
110
|
name,
|
|
103
111
|
prefix,
|
|
104
112
|
level,
|
|
105
113
|
message: display(message),
|
|
106
114
|
...data,
|
|
107
115
|
source: findSource(),
|
|
108
|
-
})
|
|
116
|
+
}),
|
|
109
117
|
)
|
|
110
118
|
: undefined;
|
|
111
119
|
|
|
112
120
|
const logger: Logger = {
|
|
121
|
+
logAt,
|
|
122
|
+
default: defaultLog,
|
|
113
123
|
level: LEVEL.INFO,
|
|
114
124
|
format: args.format ?? JSON.stringify,
|
|
115
125
|
console: args.console ?? global.console,
|
|
@@ -124,22 +134,22 @@ export function getLogger(
|
|
|
124
134
|
|
|
125
135
|
export const DEFAULT_LOGGER = getLogger("default");
|
|
126
136
|
|
|
127
|
-
export function debug(message: Display, data?:
|
|
137
|
+
export function debug(message: Display, data?: object) {
|
|
128
138
|
if (data) DEFAULT_LOGGER.debug(message, data);
|
|
129
139
|
else DEFAULT_LOGGER.debug(message);
|
|
130
140
|
}
|
|
131
141
|
|
|
132
|
-
export function info(message: Display, data?:
|
|
142
|
+
export function info(message: Display, data?: object) {
|
|
133
143
|
if (data) DEFAULT_LOGGER.info(message, data);
|
|
134
144
|
else DEFAULT_LOGGER.info(message);
|
|
135
145
|
}
|
|
136
146
|
|
|
137
|
-
export function warn(message: Display, data?:
|
|
147
|
+
export function warn(message: Display, data?: object) {
|
|
138
148
|
if (data) DEFAULT_LOGGER.warn(message, data);
|
|
139
149
|
else DEFAULT_LOGGER.warn(message);
|
|
140
150
|
}
|
|
141
151
|
|
|
142
|
-
export function error(message: Display, data?:
|
|
152
|
+
export function error(message: Display, data?: object) {
|
|
143
153
|
if (data) DEFAULT_LOGGER.error(message, data);
|
|
144
154
|
else DEFAULT_LOGGER.error(message);
|
|
145
155
|
}
|
package/src/observable/event.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { display } from "../display.
|
|
2
|
-
import { Observable } from "./observable.
|
|
1
|
+
import { display } from "../display.ts";
|
|
2
|
+
import type { Observable } from "./observable.ts";
|
|
3
3
|
|
|
4
4
|
export interface Next<T> {
|
|
5
5
|
value: T;
|
|
@@ -47,7 +47,7 @@ export const isNext = <T>(event: Event<T, unknown>): event is Next<T> =>
|
|
|
47
47
|
export const isError = <E>(event: Event<unknown, E>): event is Error<E> =>
|
|
48
48
|
event.failed && !event.completed;
|
|
49
49
|
export const isCompleted = (
|
|
50
|
-
event: Event<unknown, unknown
|
|
50
|
+
event: Event<unknown, unknown>,
|
|
51
51
|
): event is Completed => event.completed && !event.failed;
|
|
52
52
|
export const isFailed = (event: Event<unknown, unknown>): event is Failed =>
|
|
53
53
|
event.completed && event.failed;
|
|
@@ -64,10 +64,10 @@ const marble = <T, E>(event: Event<T, E>): string =>
|
|
|
64
64
|
isError(event)
|
|
65
65
|
? "X"
|
|
66
66
|
: isFailed(event)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
? "!"
|
|
68
|
+
: isCompleted(event)
|
|
69
|
+
? "|"
|
|
70
|
+
: `(${display(event.value)})`;
|
|
71
71
|
|
|
72
72
|
export const marbles = <T, E>(events: Event<T, E>[]): string =>
|
|
73
73
|
`:${events.map(marble).join("-")}`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { describe, expect, it } from "../scope/index.
|
|
2
|
-
import {
|
|
1
|
+
import { describe, expect, it } from "../scope/index.ts";
|
|
2
|
+
import { filter, map, Observable, Subject } from "./observable.ts";
|
|
3
3
|
|
|
4
4
|
describe("Observables", () => {
|
|
5
5
|
describe("basics", () => {
|
|
@@ -23,7 +23,7 @@ describe("Observables", () => {
|
|
|
23
23
|
describe("creation", () => {
|
|
24
24
|
it("builds an observable of items", async () => {
|
|
25
25
|
const stream = Observable.of(2, 4, 8, 16);
|
|
26
|
-
|
|
26
|
+
const values: number[] = [];
|
|
27
27
|
await new Promise<void>((resolve) => {
|
|
28
28
|
stream.subscribe({
|
|
29
29
|
next: (n) => {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assertExists } from "../assert.ts";
|
|
2
|
+
import type { Display } from "../display.ts";
|
|
3
|
+
import { DEFAULT_LOGGER, type Logger } from "../log.ts";
|
|
2
4
|
|
|
3
5
|
export interface FullSubscriber<T, E> {
|
|
4
6
|
// (t: T): void | Promise<undefined>;
|
|
5
|
-
next?: (t: T) => void | Promise<
|
|
6
|
-
error?: (e: E) => void | Promise<
|
|
7
|
-
complete?: () => void | Promise<
|
|
7
|
+
next?: (t: T) => void | Promise<void>;
|
|
8
|
+
error?: (e: E) => void | Promise<void>;
|
|
9
|
+
complete?: () => void | Promise<void>;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export type Subscriber<T, E> =
|
|
11
13
|
| FullSubscriber<T, E>
|
|
12
14
|
// | EventSubscriber<T, E>
|
|
13
|
-
| ((t: T) => void | Promise<
|
|
15
|
+
| ((t: T) => void | Promise<void>);
|
|
14
16
|
|
|
15
17
|
export interface Subscription {
|
|
16
18
|
// (): void;
|
|
@@ -23,7 +25,7 @@ export interface Observable<T, E = unknown> {
|
|
|
23
25
|
pipe<T1>(o1: Subscriber<T, E> & Observable<T1, E>): Observable<T1, E>;
|
|
24
26
|
pipe<T1, T2>(
|
|
25
27
|
o1: Subscriber<T, E> & Observable<T1, E>,
|
|
26
|
-
o2: Subscriber<T1, E> & Observable<T2, E
|
|
28
|
+
o2: Subscriber<T1, E> & Observable<T2, E>,
|
|
27
29
|
): Observable<T2, E>;
|
|
28
30
|
filter(fn: (t: T) => boolean): Observable<T, E>;
|
|
29
31
|
distinct(fn?: (t1: T, t2: T) => boolean): Observable<T, E>;
|
|
@@ -45,7 +47,7 @@ export const Observable = {
|
|
|
45
47
|
subject.complete();
|
|
46
48
|
return;
|
|
47
49
|
}
|
|
48
|
-
const t = ts.shift()
|
|
50
|
+
const t = assertExists(ts.shift());
|
|
49
51
|
await subject.next(t);
|
|
50
52
|
next();
|
|
51
53
|
})();
|
|
@@ -53,9 +55,9 @@ export const Observable = {
|
|
|
53
55
|
},
|
|
54
56
|
combineLatest<T1, T2, E>(
|
|
55
57
|
o1: Observable<T1, E>,
|
|
56
|
-
o2: Observable<T2, E
|
|
58
|
+
o2: Observable<T2, E>,
|
|
57
59
|
): Observable<[T1, T2], E> {
|
|
58
|
-
|
|
60
|
+
const latestSubject = new Subject<[T1, T2], E>();
|
|
59
61
|
let o1LatestSet = false;
|
|
60
62
|
let o1Latest: T1;
|
|
61
63
|
let o2LatestSet = false;
|
|
@@ -77,7 +79,7 @@ export const Observable = {
|
|
|
77
79
|
o2sub.unsubscribe();
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
const o1sub = o1.subscribe({
|
|
81
83
|
next(t: T1) {
|
|
82
84
|
o1Latest = t;
|
|
83
85
|
o1LatestSet = true;
|
|
@@ -87,7 +89,7 @@ export const Observable = {
|
|
|
87
89
|
complete,
|
|
88
90
|
});
|
|
89
91
|
|
|
90
|
-
|
|
92
|
+
const o2sub = o2.subscribe({
|
|
91
93
|
next(t: T2) {
|
|
92
94
|
o2Latest = t;
|
|
93
95
|
o2LatestSet = true;
|
|
@@ -102,25 +104,31 @@ export const Observable = {
|
|
|
102
104
|
};
|
|
103
105
|
|
|
104
106
|
interface Scheduler {
|
|
105
|
-
execute(fn: () => (void | Promise<
|
|
107
|
+
execute(fn: () => (void | Promise<void>)[]): void | Promise<void>;
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
export const AsyncScheduler: Scheduler = {
|
|
109
|
-
execute(fn: () => Promise<
|
|
111
|
+
execute(fn: () => Promise<void>[]): Promise<void> {
|
|
110
112
|
return Promise.all(fn()).then(() => undefined);
|
|
111
113
|
},
|
|
112
114
|
};
|
|
113
115
|
|
|
114
116
|
export const SyncScheduler: Scheduler = {
|
|
115
|
-
execute(fn: () =>
|
|
117
|
+
execute(fn: () => undefined[]): void {
|
|
116
118
|
fn();
|
|
117
119
|
},
|
|
118
120
|
};
|
|
119
121
|
|
|
122
|
+
let DefaultScheduler = SyncScheduler;
|
|
123
|
+
export function setDefaultScheduler(scheduler: Scheduler) {
|
|
124
|
+
DefaultScheduler = scheduler;
|
|
125
|
+
}
|
|
126
|
+
|
|
120
127
|
export class Subject<T, E = unknown, T2 = T>
|
|
121
128
|
implements FullSubscriber<T, E>, Observable<T, E>
|
|
122
129
|
{
|
|
123
|
-
|
|
130
|
+
private readonly scheduler: Scheduler;
|
|
131
|
+
#coldWaiters = new Set<CallableFunction>();
|
|
124
132
|
#subscribers = new Set<FullSubscriber<T, E>>();
|
|
125
133
|
#complete = false;
|
|
126
134
|
|
|
@@ -136,34 +144,36 @@ export class Subject<T, E = unknown, T2 = T>
|
|
|
136
144
|
return !this.hot;
|
|
137
145
|
}
|
|
138
146
|
|
|
139
|
-
constructor(
|
|
147
|
+
constructor(scheduler: Scheduler = DefaultScheduler) {
|
|
148
|
+
this.scheduler = scheduler;
|
|
149
|
+
}
|
|
140
150
|
|
|
141
|
-
onWarm(fn:
|
|
151
|
+
onWarm(fn: CallableFunction) {
|
|
142
152
|
if (this.cold) this.#coldWaiters.add(fn);
|
|
143
153
|
}
|
|
144
154
|
|
|
145
|
-
next(t: T | T2): void | Promise<
|
|
155
|
+
next(t: T | T2): void | Promise<void> {
|
|
146
156
|
if (this.#complete)
|
|
147
157
|
throw new Error("Cannot call next on a completed subject");
|
|
148
158
|
return this.scheduler.execute(() =>
|
|
149
|
-
[...this.#subscribers].map((s) => s.next?.(t as T))
|
|
159
|
+
[...this.#subscribers].map((s) => s.next?.(t as T)),
|
|
150
160
|
);
|
|
151
161
|
}
|
|
152
162
|
|
|
153
|
-
error(e: E): void | Promise<
|
|
163
|
+
error(e: E): void | Promise<void> {
|
|
154
164
|
if (this.#complete)
|
|
155
165
|
throw new Error("Cannot call error on a completed subject");
|
|
156
166
|
return this.scheduler.execute(() =>
|
|
157
|
-
[...this.#subscribers].map((s) => s.error?.(e))
|
|
167
|
+
[...this.#subscribers].map((s) => s.error?.(e)),
|
|
158
168
|
);
|
|
159
169
|
}
|
|
160
170
|
|
|
161
|
-
complete(): void | Promise<
|
|
171
|
+
complete(): void | Promise<void> {
|
|
162
172
|
if (this.#complete)
|
|
163
173
|
throw new Error("Cannot call complete on a completed subject");
|
|
164
174
|
this.#complete = true;
|
|
165
175
|
const finished = this.scheduler.execute(() =>
|
|
166
|
-
[...this.#subscribers].map((s) => s.complete?.())
|
|
176
|
+
[...this.#subscribers].map((s) => s.complete?.()),
|
|
167
177
|
);
|
|
168
178
|
this.#subscribers.clear(); // Free subscribers for garbage collection
|
|
169
179
|
return finished;
|
|
@@ -179,7 +189,7 @@ export class Subject<T, E = unknown, T2 = T>
|
|
|
179
189
|
|
|
180
190
|
this.#subscribers.add(subscriber);
|
|
181
191
|
|
|
182
|
-
|
|
192
|
+
for (const w of this.#coldWaiters) w();
|
|
183
193
|
this.#coldWaiters.clear();
|
|
184
194
|
|
|
185
195
|
return {
|
|
@@ -191,7 +201,7 @@ export class Subject<T, E = unknown, T2 = T>
|
|
|
191
201
|
pipe<T1>(o1: Subscriber<T, E> & Observable<T1, E>): Observable<T1, E>;
|
|
192
202
|
pipe<T1, T2>(
|
|
193
203
|
o1: Subscriber<T, E> & Observable<T1, E>,
|
|
194
|
-
o2: Subscriber<T1, E> & Observable<T2, E
|
|
204
|
+
o2: Subscriber<T1, E> & Observable<T2, E>,
|
|
195
205
|
): Observable<T2, E>;
|
|
196
206
|
pipe(
|
|
197
207
|
...os: (Subscriber<unknown, unknown> & Observable<unknown, unknown>)[]
|
|
@@ -232,7 +242,7 @@ export class BehaviorSubject<T, E = unknown, T2 = T> extends Subject<T, E, T2> {
|
|
|
232
242
|
#current: T;
|
|
233
243
|
|
|
234
244
|
constructor(t: T, scheduler?: Scheduler) {
|
|
235
|
-
super(scheduler);
|
|
245
|
+
super(scheduler ?? AsyncScheduler);
|
|
236
246
|
this.#current = t;
|
|
237
247
|
}
|
|
238
248
|
|
|
@@ -255,10 +265,12 @@ export class BehaviorSubject<T, E = unknown, T2 = T> extends Subject<T, E, T2> {
|
|
|
255
265
|
}
|
|
256
266
|
|
|
257
267
|
export class ReplaySubject<T, E = unknown> extends Subject<T, E> {
|
|
268
|
+
readonly n: number;
|
|
258
269
|
#history: T[] = [];
|
|
259
270
|
|
|
260
|
-
constructor(
|
|
261
|
-
super(scheduler);
|
|
271
|
+
constructor(n: number, scheduler?: Scheduler) {
|
|
272
|
+
super(scheduler ?? SyncScheduler);
|
|
273
|
+
this.n = n;
|
|
262
274
|
}
|
|
263
275
|
|
|
264
276
|
next(t: T) {
|
|
@@ -275,8 +287,8 @@ export class ReplaySubject<T, E = unknown> extends Subject<T, E> {
|
|
|
275
287
|
}
|
|
276
288
|
const history = [...this.#history];
|
|
277
289
|
(function send() {
|
|
278
|
-
if (history.length
|
|
279
|
-
const t = history.shift()
|
|
290
|
+
if (history.length === 0) return;
|
|
291
|
+
const t = assertExists(history.shift());
|
|
280
292
|
subscriber.next?.(t);
|
|
281
293
|
new Promise(send);
|
|
282
294
|
})();
|
|
@@ -295,27 +307,28 @@ export function eventListener<E extends Event>() {
|
|
|
295
307
|
}
|
|
296
308
|
|
|
297
309
|
export class EventHandler<E extends Event> extends Subject<E> {
|
|
298
|
-
constructor(
|
|
299
|
-
super();
|
|
310
|
+
constructor(eventFn: (e: E) => void | Promise<void>) {
|
|
311
|
+
super(AsyncScheduler);
|
|
312
|
+
this.eventFn = eventFn;
|
|
300
313
|
}
|
|
301
314
|
|
|
302
|
-
next(e: E) {
|
|
315
|
+
async next(e: E): Promise<undefined> {
|
|
303
316
|
e.preventDefault();
|
|
304
317
|
super.next(e);
|
|
305
318
|
}
|
|
306
319
|
}
|
|
307
320
|
|
|
308
321
|
export const watch =
|
|
309
|
-
<T, E>(logger: Logger = DEFAULT_LOGGER) =>
|
|
322
|
+
<T extends Display, E extends Display>(logger: Logger = DEFAULT_LOGGER) =>
|
|
310
323
|
(observable: Observable<T, E>) => {
|
|
311
324
|
observable.tap({
|
|
312
|
-
next(t: T) {
|
|
325
|
+
async next(t: T) {
|
|
313
326
|
logger.info(t);
|
|
314
327
|
},
|
|
315
|
-
complete() {
|
|
328
|
+
async complete() {
|
|
316
329
|
logger.info("Observable completed");
|
|
317
330
|
},
|
|
318
|
-
error(e: E) {
|
|
331
|
+
async error(e: E) {
|
|
319
332
|
logger.warn(e);
|
|
320
333
|
},
|
|
321
334
|
});
|
|
@@ -325,11 +338,13 @@ class MapOperator<T, U, E>
|
|
|
325
338
|
extends Subject<U, E, T>
|
|
326
339
|
implements FullSubscriber<T, E>, Observable<U, E>
|
|
327
340
|
{
|
|
328
|
-
|
|
329
|
-
|
|
341
|
+
private readonly mapFn: (t: T) => U;
|
|
342
|
+
constructor(mapFn: (t: T) => U) {
|
|
343
|
+
super(SyncScheduler);
|
|
344
|
+
this.mapFn = mapFn;
|
|
330
345
|
}
|
|
331
346
|
|
|
332
|
-
next(t: T): void | Promise<
|
|
347
|
+
next(t: T): void | Promise<void> {
|
|
333
348
|
return super.next(this.mapFn(t));
|
|
334
349
|
}
|
|
335
350
|
}
|
|
@@ -338,11 +353,13 @@ class FilterOperator<T, E>
|
|
|
338
353
|
extends Subject<T, E>
|
|
339
354
|
implements FullSubscriber<T, E>, Observable<T, E>
|
|
340
355
|
{
|
|
341
|
-
|
|
342
|
-
|
|
356
|
+
private readonly filterFn: (t: T) => boolean;
|
|
357
|
+
constructor(filterFn: (t: T) => boolean) {
|
|
358
|
+
super(SyncScheduler);
|
|
359
|
+
this.filterFn = filterFn;
|
|
343
360
|
}
|
|
344
361
|
|
|
345
|
-
next(t: T): void | Promise<
|
|
362
|
+
next(t: T): void | Promise<void> {
|
|
346
363
|
return this.filterFn(t) ? super.next(t) : undefined;
|
|
347
364
|
}
|
|
348
365
|
}
|
|
@@ -352,19 +369,19 @@ class DistinctOperator<T, E>
|
|
|
352
369
|
implements FullSubscriber<T, E>, Observable<T, E>
|
|
353
370
|
{
|
|
354
371
|
#prior: T | undefined = undefined;
|
|
372
|
+
private readonly distinctFn: (t1: T, t2: T) => boolean;
|
|
355
373
|
|
|
356
|
-
constructor(
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
super();
|
|
374
|
+
constructor(distinctFn: (t1: T, t2: T) => boolean = Object.is) {
|
|
375
|
+
super(SyncScheduler);
|
|
376
|
+
this.distinctFn = distinctFn;
|
|
360
377
|
}
|
|
361
378
|
|
|
362
|
-
next(t: T): void | Promise<
|
|
379
|
+
next(t: T): void | Promise<void> {
|
|
363
380
|
if (this.#prior === undefined) {
|
|
364
381
|
this.#prior = t;
|
|
365
382
|
return super.next(t);
|
|
366
383
|
}
|
|
367
|
-
const same = this.distinctFn(this.#prior
|
|
384
|
+
const same = this.distinctFn(assertExists(this.#prior), t);
|
|
368
385
|
if (!same) {
|
|
369
386
|
this.#prior = t;
|
|
370
387
|
return super.next(t);
|
|
@@ -374,8 +391,10 @@ class DistinctOperator<T, E>
|
|
|
374
391
|
}
|
|
375
392
|
|
|
376
393
|
class ReduceOperator<A, T, E> extends BehaviorSubject<A, E, T> {
|
|
377
|
-
|
|
394
|
+
private readonly fn: (acc: A, t: T) => A;
|
|
395
|
+
constructor(fn: (acc: A, t: T) => A, init: A) {
|
|
378
396
|
super(init);
|
|
397
|
+
this.fn = fn;
|
|
379
398
|
}
|
|
380
399
|
|
|
381
400
|
next(t: T) {
|
|
@@ -413,7 +432,7 @@ export class TapOperator<T, E> extends Subject<T, E> {
|
|
|
413
432
|
}
|
|
414
433
|
|
|
415
434
|
class FirstOperator<T, E> extends Subject<T, E> {
|
|
416
|
-
next(t: T): void | Promise<
|
|
435
|
+
next(t: T): void | Promise<void> {
|
|
417
436
|
const next = super.next(t);
|
|
418
437
|
this.complete();
|
|
419
438
|
return next;
|
|
@@ -427,7 +446,7 @@ class LastOperator<T, E = Error> extends Subject<T, E> {
|
|
|
427
446
|
this.#latest = t;
|
|
428
447
|
}
|
|
429
448
|
|
|
430
|
-
complete(): void | Promise<
|
|
449
|
+
complete(): void | Promise<void> {
|
|
431
450
|
if (this.#latest !== undefined) {
|
|
432
451
|
super.next(this.#latest);
|
|
433
452
|
}
|
package/src/result.test.ts
CHANGED
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
Err,
|
|
3
3
|
None,
|
|
4
4
|
Ok,
|
|
5
|
-
Result,
|
|
5
|
+
type Result,
|
|
6
6
|
Some,
|
|
7
7
|
unwrap,
|
|
8
8
|
unwrapOr,
|
|
9
9
|
unwrapOrElse,
|
|
10
|
-
} from "./result.
|
|
11
|
-
import { describe, it } from "./scope/describe.
|
|
12
|
-
import { expect } from "./scope/expect.
|
|
10
|
+
} from "./result.ts";
|
|
11
|
+
import { describe, it } from "./scope/describe.ts";
|
|
12
|
+
import { expect } from "./scope/expect.ts";
|
|
13
13
|
|
|
14
14
|
describe("Result", () => {
|
|
15
15
|
it("converts Nones", () => {
|
|
@@ -40,7 +40,7 @@ describe("Result", () => {
|
|
|
40
40
|
expect(b).toMatchObject({ message: "a error" });
|
|
41
41
|
|
|
42
42
|
// Assign Err to Result
|
|
43
|
-
const
|
|
43
|
+
const _c: Result<string> = a;
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
it("converts Oks", () => {
|
|
@@ -49,7 +49,7 @@ describe("Result", () => {
|
|
|
49
49
|
expect(b).toBe("a ok");
|
|
50
50
|
|
|
51
51
|
// Assign ok to Result
|
|
52
|
-
const
|
|
52
|
+
const _c: Result<string> = a;
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
it("unwraps", () => {
|
|
@@ -95,10 +95,7 @@ describe("Result", () => {
|
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
it("allows Result<void> with Ok()", () => {
|
|
98
|
-
|
|
99
|
-
a = Ok();
|
|
98
|
+
const a: Result<void> = Ok();
|
|
100
99
|
expect(unwrap(a)).toBe(undefined);
|
|
101
100
|
});
|
|
102
101
|
});
|
|
103
|
-
|
|
104
|
-
export {};
|