lenix 1.8.4 → 1.8.6
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/nui/fetch.ts +7 -5
- package/package.json +1 -1
- package/shared/repeat.ts +23 -21
package/nui/fetch.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { NuiFetchGeneric, Request } from '../shared/types.ts'
|
|
2
|
-
import { palette } from '../shared/palette.ts'
|
|
3
2
|
|
|
4
3
|
declare function GetParentResourceName(): string
|
|
5
4
|
|
|
@@ -30,8 +29,11 @@ export const fetchNuiServer = async <T extends NuiFetchGeneric>(
|
|
|
30
29
|
timeout?: number,
|
|
31
30
|
): Promise<T[0]> => {
|
|
32
31
|
const { data, error } = await fetchNui<Request<{
|
|
33
|
-
data: T[0]
|
|
34
|
-
error:
|
|
32
|
+
data: T[0]
|
|
33
|
+
error: null
|
|
34
|
+
} | {
|
|
35
|
+
data: null
|
|
36
|
+
error: string
|
|
35
37
|
}, '__nuiServer', {
|
|
36
38
|
id: T[1]
|
|
37
39
|
data: {
|
|
@@ -46,11 +48,11 @@ export const fetchNuiServer = async <T extends NuiFetchGeneric>(
|
|
|
46
48
|
requestData,
|
|
47
49
|
}
|
|
48
50
|
})
|
|
49
|
-
if (error) {
|
|
51
|
+
if (error !== null) {
|
|
50
52
|
const typeofError = typeof error
|
|
51
53
|
if (typeofError === 'string') throw error
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
throw `Expected 'error' typeof 'string', got ${error} typeof ${typeofError}`
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
return data
|
package/package.json
CHANGED
package/shared/repeat.ts
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
/* */
|
|
2
|
-
export function repeat<T>(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
until: () => T,
|
|
7
|
-
equal: C,
|
|
2
|
+
export function repeat<T>(check: () => T): Promise<T>
|
|
3
|
+
export function repeat<T, C extends T>(
|
|
4
|
+
check: () => T,
|
|
5
|
+
untilOrEqual: C | ((checked: T) => checked is C),
|
|
8
6
|
each?: number,
|
|
9
7
|
): Promise<C>
|
|
10
|
-
export function repeat
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
each?: number
|
|
8
|
+
export function repeat<T>(
|
|
9
|
+
check: () => T,
|
|
10
|
+
untilOrEqual?: T | ((checked: T) => boolean),
|
|
11
|
+
each?: number,
|
|
14
12
|
): Promise<T> {
|
|
13
|
+
const hasCondition = arguments.length > 1
|
|
14
|
+
const predicate = typeof untilOrEqual === 'function'
|
|
15
|
+
? untilOrEqual as (checked: T) => boolean
|
|
16
|
+
: undefined
|
|
17
|
+
|
|
15
18
|
return new Promise(resolve => {
|
|
16
19
|
const interval = setInterval(() => {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
if (equal === undefined) {
|
|
20
|
-
if (result === undefined || result === null) return
|
|
21
|
-
resolve(result)
|
|
22
|
-
clearInterval(interval)
|
|
23
|
-
return
|
|
24
|
-
}
|
|
20
|
+
const checked = check()
|
|
25
21
|
|
|
26
|
-
|
|
22
|
+
const met = predicate
|
|
23
|
+
? predicate(checked)
|
|
24
|
+
: hasCondition
|
|
25
|
+
? checked === untilOrEqual
|
|
26
|
+
: checked !== undefined && checked !== null
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
if (!met) return
|
|
29
|
+
|
|
29
30
|
clearInterval(interval)
|
|
31
|
+
resolve(checked)
|
|
30
32
|
}, each)
|
|
31
33
|
})
|
|
32
|
-
}
|
|
34
|
+
}
|