Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
feat: separate schema (#339)
Browse files Browse the repository at this point in the history
* feat: separate schema from gateway

* chore: update turbo config
  • Loading branch information
KagChi authored Feb 13, 2024
1 parent 0a83719 commit 2e5be4e
Show file tree
Hide file tree
Showing 43 changed files with 97 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# turbo cache
.turbo
28 changes: 28 additions & 0 deletions packages/kanao-schema/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@nezuchan/kanao-schema",
"version": "1.0.0",
"description": "Cache schema for Kanao Gateway",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.js"
},
"scripts": {
"build": "rimraf dist && tsc",
"lint": "eslint src",
"lint:fix": "eslint src --fix"
},
"keywords": [],
"author": "KagChi",
"license": "GPL-3.0",
"devDependencies": {
"drizzle-kit": "^0.20.14"
},
"dependencies": {
"drizzle-orm": "^0.29.3",
"tslib": "^2.6.2"
}
}
9 changes: 9 additions & 0 deletions packages/kanao-schema/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export * from "./Schema/member.js";
export * from "./Schema/user.js";
export * from "./Schema/roles.js";
export * from "./Schema/guild.js";
export * from "./Schema/channel.js";
export * from "./Schema/voice.js";
export * from "./Schema/message.js";
export * from "./Schema/session.js";
export * from "./Schema/status.js";
10 changes: 10 additions & 0 deletions packages/kanao-schema/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"sourceMap": true
},
"include": ["src"]
}
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
packages:
- 'services/*'
- 'services/*'
- 'packages/*'
1 change: 1 addition & 0 deletions services/kanao-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@discordjs/rest": "^2.2.0",
"@discordjs/ws": "^1.0.2",
"@nezuchan/constants": "^0.8.0",
"@nezuchan/kanao-schema": "workspace:^",
"@nezuchan/utilities": "^0.6.2",
"@sapphire/pieces": "^4.2.2",
"@sapphire/result": "^2.6.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { channels, channelsOverwrite } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayChannelCreateDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import { channels, channelsOverwrite } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateChannels } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { channels } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayChannelDeleteDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import { channels } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateChannels } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { channels, channelsOverwrite } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayChannelUpdateDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import { channels, channelsOverwrite } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateChannels } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { memberRoles, members, users } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayGuildMemberAddDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { memberRoles, members, users } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateUsers } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { members } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayGuildMemberRemoveDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import { members } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { memberRoles, members, users } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayGuildMemberUpdateDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import { memberRoles, members, users } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateMembers, stateUsers } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { members, users } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayGuildMembersChunkDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { members, users } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateMembers, stateUsers } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { roles } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayGuildRoleCreateDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { roles } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateRoles } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { roles } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayGuildRoleDeleteDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import { roles } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { roles } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayGuildRoleUpdateDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { roles } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateRoles } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { channels, channelsOverwrite, guilds, guildsRoles, memberRoles, members, roles, users, voiceStates } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayGuildCreateDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import { channels, channelsOverwrite, guilds, guildsRoles, memberRoles, members, roles, users, voiceStates } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateChannels, stateMembers, stateRoles, stateUsers, stateVoices } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { guilds } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayGuildDeleteDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import { guilds } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { guilds } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayGuildUpdateDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { guilds } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { memberRoles, members, messages, users } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayMessageCreateDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import { memberRoles, members, messages, users } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateMembers, stateMessages, stateUsers } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { messages } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayMessageDeleteBulkDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { inArray } from "drizzle-orm";
import { messages } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { messages } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayMessageDeleteDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import { messages } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { members, messages, users } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayMessageUpdateDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { members, messages, users } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateMembers, stateMessages, stateUsers } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { users } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayUserUpdateDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import { users } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Buffer } from "node:buffer";
import { RabbitMQ } from "@nezuchan/constants";
import { memberRoles, members, users, voiceStates } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayVoiceStateUpdateDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import { memberRoles, members, users, voiceStates } from "../../../Schema/index.js";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateMembers, stateUsers, stateVoices } from "../../../config.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { WebSocketShard } from "@discordjs/ws";
import { WebSocketShardEvents } from "@discordjs/ws";
import { status } from "../Schema/collections/status.js";
import { status } from "@nezuchan/kanao-schema";
import type { ListenerContext } from "../Stores/Listener.js";
import { Listener } from "../Stores/Listener.js";

Expand Down
2 changes: 1 addition & 1 deletion services/kanao-gateway/src/Listeners/ReadyListener.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WebSocketShardEvents } from "@discordjs/ws";
import { guilds } from "@nezuchan/kanao-schema";
import type { GatewayReadyDispatch } from "discord-api-types/v10";
import { guilds } from "../Schema/index.js";
import type { ListenerContext } from "../Stores/Listener.js";
import { Listener } from "../Stores/Listener.js";

Expand Down
9 changes: 0 additions & 9 deletions services/kanao-gateway/src/Schema/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion services/kanao-gateway/src/Structures/NezuGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { REST } from "@discordjs/rest";
import { CompressionMethod, WebSocketManager, WebSocketShardEvents, WebSocketShardStatus } from "@discordjs/ws";
import type { SessionInfo, ShardRange } from "@discordjs/ws";
import { RabbitMQ } from "@nezuchan/constants";
import * as schema from "@nezuchan/kanao-schema";
import { Util, createAmqpChannel, RoutingKey } from "@nezuchan/utilities";
import type { Channel } from "amqplib";
import { eq } from "drizzle-orm";
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import APM from "prometheus-middleware";
import * as schema from "../Schema/index.js";
import { createLogger } from "../Utilities/Logger.js";
import { ProcessShardingStrategy } from "../Utilities/WebSockets/ProcessShardingStrategy.js";
import { amqp, clientId, databaseUrl, discordToken, enablePrometheus, gatewayCompression, gatewayGuildPerShard, gatewayHandShakeTimeout, gatewayHelloTimeout, gatewayIntents, gatewayLargeThreshold, gatewayPresenceName, gatewayPresenceStatus, gatewayPresenceType, gatewayReadyTimeout, gatewayResume, gatewayShardCount, gatewayShardsPerWorkers, getShardCount, lokiHost, prometheusPath, prometheusPort, proxy, replicaId, storeLogs } from "../config.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import { Collection } from "@discordjs/collection";
import type { BootstrapOptions, WorkerReceivePayload, WorkerSendPayload, WorkerData, WebSocketShardDestroyOptions } from "@discordjs/ws";
import { WebSocketShardEvents, WebSocketShard, WorkerReceivePayloadOp, WorkerSendPayloadOp } from "@discordjs/ws";
import { RabbitMQ, ShardOp } from "@nezuchan/constants";
import * as schema from "@nezuchan/kanao-schema";
import { RoutingKey, RoutingKeyToId, createAmqpChannel } from "@nezuchan/utilities";
import { StoreRegistry } from "@sapphire/pieces";
import type { Channel, ConsumeMessage } from "amqplib";
import type { GatewaySendPayload } from "discord-api-types/v10";
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "../../Schema/index.js";
import type { Listener } from "../../Stores/Listener.js";
import { ListenerStore } from "../../Stores/ListenerStore.js";
import { discordToken, storeLogs, lokiHost, amqp, databaseUrl, clientId } from "../../config.js";
Expand Down
3 changes: 2 additions & 1 deletion services/kanao-gateway/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
"rootDir": "src",
"noEmit": true
},
"include": ["src"]
}
Loading

0 comments on commit 2e5be4e

Please sign in to comment.