Skip to content

Commit

Permalink
🔀 Merge pull request #164 from hemedani/main
Browse files Browse the repository at this point in the history
♿ add lesanApi function while declaration creation
  • Loading branch information
hemedani committed May 28, 2024
2 parents b181924 + d8da419 commit cf945fe
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions src/types/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const generateSchemTypes = async (
const schemaStruct = createStruct(schemas, schema);

str = str + `
export const ${schema}Strutct = ${JSON.stringify(schemaStruct, null, 2)};\n
export type ${schema}Schema = ${
generateTypesFromStruct({ schemaStruct })
};\n
Expand Down Expand Up @@ -71,7 +70,55 @@ export const generateSchemTypes = async (
}
}
str = str + `
}\n
};\n
`;

str = str + `
export const lesanApi = (
{ URL, settings, baseHeaders }: {
URL: string;
settings?: Record<string, any>;
baseHeaders?: Record<string, any>;
},
) => {
const setting = {
method: "POST",
headers: {
"Content-Type": "application/json",
...baseHeaders,
},
...settings,
};
const send = async <
TService extends keyof ReqType,
TModel extends keyof ReqType[TService],
TAct extends keyof ReqType[TService][TModel],
TSet extends Partial<ReqType[TService][TModel][TAct]["set"]>,
TGet extends Partial<ReqType[TService][TModel][TAct]["get"]>,
>(body: {
service?: TService;
model: TModel;
act: TAct;
details: {
set: TSet;
get: TGet;
};
}, additionalHeaders?: Record<string, any>) => {
const req = await fetch(URL, {
...setting,
headers: {
...setting.headers,
...additionalHeaders,
},
body: JSON.stringify(body),
});
return await req.json();
};
return { send };
};\n
`;

await ensureDir("./declarations");
Expand Down

0 comments on commit cf945fe

Please sign in to comment.