Dependency upgrade + lib_um_crypto_rust (#78)

Co-authored-by: 鲁树人 <[email protected]>
Co-committed-by: 鲁树人 <[email protected]>
This commit is contained in:
鲁树人 authored and 鲁树人 committed 2024-09-24 22:19:30 +00:00
1 parent c5bc436ab2
commit 58c96f264b
65 files changed
+4160 -4025

No files matched your search

+1 -1
View File
@@ -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
View File
@@ -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;
}
}
-3
View File
@@ -1,3 +0,0 @@
export function formatHex(value: number, len = 8) {
return '0x' + (value | 0).toString(16).padStart(len, '0');
}
+7
View File
@@ -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];
}
}
+15
View File
@@ -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);
}
+3 -3
View File
@@ -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),
);
}