@esportsplus/reactivity 0.6.0 → 0.6.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/build/reactive/index.d.ts +5 -2
- package/build/reactive/index.js +4 -8
- package/package.json +1 -1
- package/src/reactive/index.ts +14 -11
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import array from './array.js';
|
|
2
|
+
import object from './object.js';
|
|
3
|
+
import promise from './promise.js';
|
|
4
|
+
type API<T> = T extends (...args: infer A) => Promise<infer R> ? ReturnType<typeof promise<A, Promise<R>>> : T extends Record<PropertyKey, unknown> ? ReturnType<typeof object<T>> : T extends unknown[] ? ReturnType<typeof array<T>> : never;
|
|
2
5
|
type Guard<T> = T extends (...args: unknown[]) => Promise<unknown> ? T : T extends {
|
|
3
6
|
dispose: any;
|
|
4
7
|
} | {
|
|
@@ -6,5 +9,5 @@ type Guard<T> = T extends (...args: unknown[]) => Promise<unknown> ? T : T exten
|
|
|
6
9
|
} ? {
|
|
7
10
|
never: '[ dispose, signals ] are reserved keys';
|
|
8
11
|
} : T extends Record<PropertyKey, unknown> | unknown[] ? T : never;
|
|
9
|
-
declare const _default: <T>(data: Guard<T>) =>
|
|
12
|
+
declare const _default: <T>(data: Guard<T>) => API<T>;
|
|
10
13
|
export default _default;
|
package/build/reactive/index.js
CHANGED
|
@@ -3,18 +3,14 @@ import array from './array.js';
|
|
|
3
3
|
import object from './object.js';
|
|
4
4
|
import promise from './promise.js';
|
|
5
5
|
export default (data) => {
|
|
6
|
-
let value;
|
|
7
6
|
if (isArray(data)) {
|
|
8
|
-
|
|
7
|
+
return array(data);
|
|
9
8
|
}
|
|
10
9
|
else if (isObject(data)) {
|
|
11
|
-
|
|
10
|
+
return object(data);
|
|
12
11
|
}
|
|
13
12
|
else if (isPromise(data)) {
|
|
14
|
-
|
|
13
|
+
return promise(data);
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
throw new Error(`@esportsplus/reactivity: 'reactive' received invalid input - ${JSON.stringify(data)}`);
|
|
18
|
-
}
|
|
19
|
-
return value;
|
|
15
|
+
throw new Error(`@esportsplus/reactivity: 'reactive' received invalid input - ${JSON.stringify(data)}`);
|
|
20
16
|
};
|
package/package.json
CHANGED
package/src/reactive/index.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { isArray, isObject, isPromise } from '@esportsplus/utilities';
|
|
2
|
-
import { Reactive } from '~/types';
|
|
3
2
|
import array from './array';
|
|
4
3
|
import object from './object';
|
|
5
4
|
import promise from './promise';
|
|
6
5
|
|
|
7
6
|
|
|
7
|
+
type API<T> =
|
|
8
|
+
T extends (...args: infer A) => Promise<infer R>
|
|
9
|
+
? ReturnType<typeof promise<A, Promise<R>>>
|
|
10
|
+
: T extends Record<PropertyKey, unknown>
|
|
11
|
+
? ReturnType<typeof object<T>>
|
|
12
|
+
: T extends unknown[]
|
|
13
|
+
? ReturnType<typeof array<T>>
|
|
14
|
+
: never;
|
|
15
|
+
|
|
8
16
|
type Guard<T> =
|
|
9
17
|
T extends (...args: unknown[]) => Promise<unknown>
|
|
10
18
|
? T
|
|
@@ -15,21 +23,16 @@ type Guard<T> =
|
|
|
15
23
|
: never;
|
|
16
24
|
|
|
17
25
|
|
|
18
|
-
export default <T>(data: Guard<T>) => {
|
|
19
|
-
let value;
|
|
20
|
-
|
|
26
|
+
export default <T>(data: Guard<T>): API<T> => {
|
|
21
27
|
if (isArray(data)) {
|
|
22
|
-
|
|
28
|
+
return array(data) as API<T>;
|
|
23
29
|
}
|
|
24
30
|
else if (isObject(data)) {
|
|
25
|
-
|
|
31
|
+
return object(data) as API<T>;
|
|
26
32
|
}
|
|
27
33
|
else if (isPromise(data)) {
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
throw new Error(`@esportsplus/reactivity: 'reactive' received invalid input - ${JSON.stringify(data)}`);
|
|
34
|
+
return promise(data) as API<T>;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
throw new Error(`@esportsplus/reactivity: 'reactive' received invalid input - ${JSON.stringify(data)}`);
|
|
35
38
|
};
|