rhythia-api 97.0.0 → 99.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/handleApi.ts CHANGED
@@ -1,19 +1,19 @@
1
- import { z } from "zod";
2
- let env = "development";
3
- export function setEnvironment(
4
- stage: "development" | "testing" | "production"
5
- ) {
6
- env = stage;
7
- }
8
- export function handleApi<
9
- T extends { url: string; input: z.ZodObject<any>; output: z.ZodObject<any> }
10
- >(apiSchema: T) {
11
- return async (input: T["input"]["_type"]): Promise<T["output"]["_type"]> => {
12
- const response = await fetch(`https://${env}.rhythia.com${apiSchema.url}`, {
13
- method: "POST",
14
- body: JSON.stringify(input),
15
- });
16
- const output = await response.json();
17
- return output;
18
- };
19
- }
1
+ import { z } from "zod";
2
+ let env = "development";
3
+ export function setEnvironment(
4
+ stage: "development" | "testing" | "production"
5
+ ) {
6
+ env = stage;
7
+ }
8
+ export function handleApi<
9
+ T extends { url: string; input: z.ZodObject<any>; output: z.ZodObject<any> }
10
+ >(apiSchema: T) {
11
+ return async (input: T["input"]["_type"]): Promise<T["output"]["_type"]> => {
12
+ const response = await fetch(`https://${env}.rhythia.com${apiSchema.url}`, {
13
+ method: "POST",
14
+ body: JSON.stringify(input),
15
+ });
16
+ const output = await response.json();
17
+ return output;
18
+ };
19
+ }
package/index.html CHANGED
@@ -1,3 +1,3 @@
1
- <html>
2
- <div>Rhythia API</div>
1
+ <html>
2
+ <div>Rhythia API</div>
3
3
  </html>
package/index.ts CHANGED
@@ -1,29 +1,34 @@
1
1
  import { handleApi } from "./handleApi"
2
2
 
3
- // ./api/getPublicStats.ts API
4
- import { Schema as GetPublicStats } from "./api/getPublicStats"
5
- export { Schema as SchemaGetPublicStats } from "./api/getPublicStats"
6
- export const getPublicStats = handleApi({url:"/api/getPublicStats",...GetPublicStats})
7
-
8
- // ./api/getUserScores.ts API
9
- import { Schema as GetUserScores } from "./api/getUserScores"
10
- export { Schema as SchemaGetUserScores } from "./api/getUserScores"
11
- export const getUserScores = handleApi({url:"/api/getUserScores",...GetUserScores})
12
-
13
3
  // ./api/editProfile.ts API
14
4
  import { Schema as EditProfile } from "./api/editProfile"
15
5
  export { Schema as SchemaEditProfile } from "./api/editProfile"
16
6
  export const editProfile = handleApi({url:"/api/editProfile",...EditProfile})
17
7
 
8
+ // ./api/getLeaderboard.ts API
9
+ import { Schema as GetLeaderboard } from "./api/getLeaderboard"
10
+ export { Schema as SchemaGetLeaderboard } from "./api/getLeaderboard"
11
+ export const getLeaderboard = handleApi({url:"/api/getLeaderboard",...GetLeaderboard})
12
+
18
13
  // ./api/getProfile.ts API
19
14
  import { Schema as GetProfile } from "./api/getProfile"
20
15
  export { Schema as SchemaGetProfile } from "./api/getProfile"
21
16
  export const getProfile = handleApi({url:"/api/getProfile",...GetProfile})
22
17
 
23
- // ./api/getLeaderboard.ts API
24
- import { Schema as GetLeaderboard } from "./api/getLeaderboard"
25
- export { Schema as SchemaGetLeaderboard } from "./api/getLeaderboard"
26
- export const getLeaderboard = handleApi({url:"/api/getLeaderboard",...GetLeaderboard})
18
+ // ./api/getPublicStats.ts API
19
+ import { Schema as GetPublicStats } from "./api/getPublicStats"
20
+ export { Schema as SchemaGetPublicStats } from "./api/getPublicStats"
21
+ export const getPublicStats = handleApi({url:"/api/getPublicStats",...GetPublicStats})
22
+
23
+ // ./api/getScore.ts API
24
+ import { Schema as GetScore } from "./api/getScore"
25
+ export { Schema as SchemaGetScore } from "./api/getScore"
26
+ export const getScore = handleApi({url:"/api/getScore",...GetScore})
27
+
28
+ // ./api/getUserScores.ts API
29
+ import { Schema as GetUserScores } from "./api/getUserScores"
30
+ export { Schema as SchemaGetUserScores } from "./api/getUserScores"
31
+ export const getUserScores = handleApi({url:"/api/getUserScores",...GetUserScores})
27
32
 
