Typing
This commit is contained in:
parent
b177a348b7
commit
15de87432b
@ -1,4 +1,4 @@
|
||||
import { safePath, timedExecution } from '$lib';
|
||||
import safePath, { timedExecution } from '$lib';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
describe('safe path', () => {
|
||||
@ -32,8 +32,8 @@ describe('safe path', () => {
|
||||
});
|
||||
|
||||
describe('timedExecution', () => {
|
||||
const asyncIdentity = async (v) => v;
|
||||
const identity = (v) => v;
|
||||
const asyncIdentity = async <T>(v: T): Promise<T> => v;
|
||||
const identity = <T>(v: T): T => v;
|
||||
|
||||
it('works with async', async () => {
|
||||
const { executionTime, result } = await timedExecution(() => asyncIdentity(5));
|
||||
|
@ -8,7 +8,7 @@ export const log = bunyan.createLogger({
|
||||
src: true,
|
||||
});
|
||||
|
||||
function safePath(basePath: string, name: string): boolean {
|
||||
const safePath = (basePath: string, name: string): boolean => {
|
||||
const fullPath = `${basePath}/${name}`;
|
||||
const relative = path.relative(basePath, fullPath);
|
||||
return (
|
||||
@ -20,7 +20,9 @@ function safePath(basePath: string, name: string): boolean {
|
||||
// result is not an absolute path
|
||||
!path.isAbsolute(relative)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default safePath;
|
||||
|
||||
const defaultPath: string = './uploads';
|
||||
if (!('STORAGE_PATH' in process.env)) {
|
||||
@ -30,8 +32,6 @@ export const storagePath: string = process.env.STORAGE_PATH ?? defaultPath;
|
||||
|
||||
export const requestIdHeader = 'x-request-id';
|
||||
|
||||
export default safePath;
|
||||
|
||||
export type MaybePromise<T> = T | Promise<T>;
|
||||
|
||||
export async function timedExecution<T>(
|
||||
|
Reference in New Issue
Block a user