mirror of
https://git.um-react.app/um/um-react.git
synced 2026-11-25 22:56:59 +00:00
Dependency upgrade + lib_um_crypto_rust (#78)
Co-authored-by: 鲁树人 <[email protected]> Co-committed-by: 鲁树人 <[email protected]>
This commit is contained in:
1 parent
c5bc436ab2
commit
58c96f264b
65 files changed
+4160
-4025
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { bytesToUTF8String } from '~/decrypt-worker/util/utf8Encoder';
|
||||
import { formatHex } from './formatHex';
|
||||
import { formatHex } from './hex.ts';
|
||||
|
||||
export class MMKVParser {
|
||||
private offset = 4;
|
||||
|
||||
+7
-14
@@ -1,20 +1,13 @@
|
||||
function isPromise<T = unknown>(p: unknown): p is Promise<T> {
|
||||
return !!p && typeof p === 'object' && 'then' in p && 'catch' in p && 'finally' in p;
|
||||
}
|
||||
|
||||
export function wrapFunctionCall<R = unknown>(pre: () => void, post: () => void, fn: () => R): R {
|
||||
export async function wrapFunctionCall<R = unknown>(
|
||||
pre: () => void,
|
||||
post: () => void,
|
||||
fn: () => Promise<R>,
|
||||
): Promise<R> {
|
||||
pre();
|
||||
|
||||
try {
|
||||
const result = fn();
|
||||
|
||||
if (isPromise(result)) {
|
||||
result.finally(post);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
return await fn();
|
||||
} finally {
|
||||
post();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export function formatHex(value: number, len = 8) {
|
||||
return '0x' + (value | 0).toString(16).padStart(len, '0');
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export async function go<T = unknown, E = Error>(promise: Promise<T>): Promise<[T, null] | [null, E]> {
|
||||
try {
|
||||
return [await promise, null];
|
||||
} catch (error: unknown) {
|
||||
return [null, error as E];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
export function formatHex(value: number, len = 8) {
|
||||
return '0x' + (value | 0).toString(16).padStart(len, '0');
|
||||
}
|
||||
|
||||
export function hex(value: Uint8Array): string {
|
||||
return Array.from(value, (byte) => byte.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
|
||||
export function unhex(value: string): Uint8Array {
|
||||
const bytes = [];
|
||||
for (const [byte] of value.matchAll(/[0-9a-fA-F]{2}/g)) {
|
||||
bytes.push(parseInt(byte, 16));
|
||||
}
|
||||
return new Uint8Array(bytes);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { wrapFunctionCall } from './fnWrapper';
|
||||
|
||||
export function timedLogger<R = unknown>(label: string, fn: () => R): R {
|
||||
export async function timedLogger<R = unknown>(label: string, fn: () => Promise<R>): Promise<R> {
|
||||
if (import.meta.env.VITE_ENABLE_PERF_LOG !== '1') {
|
||||
return fn();
|
||||
} else {
|
||||
@@ -12,13 +12,13 @@ export function timedLogger<R = unknown>(label: string, fn: () => R): R {
|
||||
}
|
||||
}
|
||||
|
||||
export function withGroupedLogs<R = unknown>(label: string, fn: () => R): R {
|
||||
export async function withGroupedLogs<R = unknown>(label: string, fn: () => Promise<R>): Promise<R> {
|
||||
if (import.meta.env.VITE_ENABLE_PERF_LOG !== '1') {
|
||||
return fn();
|
||||
} else {
|
||||
return wrapFunctionCall(
|
||||
() => console.group(label),
|
||||
() => (console.groupEnd as (label: string) => void)(label),
|
||||
() => console.groupEnd(),
|
||||
() => timedLogger(`${label}/total`, fn),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user