mirror of
https://github.com/sern-handler/tools
synced 2026-06-06 01:16:59 +00:00
get lot of typings done
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@
|
||||
.yarn/cache
|
||||
#.pnp.*
|
||||
node_modules/**/*
|
||||
packages/poster/dts/discord.d.ts
|
||||
|
||||
1
.nrepl-port
Normal file
1
.nrepl-port
Normal file
@@ -0,0 +1 @@
|
||||
55388
|
||||
@@ -4,5 +4,8 @@
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
]
|
||||
],
|
||||
"devDependencies": {
|
||||
"openapi-typescript": "^6.7.2"
|
||||
}
|
||||
}
|
||||
|
||||
1
packages/.nrepl-port
Normal file
1
packages/.nrepl-port
Normal file
@@ -0,0 +1 @@
|
||||
49862
|
||||
71
packages/poster/dts/index.d.ts
vendored
71
packages/poster/dts/index.d.ts
vendored
@@ -1,32 +1,51 @@
|
||||
declare module 'index.js';
|
||||
|
||||
import type { paths } from './discord.d.ts'
|
||||
|
||||
type Method = "get" | "post" | "patch" | "put" | "delete"
|
||||
|
||||
type GlobalGetAll = paths["/applications/{application_id}/commands"]["get"]
|
||||
type GlobalGet = paths["/applications/{application_id}/commands/{command_id}"]["get"]
|
||||
type GlobalPost = paths["/applications/{application_id}/commands"]["post"]
|
||||
type GlobalEdit = paths["/applications/{application_id}/commands/{command_id}"]["patch"]
|
||||
type GlobalPut = paths["/applications/{application_id}/commands"]['put']
|
||||
type GlobalDelete = paths["/applications/{application_id}/commands/{command_id}"]["delete"]
|
||||
type GuildPost = paths["/applications/{application_id}/guilds/{guild_id}/commands"]["post"]
|
||||
type GuildGet = paths["/applications/{application_id}/guilds/{guild_id}/commands/{command_id}"]["get"]
|
||||
type GuildEdit = paths["/applications/{application_id}/guilds/{guild_id}/commands/{command_id}"]["patch"]
|
||||
type GuildDelete = paths["/applications/{application_id}/guilds/{guild_id}/commands/{command_id}"]["delete"]
|
||||
type GuildPut = paths["/applications/{application_id}/guilds/{guild_id}/commands"]["put"]
|
||||
|
||||
interface RoutesOptions {
|
||||
"global/get-all": [];
|
||||
"global/get": [GlobalGet["parameters"]["path"] & { application_id?: never }];
|
||||
"global/post": [{ body: GlobalPost["requestBody"]["content"]['application/json'] }
|
||||
& GlobalPost["parameters"]["path"]
|
||||
& { application_id?: never }];
|
||||
"global/edit": [{ body: GlobalEdit["requestBody"]["content"]['application/json']}
|
||||
& GlobalEdit["parameters"]["path"]
|
||||
& { application_id?: never }];
|
||||
"global/put": [{ body: GlobalPut["requestBody"]["content"]['application/json']}
|
||||
& GlobalPut["parameters"]['path']
|
||||
& { application_id?: never } ];
|
||||
"global/delete": [];
|
||||
"guild/post": [{ body: GuildPost["requestBody"]["content"]['application/json'] }];
|
||||
"guild/get": [GuildGet["parameters"]["path"] & { application_id?: never }];
|
||||
|
||||
"guild/edit": [{ body: GuildEdit["requestBody"]["content"]['application/json'] }
|
||||
& GuildEdit["parameters"]["path"]
|
||||
& { application_id?: never }];
|
||||
"guild/delete": [GuildDelete["parameters"]["path"] & { application_id?: never }];
|
||||
"guild/put": [{ body: GuildPut["requestBody"]["content"]['application/json']}
|
||||
& GuildPut["parameters"]["path"]
|
||||
& { application_id?: never }];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
interface Routes {
|
||||
"global/put": {
|
||||
body: {
|
||||
id?: string;
|
||||
name: string;
|
||||
name_localizations?: Record<string, unknown>
|
||||
description: string;
|
||||
description_localizations?: Record<string, unknown>
|
||||
/**
|
||||
* type of command, default = 1
|
||||
*/
|
||||
type?: number;
|
||||
nsfw?: boolean;
|
||||
default_permission?:boolean
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
default_member_permissions?: string;
|
||||
options?: Record<string,unknown>[]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
interface Send {
|
||||
<T extends keyof Routes>(command : T, opts: Routes[T]): Promise<Response>
|
||||
};
|
||||
<T extends keyof RoutesOptions>(command : T, ...opts: RoutesOptions[T]): Promise<Response>
|
||||
}
|
||||
|
||||
export default function (token: string, appid: string): Send;
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build:debug": "shadow-cljs compile poster && node -e \"require('fs').copyFileSync('dts/index.d.ts', 'dist/index.d.ts')\"",
|
||||
"build:release": "shadow-cljs release poster && node -e \"require('fs').copyFileSync('dts/index.d.ts', 'dist/index.d.ts')\"",
|
||||
"build:debug": "shadow-cljs compile poster",
|
||||
"build:release": "shadow-cljs release poster",
|
||||
"gen-discord-types": "npx openapi-typescript https://raw.githubusercontent.com/discord/discord-api-spec/main/specs/openapi.json --output ./dts/discord.d.ts",
|
||||
"repl": "shadow-cljs node-repl"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -8,4 +8,7 @@
|
||||
:builds
|
||||
{:poster {:target :node-library
|
||||
:output-to "dist/index.js"
|
||||
:exports-var core.poster/poster}}}
|
||||
:exports-var core.poster/poster
|
||||
:build-hooks
|
||||
[(dev.mv/hook 1 2 3)]
|
||||
}}}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
(def routes {
|
||||
:global/get-all ["GET" "/applications/{application.id}/commands"]
|
||||
:global/get ["GET" "/applications/{application.id}/commands/commands/{command.id}"]
|
||||
:global/get ["GET" "/applications/{application.id}/commands/{command.id}"]
|
||||
:global/post ["POST" "/applications/{application.id}/commands"]
|
||||
:global/edit ["PATCH" "/applications/{application.id}/commands/{command.id}"]
|
||||
:global/delete ["DELETE", "/applications/{application.id}/commands/{command.id}"]
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
(defn request-init [spec]
|
||||
(let [[method url] (routes spec)]
|
||||
[ url (fn [body headers]
|
||||
[url (fn [body headers]
|
||||
#js { "method" method
|
||||
"headers" headers
|
||||
"body" (.stringify js/JSON body )})
|
||||
@@ -29,8 +29,7 @@
|
||||
|
||||
(def actions (into {}
|
||||
(map (fn [[k v]] [(keyword->str k) (request-init k)]))
|
||||
routes
|
||||
))
|
||||
routes))
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
(let [header #js{ "Content-Type" "application/json"
|
||||
"Authorization" (str "Bot " token) }]
|
||||
(fn [action opts]
|
||||
(let [ [url mkrequest] (actions action)
|
||||
full-url (processed-url url #js { "app_id" appid
|
||||
"guild_id" (.-guild_id ^js opts)
|
||||
"command_id" (.-command_id ^js opts) })]
|
||||
(let [[url mkrequest] (actions action)
|
||||
full-url (processed-url url #js{"app_id" appid
|
||||
"guild_id" (.-guild_id ^js opts)
|
||||
"command_id" (.-command_id ^js opts)})]
|
||||
(js/fetch full-url (mkrequest (.-body ^js opts ) header))))))
|
||||
|
||||
9
packages/poster/src/dev/mv.clj
Normal file
9
packages/poster/src/dev/mv.clj
Normal file
@@ -0,0 +1,9 @@
|
||||
(ns dev.mv)
|
||||
|
||||
(defn hook
|
||||
{:shadow.build/stage :compile-finish}
|
||||
[build-state & args]
|
||||
(do
|
||||
(spit "./dist/discord.d.ts" (slurp "./dts/discord.d.ts"))
|
||||
(spit "./dist/index.d.ts" (slurp "./dts/index.d.ts")))
|
||||
build-state)
|
||||
@@ -3,7 +3,7 @@ import poster from '../dist/index.js';
|
||||
const send = poster("token", "appid");
|
||||
|
||||
|
||||
const req = await send("global/put", { });
|
||||
const req = await send("global/get-all");
|
||||
|
||||
|
||||
console.log(req);
|
||||
|
||||
79
yarn.lock
79
yarn.lock
@@ -1811,6 +1811,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@fastify/busboy@npm:^2.0.0":
|
||||
version: 2.1.0
|
||||
resolution: "@fastify/busboy@npm:2.1.0"
|
||||
checksum: 3233abd10f73e50668cb4bb278a79b7b3fadd30215ac6458299b0e5a09a29c3586ec07597aae6bd93f5cbedfcef43a8aeea51829cd28fc13850cdbcd324c28d5
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@isaacs/cliui@npm:^8.0.2":
|
||||
version: 8.0.2
|
||||
resolution: "@isaacs/cliui@npm:8.0.2"
|
||||
@@ -2263,6 +2270,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ansi-colors@npm:^4.1.3":
|
||||
version: 4.1.3
|
||||
resolution: "ansi-colors@npm:4.1.3"
|
||||
checksum: a9c2ec842038a1fabc7db9ece7d3177e2fe1c5dc6f0c51ecfbf5f39911427b89c00b5dc6b8bd95f82a26e9b16aaae2e83d45f060e98070ce4d1333038edceb0e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ansi-regex@npm:^2.0.0":
|
||||
version: 2.1.1
|
||||
resolution: "ansi-regex@npm:2.1.1"
|
||||
@@ -2340,6 +2354,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"argparse@npm:^2.0.1":
|
||||
version: 2.0.1
|
||||
resolution: "argparse@npm:2.0.1"
|
||||
checksum: 83644b56493e89a254bae05702abf3a1101b4fa4d0ca31df1c9985275a5a5bd47b3c27b7fa0b71098d41114d8ca000e6ed90cad764b306f8a503665e4d517ced
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"array-buffer-byte-length@npm:^1.0.0":
|
||||
version: 1.0.0
|
||||
resolution: "array-buffer-byte-length@npm:1.0.0"
|
||||
@@ -3871,6 +3892,19 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"fast-glob@npm:^3.3.1":
|
||||
version: 3.3.2
|
||||
resolution: "fast-glob@npm:3.3.2"
|
||||
dependencies:
|
||||
"@nodelib/fs.stat": ^2.0.2
|
||||
"@nodelib/fs.walk": ^1.2.3
|
||||
glob-parent: ^5.1.2
|
||||
merge2: ^1.3.0
|
||||
micromatch: ^4.0.4
|
||||
checksum: 900e4979f4dbc3313840078419245621259f349950411ca2fa445a2f9a1a6d98c3b5e7e0660c5ccd563aa61abe133a21765c6c0dec8e57da1ba71d8000b05ec1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"fastq@npm:^1.6.0":
|
||||
version: 1.15.0
|
||||
resolution: "fastq@npm:1.15.0"
|
||||
@@ -4806,6 +4840,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"js-yaml@npm:^4.1.0":
|
||||
version: 4.1.0
|
||||
resolution: "js-yaml@npm:4.1.0"
|
||||
dependencies:
|
||||
argparse: ^2.0.1
|
||||
bin:
|
||||
js-yaml: bin/js-yaml.js
|
||||
checksum: c7830dfd456c3ef2c6e355cc5a92e6700ceafa1d14bba54497b34a99f0376cecbb3e9ac14d3e5849b426d5a5140709a66237a8c991c675431271c4ce5504151a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"jsesc@npm:^2.5.1":
|
||||
version: 2.5.2
|
||||
resolution: "jsesc@npm:2.5.2"
|
||||
@@ -5534,6 +5579,22 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"openapi-typescript@npm:^6.7.2":
|
||||
version: 6.7.2
|
||||
resolution: "openapi-typescript@npm:6.7.2"
|
||||
dependencies:
|
||||
ansi-colors: ^4.1.3
|
||||
fast-glob: ^3.3.1
|
||||
js-yaml: ^4.1.0
|
||||
supports-color: ^9.4.0
|
||||
undici: ^5.27.2
|
||||
yargs-parser: ^21.1.1
|
||||
bin:
|
||||
openapi-typescript: bin/cli.js
|
||||
checksum: cec414943b930f60bd3b58fc0f5b996ac54e35261a4bd9a8c25e6a3a3395281f5288cb6231bc74cb8c3b60d58436a510d6628c53198722bd3dc6d1e2e3fe4aef
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"os-browserify@npm:^0.3.0":
|
||||
version: 0.3.0
|
||||
resolution: "os-browserify@npm:0.3.0"
|
||||
@@ -7232,6 +7293,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"supports-color@npm:^9.4.0":
|
||||
version: 9.4.0
|
||||
resolution: "supports-color@npm:9.4.0"
|
||||
checksum: cb8ff8daeaf1db642156f69a9aa545b6c01dd9c4def4f90a49f46cbf24be0c245d392fcf37acd119cd1819b99dad2cc9b7e3260813f64bcfd7f5b18b5a1eefb8
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"supports-preserve-symlinks-flag@npm:^1.0.0":
|
||||
version: 1.0.0
|
||||
resolution: "supports-preserve-symlinks-flag@npm:1.0.0"
|
||||
@@ -7368,6 +7436,8 @@ __metadata:
|
||||
"tools@workspace:.":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "tools@workspace:."
|
||||
dependencies:
|
||||
openapi-typescript: ^6.7.2
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -7602,6 +7672,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"undici@npm:^5.27.2":
|
||||
version: 5.28.2
|
||||
resolution: "undici@npm:5.28.2"
|
||||
dependencies:
|
||||
"@fastify/busboy": ^2.0.0
|
||||
checksum: f9e9335803f962fff07c3c11c6d50bbc76248bacf97035047155adb29c3622a65bd6bff23a22218189740133149d22e63b68131d8c40e78ac6cb4b6d686a6dfa
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"unicode-canonical-property-names-ecmascript@npm:^2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "unicode-canonical-property-names-ecmascript@npm:2.0.0"
|
||||
|
||||
Reference in New Issue
Block a user