forked from FoundKeyGang/FoundKey
stash
This commit is contained in:
parent
4dac197dff
commit
e0c1d06f21
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "foundkey-api-schema",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "ts-node --esm -O '{\"module\":\"node16\", \"target\":\"es2022\"}' scripts/dump-json.ts",
|
||||
"prepack": "yarn build"
|
||||
},
|
||||
"main": "generated/lib.ts",
|
||||
"files": [
|
||||
"generated/lib.ts"
|
||||
],
|
||||
"devDependencies": {
|
||||
"openapi-typescript": "^5.4.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.8.3"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
import { writeFileSync, mkdirSync } from 'fs';
|
||||
import { schema } from '../src/openapi.js';
|
||||
import openapiTS from 'openapi-typescript';
|
||||
|
||||
mkdirSync('./generated', {recursive: true});
|
||||
writeFileSync('./generated/openapi.json', JSON.stringify(schema));
|
||||
writeFileSync('./lib.ts', await openapiTS(schema, {}));
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"$schema": "http://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"target": "es2020",
|
||||
"module": "es2020",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true,
|
||||
"rootDir": "./generated/",
|
||||
"outDir": "./built/",
|
||||
"removeComments": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"experimentalDecorators": true,
|
||||
"noImplicitReturns": true,
|
||||
"esModuleInterop": true,
|
||||
"moduleResolution": "Node16",
|
||||
"composite": true
|
||||
},
|
||||
"include": [
|
||||
"generated/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"test/**/*"
|
||||
]
|
||||
}
|
|
@ -25,6 +25,7 @@
|
|||
"@typescript-eslint/eslint-plugin": "5.36.2",
|
||||
"@typescript-eslint/parser": "^5.36.2",
|
||||
"eslint": "^8.23.0",
|
||||
"foundkey-api-schema": "workspace:*",
|
||||
"jest": "^27.4.5",
|
||||
"jest-fetch-mock": "^3.0.3",
|
||||
"jest-websocket-mock": "^2.2.1",
|
||||
|
@ -40,6 +41,7 @@
|
|||
"dependencies": {
|
||||
"autobind-decorator": "^2.4.0",
|
||||
"eventemitter3": "^4.0.7",
|
||||
"openapi-typescript-fetch": "^1.1.3",
|
||||
"reconnecting-websocket": "^4.4.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { Endpoints } from './api.types.js';
|
||||
|
||||
import * as schema from 'foundkey-api-schema';
|
||||
|
||||
const MK_API_ERROR = Symbol();
|
||||
|
||||
export type APIError = {
|
||||
|
@ -51,22 +53,9 @@ export class APIClient {
|
|||
this.fetch = opts.fetch || ((...args) => fetch(...args));
|
||||
}
|
||||
|
||||
public request<E extends keyof Endpoints, P extends Endpoints[E]['req']>(
|
||||
public request<E extends keyof schema.operations, T extends keyof schema.operations[E]['requestBody']['content'], P extends schema.operations[E]['requestBody']['content'][T]>(
|
||||
endpoint: E, params: P = {} as P, credential?: string | null | undefined,
|
||||
): Promise<Endpoints[E]['res'] extends { $switch: { $cases: [any, any][]; $default: any; }; }
|
||||
?
|
||||
IsCaseMatched<E, P, 0> extends true ? GetCaseResult<E, P, 0> :
|
||||
IsCaseMatched<E, P, 1> extends true ? GetCaseResult<E, P, 1> :
|
||||
IsCaseMatched<E, P, 2> extends true ? GetCaseResult<E, P, 2> :
|
||||
IsCaseMatched<E, P, 3> extends true ? GetCaseResult<E, P, 3> :
|
||||
IsCaseMatched<E, P, 4> extends true ? GetCaseResult<E, P, 4> :
|
||||
IsCaseMatched<E, P, 5> extends true ? GetCaseResult<E, P, 5> :
|
||||
IsCaseMatched<E, P, 6> extends true ? GetCaseResult<E, P, 6> :
|
||||
IsCaseMatched<E, P, 7> extends true ? GetCaseResult<E, P, 7> :
|
||||
IsCaseMatched<E, P, 8> extends true ? GetCaseResult<E, P, 8> :
|
||||
IsCaseMatched<E, P, 9> extends true ? GetCaseResult<E, P, 9> :
|
||||
Endpoints[E]['res']['$switch']['$default']
|
||||
: Endpoints[E]['res']>
|
||||
): Promise<schema.operations[E]['responses'] extends {'200': any} ? schema.operations[E]['responses']['200']['content']['application/json'] : null>
|
||||
{
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
this.fetch(`${this.origin}/api/${endpoint}`, {
|
||||
|
|
83
yarn.lock
83
yarn.lock
|
@ -7834,6 +7834,16 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"foundkey-api-schema@workspace:*, foundkey-api-schema@workspace:packages/foundkey-api-schema":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "foundkey-api-schema@workspace:packages/foundkey-api-schema"
|
||||
dependencies:
|
||||
openapi-typescript: ^5.4.1
|
||||
ts-node: ^10.9.1
|
||||
typescript: ^4.8.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"foundkey-js@workspace:*, foundkey-js@workspace:packages/foundkey-js":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "foundkey-js@workspace:packages/foundkey-js"
|
||||
|
@ -7846,10 +7856,12 @@ __metadata:
|
|||
autobind-decorator: ^2.4.0
|
||||
eslint: ^8.23.0
|
||||
eventemitter3: ^4.0.7
|
||||
foundkey-api-schema: "workspace:*"
|
||||
jest: ^27.4.5
|
||||
jest-fetch-mock: ^3.0.3
|
||||
jest-websocket-mock: ^2.2.1
|
||||
mock-socket: ^9.0.8
|
||||
openapi-typescript-fetch: ^1.1.3
|
||||
reconnecting-websocket: ^4.4.0
|
||||
ts-jest: ^27.1.5
|
||||
ts-node: 10.9.1
|
||||
|
@ -8368,6 +8380,13 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"globalyzer@npm:0.1.0":
|
||||
version: 0.1.0
|
||||
resolution: "globalyzer@npm:0.1.0"
|
||||
checksum: 419a0f95ba542534fac0842964d31b3dc2936a479b2b1a8a62bad7e8b61054faa9b0a06ad9f2e12593396b9b2621cac93358d9b3071d33723fb1778608d358a1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"globby@npm:^11.0.1, globby@npm:^11.0.4, globby@npm:^11.1.0":
|
||||
version: 11.1.0
|
||||
resolution: "globby@npm:11.1.0"
|
||||
|
@ -8382,6 +8401,13 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"globrex@npm:^0.1.2":
|
||||
version: 0.1.2
|
||||
resolution: "globrex@npm:0.1.2"
|
||||
checksum: adca162494a176ce9ecf4dd232f7b802956bb1966b37f60c15e49d2e7d961b66c60826366dc2649093cad5a0d69970cfa8875bd1695b5a1a2f33dcd2aa88da3c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"glogg@npm:^1.0.0":
|
||||
version: 1.0.2
|
||||
resolution: "glogg@npm:1.0.2"
|
||||
|
@ -11772,6 +11798,15 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"mime@npm:^3.0.0":
|
||||
version: 3.0.0
|
||||
resolution: "mime@npm:3.0.0"
|
||||
bin:
|
||||
mime: cli.js
|
||||
checksum: f43f9b7bfa64534e6b05bd6062961681aeb406a5b53673b53b683f27fcc4e739989941836a355eef831f4478923651ecc739f4a5f6e20a76487b432bfd4db928
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"mimic-fn@npm:^2.1.0":
|
||||
version: 2.1.0
|
||||
resolution: "mimic-fn@npm:2.1.0"
|
||||
|
@ -12729,6 +12764,29 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"openapi-typescript-fetch@npm:^1.1.3":
|
||||
version: 1.1.3
|
||||
resolution: "openapi-typescript-fetch@npm:1.1.3"
|
||||
checksum: df3171b0b1e8a99f2bdfb794b4dc348a1f4e5db184fabc7578a810236a5deb7bc7885240ecb2463c03d94707434784c48bd8256ea715b381f5ff91fb9218c7b6
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"openapi-typescript@npm:^5.4.1":
|
||||
version: 5.4.1
|
||||
resolution: "openapi-typescript@npm:5.4.1"
|
||||
dependencies:
|
||||
js-yaml: ^4.1.0
|
||||
mime: ^3.0.0
|
||||
prettier: ^2.6.2
|
||||
tiny-glob: ^0.2.9
|
||||
undici: ^5.4.0
|
||||
yargs-parser: ^21.0.1
|
||||
bin:
|
||||
openapi-typescript: bin/cli.js
|
||||
checksum: ab0e7613a478fcfa675887e50ff00fd6403ad6313357944408c11b420c08bbfa2bb58bff66c4e9a8c5670c79fe1a8d2f4ee85beceb004e72c529a97019b57c20
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"opentype.js@npm:^0.4.3":
|
||||
version: 0.4.11
|
||||
resolution: "opentype.js@npm:0.4.11"
|
||||
|
@ -13743,6 +13801,15 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"prettier@npm:^2.6.2":
|
||||
version: 2.7.1
|
||||
resolution: "prettier@npm:2.7.1"
|
||||
bin:
|
||||
prettier: bin-prettier.js
|
||||
checksum: 55a4409182260866ab31284d929b3cb961e5fdb91fe0d2e099dac92eaecec890f36e524b4c19e6ceae839c99c6d7195817579cdffc8e2c80da0cb794463a748b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"pretty-bytes@npm:^5.6.0":
|
||||
version: 5.6.0
|
||||
resolution: "pretty-bytes@npm:5.6.0"
|
||||
|
@ -16283,6 +16350,16 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"tiny-glob@npm:^0.2.9":
|
||||
version: 0.2.9
|
||||
resolution: "tiny-glob@npm:0.2.9"
|
||||
dependencies:
|
||||
globalyzer: 0.1.0
|
||||
globrex: ^0.1.2
|
||||
checksum: aea5801eb6663ddf77ebb74900b8f8bd9dfcfc9b6a1cc8018cb7421590c00bf446109ff45e4b64a98e6c95ddb1255a337a5d488fb6311930e2a95334151ec9c6
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"tinycolor2@npm:1.4.2":
|
||||
version: 1.4.2
|
||||
resolution: "tinycolor2@npm:1.4.2"
|
||||
|
@ -16512,7 +16589,7 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ts-node@npm:10.9.1":
|
||||
"ts-node@npm:10.9.1, ts-node@npm:^10.9.1":
|
||||
version: 10.9.1
|
||||
resolution: "ts-node@npm:10.9.1"
|
||||
dependencies:
|
||||
|
@ -16939,7 +17016,7 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"undici@npm:^5.2.0":
|
||||
"undici@npm:^5.2.0, undici@npm:^5.4.0":
|
||||
version: 5.10.0
|
||||
resolution: "undici@npm:5.10.0"
|
||||
checksum: 7ba2b71dccc74cd2bdf645b83e9aaef374ae04855943d0a2f42a3d0b9e5556f37cc9b5156fb5288277a2fa95fd46a56f3ae0d5cf73db3f008d75ec41104b136c
|
||||
|
@ -17956,7 +18033,7 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"yargs-parser@npm:^21.0.0":
|
||||
"yargs-parser@npm:^21.0.0, yargs-parser@npm:^21.0.1":
|
||||
version: 21.1.1
|
||||
resolution: "yargs-parser@npm:21.1.1"
|
||||
checksum: ed2d96a616a9e3e1cc7d204c62ecc61f7aaab633dcbfab2c6df50f7f87b393993fe6640d017759fe112d0cb1e0119f2b4150a87305cc873fd90831c6a58ccf1c
|
||||
|
|
Loading…
Reference in New Issue