mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-11-19 03:16:35 +01:00
27 lines
590 B
TypeScript
27 lines
590 B
TypeScript
import { Context } from 'cafy';
|
|
|
|
type Defs = {
|
|
params: { [key: string]: Context<any> }
|
|
};
|
|
|
|
export default function <T extends Defs>(defs: T, params: any): [{
|
|
[P in keyof T['params']]: ReturnType<T['params'][P]['get']>[0];
|
|
}, Error] {
|
|
const x: any = {};
|
|
let err: Error = null;
|
|
Object.keys(defs.params).some(k => {
|
|
const [v, e] = defs.params[k].get(params[k]);
|
|
if (e) {
|
|
err = e;
|
|
return true;
|
|
} else {
|
|
if (v === undefined && defs.params[k].data.default) {
|
|
x[k] = defs.params[k].data.default;
|
|
} else {
|
|
x[k] = v;
|
|
}
|
|
return false;
|
|
}
|
|
});
|
|
return [x, err];
|
|
}
|