@dereekb/util 7.6.0 → 7.7.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/CHANGELOG.md +9 -0
- package/package.json +1 -1
- package/src/lib/getter/getter.d.ts +5 -0
- package/src/lib/getter/getter.js.map +1 -1
- package/src/lib/promise/use.d.ts +4 -5
- package/src/lib/promise/use.js +1 -1
- package/src/lib/promise/use.js.map +1 -1
- package/src/lib/value/use.d.ts +17 -1
- package/src/lib/value/use.js +31 -1
- package/src/lib/value/use.js.map +1 -1
- package/test/CHANGELOG.md +4 -0
- package/test/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
# [7.7.0](https://github.com/dereekb/dbx-components/compare/v7.6.0-dev...v7.7.0) (2022-06-09)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* added UseAsync ([f52ff34](https://github.com/dereekb/dbx-components/commit/f52ff345621ecbcb4d6b0f2957dcd7f4f901ac3a))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
5
14
|
# [7.6.0](https://github.com/dereekb/dbx-components/compare/v7.5.0-dev...v7.6.0) (2022-06-09)
|
|
6
15
|
|
|
7
16
|
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PromiseOrValue } from '../promise/promise';
|
|
1
2
|
/**
|
|
2
3
|
* Function that returns a value.
|
|
3
4
|
*/
|
|
@@ -18,6 +19,10 @@ export declare type FactoryWithRequiredInput<T, A> = (args: A) => T;
|
|
|
18
19
|
* Either a Getter, or an instance of the item.
|
|
19
20
|
*/
|
|
20
21
|
export declare type GetterOrValue<T> = T | Getter<T>;
|
|
22
|
+
/**
|
|
23
|
+
* A GetterOrValue returned from a Promise.
|
|
24
|
+
*/
|
|
25
|
+
export declare type AsyncGetterOrValue<T> = GetterOrValue<PromiseOrValue<T>>;
|
|
21
26
|
/**
|
|
22
27
|
* Either a GetterWithInput, or a Getter.
|
|
23
28
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getter.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/getter/getter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getter.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/getter/getter.ts"],"names":[],"mappings":";;;AA4CA;;;;;GAKG;AACH,SAAgB,QAAQ,CAAc,KAAc;IAClD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC;AAFD,4BAEC;AAaD,SAAgB,kBAAkB,CAAsB,KAAc,EAAE,IAAQ;IAC9E,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;QAC/B,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;KACpB;SAAM;QACL,OAAO,KAAU,CAAC;KACnB;AACH,CAAC;AAND,gDAMC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAI,KAAuB;IACjD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;QAC/B,OAAO,KAAkB,CAAC;KAC3B;SAAM;QACL,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;KAC1B;AACH,CAAC;AAND,4BAMC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAI,KAAQ;IACpC,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;AACrB,CAAC;AAFD,gCAEC"}
|
package/src/lib/promise/use.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { GetterOrValue } from '../getter';
|
|
2
|
-
import {
|
|
3
|
-
export declare type UsePromiseUseFunction<I, O> = (value: I) => PromiseOrValue<O>;
|
|
2
|
+
import { UseAsync } from '../value';
|
|
4
3
|
/**
|
|
5
|
-
* Uses a
|
|
4
|
+
* Uses a cached promise value.
|
|
6
5
|
*/
|
|
7
|
-
export declare type UsePromiseFunction<I> = <O>(useFn:
|
|
6
|
+
export declare type UsePromiseFunction<I> = <O>(useFn: UseAsync<I, O>) => Promise<O>;
|
|
8
7
|
/**
|
|
9
|
-
* Creates a
|
|
8
|
+
* Creates a UsePromiseFunction.
|
|
10
9
|
*
|
|
11
10
|
* @param input
|
|
12
11
|
* @returns
|
package/src/lib/promise/use.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/promise/use.ts"],"names":[],"mappings":";;;AAAA,sCAAoD;
|
|
1
|
+
{"version":3,"file":"use.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/promise/use.ts"],"names":[],"mappings":";;;AAAA,sCAAoD;AAQpD;;;;;GAKG;AACH,SAAgB,UAAU,CAAI,KAAgC;IAC5D,MAAM,OAAO,GAAG,IAAA,iBAAQ,EAAC,KAAK,CAAC,CAAC;IAChC,OAAO,CAAI,KAAqB,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,CAAe,CAAC;AAC3E,CAAC;AAHD,gCAGC"}
|
package/src/lib/value/use.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { GetterOrValue } from '../getter';
|
|
1
|
+
import { AsyncGetterOrValue, GetterOrValue } from '../getter';
|
|
2
|
+
import { PromiseOrValue } from '../promise/promise';
|
|
2
3
|
import { MapFunction } from './map';
|
|
3
4
|
import { Maybe } from './maybe.type';
|
|
4
5
|
/**
|
|
@@ -24,3 +25,18 @@ export declare type UseContextFunction<I> = <O>(input: Maybe<I>) => Maybe<O>;
|
|
|
24
25
|
* Creates a UseContextFunction.
|
|
25
26
|
*/
|
|
26
27
|
export declare function useContextFunction<I, O>(use: UseValue<I, O>, defaultValue?: GetterOrValue<O>): UseContextFunction<I>;
|
|
28
|
+
/**
|
|
29
|
+
* A map function with the intent of using the input value, and returning another value as a promise.
|
|
30
|
+
*/
|
|
31
|
+
export declare type UseAsync<I, O = void> = MapFunction<I, PromiseOrValue<O>>;
|
|
32
|
+
export declare function useAsync<I, O = void>(input: Maybe<I>, use: UseValue<I, O>, defaultValue?: Maybe<GetterOrValue<O>>): Promise<Maybe<O>>;
|
|
33
|
+
export declare type UseAsyncFunction<I> = MappedUseAsyncFunction<I, I>;
|
|
34
|
+
export declare type MappedUseAsyncFunction<A, I> = <O = void>(input: Maybe<A>, use: UseAsync<I, O>, defaultValue?: Maybe<AsyncGetterOrValue<O>>) => Promise<Maybe<O>>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a MappedUseFunction.
|
|
37
|
+
*/
|
|
38
|
+
export declare function mappedUseAsyncFunction<A, I>(map: MapFunction<A, Maybe<PromiseOrValue<I>>>): MappedUseAsyncFunction<A, I>;
|
|
39
|
+
/**
|
|
40
|
+
* Wraps another MappedUseFunction or MappedUseAsyncFunction and maps the input values.
|
|
41
|
+
*/
|
|
42
|
+
export declare function wrapUseAsyncFunction<A, B, I>(mappedUsePromiseFn: MappedUseAsyncFunction<A, B>, map: MapFunction<B, Maybe<PromiseOrValue<I>>>): MappedUseAsyncFunction<A, I>;
|
package/src/lib/value/use.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useContextFunction = exports.wrapUseFunction = exports.mappedUseFunction = exports.useValue = void 0;
|
|
3
|
+
exports.wrapUseAsyncFunction = exports.mappedUseAsyncFunction = exports.useAsync = exports.useContextFunction = exports.wrapUseFunction = exports.mappedUseFunction = exports.useValue = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const getter_1 = require("../getter");
|
|
5
6
|
function useValue(input, use, defaultValue) {
|
|
6
7
|
let result;
|
|
@@ -45,4 +46,33 @@ function useContextFunction(use, defaultValue) {
|
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
exports.useContextFunction = useContextFunction;
|
|
49
|
+
function useAsync(input, use, defaultValue) {
|
|
50
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
let result;
|
|
52
|
+
if (input != null) {
|
|
53
|
+
result = (yield use(input));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
result = yield (0, getter_1.getValueFromGetter)(defaultValue);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.useAsync = useAsync;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a MappedUseFunction.
|
|
64
|
+
*/
|
|
65
|
+
function mappedUseAsyncFunction(map) {
|
|
66
|
+
return wrapUseAsyncFunction(useAsync, map);
|
|
67
|
+
}
|
|
68
|
+
exports.mappedUseAsyncFunction = mappedUseAsyncFunction;
|
|
69
|
+
/**
|
|
70
|
+
* Wraps another MappedUseFunction or MappedUseAsyncFunction and maps the input values.
|
|
71
|
+
*/
|
|
72
|
+
function wrapUseAsyncFunction(mappedUsePromiseFn, map) {
|
|
73
|
+
return ((input, useFn, defaultValue) => {
|
|
74
|
+
return mappedUsePromiseFn(input, ((value) => tslib_1.__awaiter(this, void 0, void 0, function* () { return useValue(yield map(value), useFn, defaultValue); })), defaultValue);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
exports.wrapUseAsyncFunction = wrapUseAsyncFunction;
|
|
48
78
|
//# sourceMappingURL=use.js.map
|
package/src/lib/value/use.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/value/use.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/value/use.ts"],"names":[],"mappings":";;;;AAAA,sCAAkF;AAWlF,SAAgB,QAAQ,CAAc,KAAe,EAAE,GAAmB,EAAE,YAAsC;IAChH,IAAI,MAAgB,CAAC;IAErB,IAAI,KAAK,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L,MAAM,GAAG,MAAM,IAAA,2BAAkB,EAAC,YAAY,CAAC,CAAC;SACjD;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CAAA;AAVD,4BAUC;AAKD;;GAEG;AACH,SAAgB,sBAAsB,CAAO,GAA6C;IACxF,OAAO,oBAAoB,CAAU,QAAe,EAAE,GAAU,CAAC,CAAC;AACpE,CAAC;AAFD,wDAEC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAU,kBAAgD,EAAE,GAA6C;IAC3I,OAAO,CAAC,CAAW,KAAe,EAAE,KAAqB,EAAE,YAA2C,EAAE,EAAE;QACxG,OAAO,kBAAkB,CAAI,KAAK,EAAE,CAAC,CAAO,KAAQ,EAAE,EAAE,wDAAC,OAAA,QAAQ,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAA,GAAA,CAAmB,EAAE,YAAY,CAAC,CAAC;IAC7I,CAAC,CAAiC,CAAC;AACrC,CAAC;AAJD,oDAIC"}
|
package/test/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
# [7.7.0](https://github.com/dereekb/dbx-components/compare/v7.6.0-dev...v7.7.0) (2022-06-09)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
5
9
|
# [7.6.0](https://github.com/dereekb/dbx-components/compare/v7.5.0-dev...v7.6.0) (2022-06-09)
|
|
6
10
|
|
|
7
11
|
|
package/test/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/util/test",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.7.0",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"typings": "./src/index.d.ts",
|
|
6
6
|
"dependencies": {},
|
|
7
7
|
"peerDependencies": {
|
|
8
|
-
"@dereekb/util": "7.
|
|
8
|
+
"@dereekb/util": "7.7.0",
|
|
9
9
|
"make-error": "^1.3.0",
|
|
10
10
|
"ts-essentials": "^9.1.2",
|
|
11
11
|
"extra-set": "^2.2.11",
|