Merge remote-tracking branch 'misskey/develop' into future-2024-04-10
This commit is contained in:
commit
a3b4ca782a
78 changed files with 3068 additions and 2243 deletions
|
@ -5,3 +5,4 @@ node_modules
|
|||
/jest.config.ts
|
||||
/test
|
||||
/test-d
|
||||
build.js
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
*/
|
||||
"mainEntryPointFilePath": "<projectFolder>/built/dts/index.d.ts",
|
||||
"mainEntryPointFilePath": "<projectFolder>/built/index.d.ts",
|
||||
|
||||
/**
|
||||
* A list of NPM package names whose exports should be treated as part of this package.
|
||||
|
|
105
packages/misskey-js/build.js
Normal file
105
packages/misskey-js/build.js
Normal file
|
@ -0,0 +1,105 @@
|
|||
import * as esbuild from "esbuild";
|
||||
import { build } from "esbuild";
|
||||
import { globSync } from "glob";
|
||||
import { execa } from "execa";
|
||||
import fs from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname } from "node:path";
|
||||
|
||||
const _filename = fileURLToPath(import.meta.url);
|
||||
const _dirname = dirname(_filename);
|
||||
const _package = JSON.parse(fs.readFileSync(_dirname + '/package.json', 'utf-8'));
|
||||
|
||||
const entryPoints = globSync("./src/**/**.{ts,tsx}");
|
||||
|
||||
/** @type {import('esbuild').BuildOptions} */
|
||||
const options = {
|
||||
entryPoints,
|
||||
minify: process.env.NODE_ENV === 'production',
|
||||
outdir: "./built",
|
||||
target: "es2022",
|
||||
platform: "browser",
|
||||
format: "esm",
|
||||
sourcemap: 'linked',
|
||||
};
|
||||
|
||||
// built配下をすべて削除する
|
||||
fs.rmSync('./built', { recursive: true, force: true });
|
||||
|
||||
if (process.argv.map(arg => arg.toLowerCase()).includes("--watch")) {
|
||||
await watchSrc();
|
||||
} else {
|
||||
await buildSrc();
|
||||
}
|
||||
|
||||
async function buildSrc() {
|
||||
console.log(`[${_package.name}] start building...`);
|
||||
|
||||
await build(options)
|
||||
.then(it => {
|
||||
console.log(`[${_package.name}] build succeeded.`);
|
||||
})
|
||||
.catch((err) => {
|
||||
process.stderr.write(err.stderr);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
console.log(`[${_package.name}] skip building d.ts because NODE_ENV is production.`);
|
||||
} else {
|
||||
await buildDts();
|
||||
}
|
||||
|
||||
console.log(`[${_package.name}] finish building.`);
|
||||
}
|
||||
|
||||
function buildDts() {
|
||||
return execa(
|
||||
'tsc',
|
||||
[
|
||||
'--project', 'tsconfig.json',
|
||||
'--outDir', 'built',
|
||||
'--declaration', 'true',
|
||||
'--emitDeclarationOnly', 'true',
|
||||
],
|
||||
{
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async function watchSrc() {
|
||||
const plugins = [{
|
||||
name: 'gen-dts',
|
||||
setup(build) {
|
||||
build.onStart(() => {
|
||||
console.log(`[${_package.name}] detect changed...`);
|
||||
});
|
||||
build.onEnd(async result => {
|
||||
if (result.errors.length > 0) {
|
||||
console.error(`[${_package.name}] watch build failed:`, result);
|
||||
return;
|
||||
}
|
||||
await buildDts();
|
||||
});
|
||||
},
|
||||
}];
|
||||
|
||||
console.log(`[${_package.name}] start watching...`)
|
||||
|
||||
const context = await esbuild.context({ ...options, plugins });
|
||||
await context.watch();
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
process.on('SIGHUP', resolve);
|
||||
process.on('SIGINT', resolve);
|
||||
process.on('SIGTERM', resolve);
|
||||
process.on('SIGKILL', resolve);
|
||||
process.on('uncaughtException', reject);
|
||||
process.on('exit', resolve);
|
||||
}).finally(async () => {
|
||||
await context.dispose();
|
||||
console.log(`[${_package.name}] finish watching.`);
|
||||
});
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -60,13 +60,17 @@ async function generateEndpoints(
|
|||
// misskey-jsはPOST固定で送っているので、こちらも決め打ちする。別メソッドに対応することがあればこちらも直す必要あり
|
||||
const paths = openApiDocs.paths ?? {};
|
||||
const postPathItems = Object.keys(paths)
|
||||
.map(it => paths[it]?.post)
|
||||
.map(it => ({
|
||||
_path_: it.replace(/^\//, ''),
|
||||
...paths[it]?.post,
|
||||
}))
|
||||
.filter(filterUndefined);
|
||||
|
||||
for (const operation of postPathItems) {
|
||||
const path = operation._path_;
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const operationId = operation.operationId!;
|
||||
const endpoint = new Endpoint(operationId);
|
||||
const endpoint = new Endpoint(path);
|
||||
endpoints.push(endpoint);
|
||||
|
||||
if (isRequestBodyObject(operation.requestBody)) {
|
||||
|
@ -76,19 +80,21 @@ async function generateEndpoints(
|
|||
// いまのところ複数のメディアタイプをとるエンドポイントは無いので決め打ちする
|
||||
endpoint.request = new OperationTypeAlias(
|
||||
operationId,
|
||||
path,
|
||||
supportMediaTypes[0],
|
||||
OperationsAliasType.REQUEST,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isResponseObject(operation.responses['200']) && operation.responses['200'].content) {
|
||||
if (operation.responses && isResponseObject(operation.responses['200']) && operation.responses['200'].content) {
|
||||
const resContent = operation.responses['200'].content;
|
||||
const supportMediaTypes = Object.keys(resContent);
|
||||
if (supportMediaTypes.length > 0) {
|
||||
// いまのところ複数のメディアタイプを返すエンドポイントは無いので決め打ちする
|
||||
endpoint.response = new OperationTypeAlias(
|
||||
operationId,
|
||||
path,
|
||||
supportMediaTypes[0],
|
||||
OperationsAliasType.RESPONSE,
|
||||
);
|
||||
|
@ -140,12 +146,19 @@ async function generateApiClientJSDoc(
|
|||
endpointsFileName: string,
|
||||
warningsOutputPath: string,
|
||||
) {
|
||||
const endpoints: { operationId: string; description: string; }[] = [];
|
||||
const endpoints: {
|
||||
operationId: string;
|
||||
path: string;
|
||||
description: string;
|
||||
}[] = [];
|
||||
|
||||
// misskey-jsはPOST固定で送っているので、こちらも決め打ちする。別メソッドに対応することがあればこちらも直す必要あり
|
||||
const paths = openApiDocs.paths ?? {};
|
||||
const postPathItems = Object.keys(paths)
|
||||
.map(it => paths[it]?.post)
|
||||
.map(it => ({
|
||||
_path_: it.replace(/^\//, ''),
|
||||
...paths[it]?.post,
|
||||
}))
|
||||
.filter(filterUndefined);
|
||||
|
||||
for (const operation of postPathItems) {
|
||||
|
@ -155,6 +168,7 @@ async function generateApiClientJSDoc(
|
|||
if (operation.description) {
|
||||
endpoints.push({
|
||||
operationId: operationId,
|
||||
path: operation._path_,
|
||||
description: operation.description,
|
||||
});
|
||||
}
|
||||
|
@ -175,7 +189,7 @@ async function generateApiClientJSDoc(
|
|||
' /**',
|
||||
` * ${endpoint.description.split('\n').join('\n * ')}`,
|
||||
' */',
|
||||
` request<E extends '${endpoint.operationId}', P extends Endpoints[E][\'req\']>(`,
|
||||
` request<E extends '${endpoint.path}', P extends Endpoints[E][\'req\']>(`,
|
||||
' endpoint: E,',
|
||||
' params: P,',
|
||||
' credential?: string | null,',
|
||||
|
@ -234,21 +248,24 @@ interface IOperationTypeAlias {
|
|||
|
||||
class OperationTypeAlias implements IOperationTypeAlias {
|
||||
public readonly operationId: string;
|
||||
public readonly path: string;
|
||||
public readonly mediaType: string;
|
||||
public readonly type: OperationsAliasType;
|
||||
|
||||
constructor(
|
||||
operationId: string,
|
||||
path: string,
|
||||
mediaType: string,
|
||||
type: OperationsAliasType,
|
||||
) {
|
||||
this.operationId = operationId;
|
||||
this.path = path;
|
||||
this.mediaType = mediaType;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
generateName(): string {
|
||||
const nameBase = this.operationId.replace(/\//g, '-');
|
||||
const nameBase = this.path.replace(/\//g, '-');
|
||||
return toPascal(nameBase + this.type);
|
||||
}
|
||||
|
||||
|
@ -281,19 +298,19 @@ const emptyRequest = new EmptyTypeAlias(OperationsAliasType.REQUEST);
|
|||
const emptyResponse = new EmptyTypeAlias(OperationsAliasType.RESPONSE);
|
||||
|
||||
class Endpoint {
|
||||
public readonly operationId: string;
|
||||
public readonly path: string;
|
||||
public request?: IOperationTypeAlias;
|
||||
public response?: IOperationTypeAlias;
|
||||
|
||||
constructor(operationId: string) {
|
||||
this.operationId = operationId;
|
||||
constructor(path: string) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
toLine(): string {
|
||||
const reqName = this.request?.generateName() ?? emptyRequest.generateName();
|
||||
const resName = this.response?.generateName() ?? emptyResponse.generateName();
|
||||
|
||||
return `'${this.operationId}': { req: ${reqName}; res: ${resName} };`;
|
||||
return `'${this.path}': { req: ${reqName}; res: ${resName} };`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,23 +3,21 @@
|
|||
"name": "misskey-js",
|
||||
"version": "2024.3.1",
|
||||
"description": "Misskey SDK for JavaScript",
|
||||
"types": "./built/dts/index.d.ts",
|
||||
"main": "./built/index.js",
|
||||
"types": "./built/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./built/esm/index.js",
|
||||
"types": "./built/dts/index.d.ts"
|
||||
"import": "./built/index.js",
|
||||
"types": "./built/index.d.ts"
|
||||
},
|
||||
"./*": {
|
||||
"import": "./built/esm/*",
|
||||
"types": "./built/dts/*"
|
||||
"import": "./built/*",
|
||||
"types": "./built/*"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run ts",
|
||||
"ts": "npm run ts-esm && npm run ts-dts",
|
||||
"ts-esm": "tsc --outDir built/esm",
|
||||
"ts-dts": "tsc --outDir built/dts --declaration true --emitDeclarationOnly true --declarationMap true",
|
||||
"watch": "nodemon -w src -e ts,js,cjs,mjs,json --exec \"pnpm run ts\"",
|
||||
"build": "node ./build.js",
|
||||
"watch": "nodemon -w package.json -e json --exec \"node ./build.js --watch\"",
|
||||
"tsd": "tsd",
|
||||
"api": "pnpm api-extractor run --local --verbose",
|
||||
"api-prod": "pnpm api-extractor run --verbose",
|
||||
|
@ -49,17 +47,16 @@
|
|||
"mock-socket": "9.3.1",
|
||||
"ncp": "2.0.0",
|
||||
"nodemon": "3.1.0",
|
||||
"execa": "8.0.1",
|
||||
"tsd": "0.30.7",
|
||||
"typescript": "5.3.3"
|
||||
"typescript": "5.3.3",
|
||||
"esbuild": "0.19.11",
|
||||
"glob": "10.3.10"
|
||||
},
|
||||
"files": [
|
||||
"built",
|
||||
"built/esm",
|
||||
"built/dts"
|
||||
"built"
|
||||
],
|
||||
"dependencies": {
|
||||
"@swc/cli": "0.1.63",
|
||||
"@swc/core": "1.3.105",
|
||||
"eventemitter3": "5.0.1",
|
||||
"reconnecting-websocket": "4.4.0"
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import './autogen/apiClientJSDoc.js';
|
|||
import { SwitchCaseResponseType } from './api.types.js';
|
||||
import type { Endpoints } from './api.types.js';
|
||||
|
||||
export {
|
||||
export type {
|
||||
SwitchCaseResponseType,
|
||||
} from './api.types.js';
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,17 +1,20 @@
|
|||
import { Endpoints } from './api.types.js';
|
||||
import { type Endpoints } from './api.types.js';
|
||||
import Stream, { Connection } from './streaming.js';
|
||||
import { Channels } from './streaming.types.js';
|
||||
import { Acct } from './acct.js';
|
||||
import { type Channels } from './streaming.types.js';
|
||||
import { type Acct } from './acct.js';
|
||||
import * as consts from './consts.js';
|
||||
|
||||
export {
|
||||
export type {
|
||||
Endpoints,
|
||||
Stream,
|
||||
Connection as ChannelConnection,
|
||||
Channels,
|
||||
Acct,
|
||||
};
|
||||
|
||||
export {
|
||||
Stream,
|
||||
Connection as ChannelConnection,
|
||||
};
|
||||
|
||||
export const permissions = consts.permissions;
|
||||
export const notificationTypes = consts.notificationTypes;
|
||||
export const noteVisibilities = consts.noteVisibilities;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"moduleResolution": "nodenext",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true,
|
||||
"sourceMap": false,
|
||||
"outDir": "./built/",
|
||||
"removeComments": true,
|
||||
"strict": true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue