rhythia-api 37.0.0 → 45.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/createUser.ts +23 -0
- package/api/editUser.ts +20 -9
- package/handleApi.ts +17 -0
- package/index.ts +3 -3
- package/package.json +5 -2
- package/scripts/update.ts +24 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
|
|
3
|
+
export const Schema = {
|
|
4
|
+
url: "/api/createUser",
|
|
5
|
+
input: z.object({
|
|
6
|
+
name: z.string(),
|
|
7
|
+
age: z.number(),
|
|
8
|
+
}),
|
|
9
|
+
output: z.object({
|
|
10
|
+
uid: z.string(),
|
|
11
|
+
}),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export async function GET(
|
|
15
|
+
res: Response
|
|
16
|
+
): Promise<(typeof Schema)["output"]["_type"]> {
|
|
17
|
+
const toParse = await res.json();
|
|
18
|
+
const data = Schema.input.parse(toParse);
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
uid: data.name,
|
|
22
|
+
};
|
|
23
|
+
}
|
package/api/editUser.ts
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
const request = await fetch(`https://rhythia.com/api/editUser`);
|
|
3
|
-
return request.json();
|
|
4
|
-
}
|
|
1
|
+
import z from "zod";
|
|
5
2
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export const Schema = {
|
|
4
|
+
url: "/api/editUser",
|
|
5
|
+
input: z.object({
|
|
6
|
+
name: z.string(),
|
|
7
|
+
age: z.number(),
|
|
8
|
+
}),
|
|
9
|
+
output: z.object({
|
|
10
|
+
uid: z.string(),
|
|
11
|
+
}),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export async function GET(
|
|
15
|
+
res: Response
|
|
16
|
+
): Promise<(typeof Schema)["output"]["_type"]> {
|
|
17
|
+
const toParse = await res.json();
|
|
18
|
+
const data = Schema.input.parse(toParse);
|
|
9
19
|
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
return {
|
|
21
|
+
uid: data.name,
|
|
22
|
+
};
|
|
12
23
|
}
|
package/handleApi.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export function handleApi<
|
|
4
|
+
T extends { url: string; input: z.ZodObject<any>; output: z.ZodObject<any> }
|
|
5
|
+
>(apiSchema: T) {
|
|
6
|
+
return async (input: T["input"]["_type"]): Promise<T["output"]["_type"]> => {
|
|
7
|
+
const response = await fetch(`https://test.com${apiSchema.url}`, {
|
|
8
|
+
method: "POST",
|
|
9
|
+
body: JSON.stringify(input),
|
|
10
|
+
headers: {
|
|
11
|
+
"Content-Type": "application/json",
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
const output = await response.json();
|
|
15
|
+
return output;
|
|
16
|
+
};
|
|
17
|
+
}
|
package/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
1
|
+
export { Schema as CreateUser } from "./api/createUser"
|
|
2
|
+
export { Schema as EditUser } from "./api/editUser"
|
|
3
|
+
export { handleApi } from "./handleApi"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rhythia-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "45.0.0",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"update": "bun scripts/update.ts",
|
|
@@ -10,9 +10,12 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@supabase/supabase-js": "^2.45.1",
|
|
12
12
|
"@types/bun": "^1.1.6",
|
|
13
|
+
"@types/lodash": "^4.17.7",
|
|
13
14
|
"@types/node": "^22.2.0",
|
|
14
15
|
"bun": "^1.1.22",
|
|
16
|
+
"lodash": "^4.17.21",
|
|
15
17
|
"supabase": "^1.188.4",
|
|
16
|
-
"tsx": "^4.17.0"
|
|
18
|
+
"tsx": "^4.17.0",
|
|
19
|
+
"zod": "^3.23.8"
|
|
17
20
|
}
|
|
18
21
|
}
|
package/scripts/update.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { $ } from "bun";
|
|
2
|
-
import { readFileSync, writeFileSync } from "fs";
|
|
2
|
+
import { readdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
+
import { upperFirst } from "lodash";
|
|
4
|
+
import path from "path";
|
|
3
5
|
const packageJson = JSON.parse(readFileSync("./package.json", "utf-8"));
|
|
4
6
|
|
|
5
7
|
const versions = packageJson.version.split(".");
|
|
@@ -9,6 +11,27 @@ packageJson.version = versions.join(".");
|
|
|
9
11
|
|
|
10
12
|
writeFileSync("./package.json", JSON.stringify(packageJson, null, 2));
|
|
11
13
|
|
|
14
|
+
const apis = readdirSync("./api");
|
|
15
|
+
|
|
16
|
+
const exports: string[] = [];
|
|
17
|
+
for (const api of apis) {
|
|
18
|
+
if (
|
|
19
|
+
!readFileSync(path.join("./api", api), "utf-8").includes(
|
|
20
|
+
"export const Schema"
|
|
21
|
+
)
|
|
22
|
+
) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
exports.push(
|
|
26
|
+
`export { Schema as ${upperFirst(path.parse(api).name)} } from "./api/${
|
|
27
|
+
path.parse(api).name
|
|
28
|
+
}"`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
exports.push(`export { handleApi } from "./handleApi"`);
|
|
32
|
+
|
|
33
|
+
writeFileSync("./index.ts", exports.join("\n"));
|
|
34
|
+
|
|
12
35
|
const conf = readFileSync("./.cred", "utf-8");
|
|
13
36
|
await $`npm logout`.nothrow();
|
|
14
37
|
await $`npm config set ${conf.split("$").join("")} && yarn publish`;
|