mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 20:24:47 +00:00
chore: New sdk things
This commit is contained in:
@@ -4,34 +4,15 @@ export { guardAll, typeFromProps } from "./propertiesMatcher";
|
||||
export { default as nullIfEmpty } from "./nullIfEmpty";
|
||||
export { FileHelper } from "./fileHelper";
|
||||
|
||||
export function unwrapResultType<T>(res: T.ResultType<T>): T {
|
||||
if ("error-code" in res) {
|
||||
throw new Error(res["error-code"][1]);
|
||||
} else if ("error" in res) {
|
||||
throw new Error(res["error"]);
|
||||
} else {
|
||||
return res.result;
|
||||
}
|
||||
}
|
||||
|
||||
/** Used to check if the file exists before hand */
|
||||
export const exists = (
|
||||
effects: T.Effects,
|
||||
props: { path: string; volumeId: string }
|
||||
props: { path: string; volumeId: string },
|
||||
) =>
|
||||
effects.metadata(props).then(
|
||||
(_) => true,
|
||||
(_) => false
|
||||
(_) => false,
|
||||
);
|
||||
|
||||
export const errorCode = (code: number, error: string) => ({
|
||||
"error-code": [code, error] as const,
|
||||
});
|
||||
export const error = (error: string) => ({ error });
|
||||
export const okOf = <A>(result: A) => ({
|
||||
result,
|
||||
});
|
||||
export const ok = { result: null };
|
||||
|
||||
export const isKnownError = (e: unknown): e is T.KnownError =>
|
||||
e instanceof Object && ("error" in e || "error-code" in e);
|
||||
|
||||
Reference in New Issue
Block a user