28
33
  // ./api/searchUsers.ts API
29
34
  import { Schema as SearchUsers } from "./api/searchUsers"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "97.0.0",
3
+ "version": "99.0.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "update": "bun ./scripts/update.ts",
@@ -1,76 +1,76 @@
1
- import fs from "fs";
2
- import * as git from "isomorphic-git";
3
- import http from "isomorphic-git/http/node";
4
- import path from "path";
5
-
6
- // Set up the repository URL
7
- const repoUrl = `https://${process.env.GIT_KEY}@github.com/cunev/rhythia-api.git`;
8
-
9
- const sourceBranch = process.env.SOURCE_BRANCH!;
10
- const targetBranch = process.env.TARGET_BRANCH!;
11
-
12
- async function cloneBranch() {
13
- const dir = path.join("/tmp", "repo");
14
-
15
- try {
16
- // Ensure the directory is clean before cloning
17
- if (fs.existsSync(dir)) {
18
- fs.rmdirSync(dir, { recursive: true });
19
- console.log(`Deleted existing directory: ${dir}`);
20
- }
21
-
22
- // Clone the repository into a temporary directory
23
- await git.clone({
24
- fs,
25
- http,
26
- dir,
27
- url: repoUrl,
28
- ref: sourceBranch,
29
- singleBranch: true,
30
- depth: 1,
31
- });
32
- console.log(`Cloned ${sourceBranch} branch from remote repository.`);
33
-
34
- // Check out the source branch
35
- await git.checkout({ fs, dir, ref: sourceBranch });
36
- console.log(`Checked out to branch: ${sourceBranch}`);
37
-
38
- // Pull the latest changes from the source branch
39
- await git.pull({
40
- fs,
41
- http,
42
- dir,
43
- ref: sourceBranch,
44
- singleBranch: true,
45
- author: {
46
- name: process.env.GIT_USER,
47
- email: "you@example.com", // Replace with the actual email
48
- },
49
- });
50
- console.log(`Pulled latest changes from branch: ${sourceBranch}`);
51
-
52
- // Create and checkout the target branch from the source branch
53
- await git.branch({ fs, dir, ref: targetBranch });
54
- await git.checkout({ fs, dir, ref: targetBranch });
55
- console.log(`Created and checked out to branch: ${targetBranch}`);
56
-
57
- // Push the new branch to the remote repository
58
- await git.push({
59
- fs,
60
- http,
61
- dir,
62
- remote: "origin",
63
- ref: targetBranch,
64
- force: true,
65
- onAuth: () => ({
66
- username: process.env.GIT_KEY, // GitHub token or password
67
- password: "",
68
- }),
69
- });
70
- console.log(`Pushed new branch to remote: ${targetBranch}`);
71
- } catch (error) {
72
- console.error("Error performing Git operations:", error.message);
73
- }
74
- }
75
-
76
- cloneBranch();
1
+ import fs from "fs";
2
+ import * as git from "isomorphic-git";
3
+ import http from "isomorphic-git/http/node";
4
+ import path from "path";
5
+
6
+ // Set up the repository URL
7
+ const repoUrl = `https://${process.env.GIT_KEY}@github.com/cunev/rhythia-api.git`;
8
+
9
+ const sourceBranch = process.env.SOURCE_BRANCH!;
10
+ const targetBranch = process.env.TARGET_BRANCH!;
11
+
12
+ async function cloneBranch() {
13
+ const dir = path.join("/tmp", "repo");
14
+
15
+ try {
16
+ // Ensure the directory is clean before cloning
17
+ if (fs.existsSync(dir)) {
18
+ fs.rmdirSync(dir, { recursive: true });
19
+ console.log(`Deleted existing directory: ${dir}`);
20
+ }
21
+
22
+ // Clone the repository into a temporary directory
23
+ await git.clone({
24
+ fs,
25
+ http,
26
+ dir,
27
+ url: repoUrl,
28
+ ref: sourceBranch,
29
+ singleBranch: true,
30
+ depth: 1,
31
+ });
32
+ console.log(`Cloned ${sourceBranch} branch from remote repository.`);
33
+
34
+ // Check out the source branch
35
+ await git.checkout({ fs, dir, ref: sourceBranch });
36
+ console.log(`Checked out to branch: ${sourceBranch}`);
37
+
38
+ // Pull the latest changes from the source branch
39
+ await git.pull({
40
+ fs,
41
+ http,
42
+ dir,
43
+ ref: sourceBranch,
44
+ singleBranch: true,
45
+ author: {
46
+ name: process.env.GIT_USER,
47
+ email: "you@example.com", // Replace with the actual email
48
+ },
49
+ });
50
+ console.log(`Pulled latest changes from branch: ${sourceBranch}`);
51
+
52
+ // Create and checkout the target branch from the source branch
53
+ await git.branch({ fs, dir, ref: targetBranch });
54
+ await git.checkout({ fs, dir, ref: targetBranch });
55
+ console.log(`Created and checked out to branch: ${targetBranch}`);
56
+
57
+ // Push the new branch to the remote repository
58
+ await git.push({
59
+ fs,
60
+ http,
61
+ dir,
62
+ remote: "origin",
63
+ ref: targetBranch,
64
+ force: true,
65
+ onAuth: () => ({
66
+ username: process.env.GIT_KEY, // GitHub token or password
67
+ password: "",
68
+ }),
69
+ });
70
+ console.log(`Pushed new branch to remote: ${targetBranch}`);
71
+ } catch (error) {
72
+ console.error("Error performing Git operations:", error.message);
73
+ }
74
+ }
75
+
76
+ cloneBranch();
package/scripts/update.ts CHANGED
@@ -1,49 +1,49 @@
1
- import { $ } from "bun";
2
- import { readdirSync, readFileSync, writeFileSync } from "fs";
3
- import { lowerFirst, upperFirst } from "lodash";
4
- import path from "path";
5
- const packageJson = JSON.parse(readFileSync("./package.json", "utf-8"));
6
-
7
- const versions = packageJson.version.split(".");
8
- versions[0] = Number(versions[0]) + 1;
9
-
10
- packageJson.version = versions.join(".");
11
-
12
- writeFileSync("./package.json", JSON.stringify(packageJson, null, 2));
13
-
14
- const apis = readdirSync("./api");
15
-
16
- const exports: string[] = [];
17
- exports.push(`import { handleApi } from "./handleApi"`);
18
-
19
- for (const api of apis) {
20
- if (
21
- !readFileSync(path.join("./api", api), "utf-8").includes(
22
- "export const Schema"
23
- )
24
- ) {
25
- continue;
26
- }
27
- exports.push(`\n// ./api/${api} API`);
28
-
29
- const apiName = path.parse(api).name;
30
- exports.push(
31
- `import { Schema as ${upperFirst(apiName)} } from "./api/${apiName}"`
32
- );
33
- exports.push(
34
- `export { Schema as Schema${upperFirst(apiName)} } from "./api/${apiName}"`
35
- );
36
-
37
- exports.push(
38
- `export const ${lowerFirst(
39
- apiName
40
- )} = handleApi({url:"/api/${apiName}",...${upperFirst(apiName)}})`
41
- );
42
- }
43
- exports.push(`export { handleApi } from "./handleApi"`);
44
-
45
- writeFileSync("./index.ts", exports.join("\n"));
46
-
47
- // const conf = readFileSync("./.cred", "utf-8");
48
- // await $`npm logout`.nothrow();
49
- await $`yarn publish`;
1
+ import { $ } from "bun";
2
+ import { readdirSync, readFileSync, writeFileSync } from "fs";
3
+ import { lowerFirst, upperFirst } from "lodash";
4
+ import path from "path";
5
+ const packageJson = JSON.parse(readFileSync("./package.json", "utf-8"));
6
+
7
+ const versions = packageJson.version.split(".");
8
+ versions[0] = Number(versions[0]) + 1;
9
+
10
+ packageJson.version = versions.join(".");
11
+
12
+ writeFileSync("./package.json", JSON.stringify(packageJson, null, 2));
13
+
14
+ const apis = readdirSync("./api");
15
+
16
+ const exports: string[] = [];
17
+ exports.push(`import { handleApi } from "./handleApi"`);
18
+
19
+ for (const api of apis) {
20
+ if (
21
+ !readFileSync(path.join("./api", api), "utf-8").includes(
22
+ "export const Schema"
23
+ )
24
+ ) {
25
+ continue;
26
+ }
27
+ exports.push(`\n// ./api/${api} API`);
28
+
29
+ const apiName = path.parse(api).name;
30
+ exports.push(
31
+ `import { Schema as ${upperFirst(apiName)} } from "./api/${apiName}"`
32
+ );
33
+ exports.push(
34
+ `export { Schema as Schema${upperFirst(apiName)} } from "./api/${apiName}"`
35
+ );
36
+
37
+ exports.push(
38
+ `export const ${lowerFirst(
39
+ apiName
40
+ )} = handleApi({url:"/api/${apiName}",...${upperFirst(apiName)}})`
41
+ );
42
+ }
43
+ exports.push(`export { handleApi } from "./handleApi"`);
44
+
45
+ writeFileSync("./index.ts", exports.join("\n"));
46
+
47
+ // const conf = readFileSync("./.cred", "utf-8");
48
+ // await $`npm logout`.nothrow();
49
+ await $`yarn publish`;