Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

バックエンドが生成するapi.jsonからmisskey-jsの型を作成する #12434

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ddeeda9
ひとまず生成できるところまで
samunohito Nov 23, 2023
27c07cc
ファイル構成整理
samunohito Nov 23, 2023
6a46a80
生成コマンド整理
samunohito Nov 23, 2023
9e59a16
misskey-jsへの組み込み
samunohito Nov 24, 2023
a16e357
fix generator.ts
samunohito Nov 24, 2023
4e87a31
wip
samunohito Nov 24, 2023
19cee66
fix generator.ts
samunohito Nov 24, 2023
3ee2723
fix package.json
samunohito Nov 24, 2023
5f88d62
生成ロジックの調整
samunohito Nov 25, 2023
de37897
型レベルでのswitch-case機構をmisskey-jsからfrontendに持ち込めるようにした
samunohito Nov 25, 2023
bfc9187
型チェック用のtsconfig.jsonを作成
samunohito Nov 25, 2023
0add5d0
他のエンドポイントを呼ぶ関数にも適用
samunohito Nov 25, 2023
62e15ab
未使用エンティティなどを削除
samunohito Nov 25, 2023
0874bd9
misskey-js側で手動定義されていた型を自動生成された型に移行(ただしapi.jsonがvalidでなくなってしまったので後で修正する)
samunohito Nov 25, 2023
6a9fd7d
messagingは廃止されている(テストのビルドエラー解消)
samunohito Nov 25, 2023
fef0671
validなapi.jsonを出力できるように修正
samunohito Nov 26, 2023
058ccb9
修正漏れ対応
samunohito Nov 26, 2023
508e18c
Ajvに怒られて起動できなかったところを修正
samunohito Nov 26, 2023
657bf5f
Merge branch 'develop' into enhance/misskey-js-type-autogen
samunohito Nov 26, 2023
d62d5a8
fix ci(途中)
samunohito Nov 26, 2023
1171d2f
パラメータenumをやめる
samunohito Nov 26, 2023
a3f7385
add command
samunohito Nov 26, 2023
75c72a1
Merge branch 'develop' into enhance/misskey-js-type-autogen
samunohito Nov 26, 2023
8cd5b8e
add api.json
samunohito Nov 26, 2023
a178602
都度自動生成をやめる
samunohito Nov 26, 2023
f879a3b
一気通貫スクリプト修正
samunohito Nov 26, 2023
c06f7f1
fix ci
samunohito Nov 26, 2023
63b01dc
生成ロジック修正
samunohito Nov 27, 2023
531df7c
フロントの型チェックは結局やらなかったので戻しておく
samunohito Nov 27, 2023
492b882
Merge branch 'develop' into enhance/misskey-js-type-autogen
samunohito Nov 27, 2023
4070396
fix pnpm-lock.yaml
samunohito Nov 27, 2023
0a4f8d7
add README.md
samunohito Nov 27, 2023
f5491e0
Merge branch 'develop' into enhance/misskey-js-type-autogen
samunohito Nov 29, 2023
2d7d633
Merge branch 'develop' into enhance/misskey-js-type-autogen
samunohito Nov 29, 2023
9791a43
Merge branch 'develop' into enhance/misskey-js-type-autogen
syuilo Dec 2, 2023
3a64cf7
Merge branch 'develop' into pr/12434
syuilo Dec 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"build-assets": "node ./scripts/build-assets.mjs",
"build": "pnpm build-pre && pnpm -r build && pnpm build-assets",
"build-storybook": "pnpm --filter frontend build-storybook",
"build-misskey-js-with-types": "pnpm --filter backend build && pnpm --filter backend generate-api-json && ncp packages/backend/built/api.json packages/misskey-js/generator/api.json && pnpm --filter misskey-js update-autogen-code && pnpm --filter misskey-js build",
"start": "pnpm check:connect && cd packages/backend && node ./built/boot/entry.js",
"start:test": "cd packages/backend && cross-env NODE_ENV=test node ./built/boot/entry.js",
"init": "pnpm migrate",
Expand Down Expand Up @@ -57,7 +58,8 @@
"cross-env": "7.0.3",
"cypress": "13.6.0",
"eslint": "8.54.0",
"start-server-and-test": "2.0.3"
"start-server-and-test": "2.0.3",
"ncp": "2.0.0"
},
"optionalDependencies": {
"@tensorflow/tfjs-core": "4.4.0"
Expand Down
76 changes: 76 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,82 @@ export const meta = {
type: 'number',
optional: false, nullable: false,
},
backgroundImageUrl: {
type: 'string',
optional: false, nullable: true,
},
deeplAuthKey: {
type: 'string',
optional: false, nullable: true,
},
deeplIsPro: {
type: 'boolean',
optional: false, nullable: false,
},
defaultDarkTheme: {
type: 'string',
optional: false, nullable: true,
},
defaultLightTheme: {
type: 'string',
optional: false, nullable: true,
},
description: {
type: 'string',
optional: false, nullable: true,
},
disableRegistration: {
type: 'boolean',
optional: false, nullable: false,
},
impressumUrl: {
type: 'string',
optional: false, nullable: true,
},
maintainerEmail: {
type: 'string',
optional: false, nullable: true,
},
maintainerName: {
type: 'string',
optional: false, nullable: true,
},
name: {
type: 'string',
optional: false, nullable: true,
},
objectStorageS3ForcePathStyle: {
type: 'boolean',
optional: false, nullable: false,
},
privacyPolicyUrl: {
type: 'string',
optional: false, nullable: true,
},
repositoryUrl: {
type: 'string',
optional: false, nullable: false,
},
summalyProxy: {
type: 'string',
optional: false, nullable: true,
},
themeColor: {
type: 'string',
optional: false, nullable: true,
},
tosUrl: {
type: 'string',
optional: false, nullable: true,
},
uri: {
type: 'string',
optional: false, nullable: false,
},
version: {
type: 'string',
optional: false, nullable: false,
},
},
},
} as const;
Expand Down
29 changes: 24 additions & 5 deletions packages/backend/src/server/api/endpoints/federation/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,32 @@ export const paramDef = {
blocked: { type: 'boolean', nullable: true },
notResponding: { type: 'boolean', nullable: true },
suspended: { type: 'boolean', nullable: true },
silenced: { type: "boolean", nullable: true },
silenced: { type: 'boolean', nullable: true },
federating: { type: 'boolean', nullable: true },
subscribing: { type: 'boolean', nullable: true },
publishing: { type: 'boolean', nullable: true },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 30 },
offset: { type: 'integer', default: 0 },
sort: { type: 'string' },
sort: {
type: 'string',
nullable: true,
enum: [
'+pubSub',
'-pubSub',
'+notes',
'-notes',
'+users',
'-users',
'+following',
'-following',
'+followers',
'-followers',
'+firstRetrievedAt',
'-firstRetrievedAt',
'+latestRequestReceivedAt',
'-latestRequestReceivedAt',
],
},
},
required: [],
} as const;
Expand Down Expand Up @@ -103,18 +122,18 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
}

if (typeof ps.silenced === "boolean") {
if (typeof ps.silenced === 'boolean') {
const meta = await this.metaService.fetch(true);

if (ps.silenced) {
if (meta.silencedHosts.length === 0) {
return [];
}
query.andWhere("instance.host IN (:...silences)", {
query.andWhere('instance.host IN (:...silences)', {
silences: meta.silencedHosts,
});
} else if (meta.silencedHosts.length > 0) {
query.andWhere("instance.host NOT IN (:...silences)", {
query.andWhere('instance.host NOT IN (:...silences)', {
silences: meta.silencedHosts,
});
}
Expand Down
27 changes: 27 additions & 0 deletions packages/backend/src/server/api/endpoints/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,33 @@ export const meta = {
},
},
},
backgroundImageUrl: {
type: 'string',
optional: false, nullable: true,
},
impressumUrl: {
type: 'string',
optional: false, nullable: true,
},
logoImageUrl: {
type: 'string',
optional: false, nullable: true,
},
privacyPolicyUrl: {
type: 'string',
optional: false, nullable: true,
},
serverRules: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'string',
},
},
themeColor: {
type: 'string',
optional: false, nullable: true,
},
},
},
} as const;
Expand Down
8 changes: 4 additions & 4 deletions packages/frontend/src/components/MkEmojiPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const size = computed(() => props.asReactionPicker ? reactionPickerSize.value :
const width = computed(() => props.asReactionPicker ? reactionPickerWidth.value : 3);
const height = computed(() => props.asReactionPicker ? reactionPickerHeight.value : 2);
const q = ref<string>('');
const searchResultCustom = ref<Misskey.entities.CustomEmoji[]>([]);
const searchResultCustom = ref<Misskey.entities.EmojiSimple[]>([]);
const searchResultUnicode = ref<UnicodeEmojiDef[]>([]);
const tab = ref<'index' | 'custom' | 'unicode' | 'tags'>('index');

Expand Down Expand Up @@ -196,7 +196,7 @@ watch(q, () => {
const searchCustom = () => {
const max = 100;
const emojis = customEmojis.value;
const matches = new Set<Misskey.entities.CustomEmoji>();
const matches = new Set<Misskey.entities.EmojiSimple>();

const exactMatch = emojis.find(emoji => emoji.name === newQ);
if (exactMatch) matches.add(exactMatch);
Expand Down Expand Up @@ -326,7 +326,7 @@ watch(q, () => {
searchResultUnicode.value = Array.from(searchUnicode());
});

function filterAvailable(emoji: Misskey.entities.CustomEmoji): boolean {
function filterAvailable(emoji: Misskey.entities.EmojiSimple): boolean {
return (emoji.roleIdsThatCanBeUsedThisEmojiAsReaction == null || emoji.roleIdsThatCanBeUsedThisEmojiAsReaction.length === 0) || ($i && $i.roles.some(r => emoji.roleIdsThatCanBeUsedThisEmojiAsReaction.includes(r.id)));
}

Expand All @@ -343,7 +343,7 @@ function reset() {
q.value = '';
}

function getKey(emoji: string | Misskey.entities.CustomEmoji | UnicodeEmojiDef): string {
function getKey(emoji: string | Misskey.entities.EmojiSimple | UnicodeEmojiDef): string {
return typeof emoji === 'string' ? emoji : 'char' in emoji ? emoji.char : `:${emoji.name}:`;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkFeaturedPhotos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ref } from 'vue';
import * as Misskey from 'misskey-js';
import * as os from '@/os.js';

const meta = ref<Misskey.entities.DetailedInstanceMetadata>();
const meta = ref<Misskey.entities.MetaResponse>();

os.api('meta', { detail: true }).then(gotMeta => {
meta.value = gotMeta;
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/components/MkInstanceCardMini.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import * as os from '@/os.js';
import { getProxiedImageUrlNullable } from '@/scripts/media-proxy.js';

const props = defineProps<{
instance: Misskey.entities.Instance;
instance: Misskey.entities.FederationInstance;
}>();

let chartValues = $ref<number[] | null>(null);

os.apiGet('charts/instance', { host: props.instance.host, limit: 16 + 1, span: 'day' }).then(res => {
// 今日のぶんの値はまだ途中の値であり、それも含めると大抵の場合前日よりも下降しているようなグラフになってしまうため今日は弾く
res.requests.received.splice(0, 1);
chartValues = res.requests.received;
res['requests.received'].splice(0, 1);
chartValues = res['requests.received'];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

返ってくる値の形が↓のようになっており、エラーとなっていましたので値の参照方法を変えています
https://github.com/samunohito/misskey/blob/c2370a1be631355e709c47d3b5e9469906116b84/packages/backend/src/core/chart/charts/entities/instance.ts

});

function getInstanceIcon(instance): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkInviteCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { i18n } from '@/i18n.js';
import * as os from '@/os.js';

const props = defineProps<{
invite: Misskey.entities.Invite;
invite: Misskey.entities.InviteCode;
moderator?: boolean;
}>();

Expand Down
7 changes: 3 additions & 4 deletions packages/frontend/src/components/MkVisitorDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ import number from '@/filters/number.js';
import MkNumber from '@/components/MkNumber.vue';
import XActiveUsersChart from '@/components/MkVisitorDashboard.ActiveUsersChart.vue';

let meta = $ref<Misskey.entities.Instance>();
let stats = $ref(null);
let meta = $ref<Misskey.entities.MetaResponse | null>(null);
let stats = $ref<Misskey.entities.StatsResponse | null>(null);

os.api('meta', { detail: true }).then(_meta => {
meta = _meta;
});

os.api('stats', {
}).then((res) => {
os.api('stats', {}).then((res) => {
stats = res;
});

Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/custom-emojis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useStream } from '@/stream.js';
import { get, set } from '@/scripts/idb-proxy.js';

const storageCache = await get('emojis');
export const customEmojis = shallowRef<Misskey.entities.CustomEmoji[]>(Array.isArray(storageCache) ? storageCache : []);
export const customEmojis = shallowRef<Misskey.entities.EmojiSimple[]>(Array.isArray(storageCache) ? storageCache : []);
export const customEmojiCategories = computed<[ ...string[], null ]>(() => {
const categories = new Set<string>();
for (const emoji of customEmojis.value) {
Expand All @@ -21,7 +21,7 @@ export const customEmojiCategories = computed<[ ...string[], null ]>(() => {
return markRaw([...Array.from(categories), null]);
});

export const customEmojisMap = new Map<string, Misskey.entities.CustomEmoji>();
export const customEmojisMap = new Map<string, Misskey.entities.EmojiSimple>();
watch(customEmojis, emojis => {
customEmojisMap.clear();
for (const emoji of emojis) {
Expand All @@ -38,7 +38,7 @@ stream.on('emojiAdded', emojiData => {
});

stream.on('emojiUpdated', emojiData => {
customEmojis.value = customEmojis.value.map(item => emojiData.emojis.find(search => search.name === item.name) as Misskey.entities.CustomEmoji ?? item);
customEmojis.value = customEmojis.value.map(item => emojiData.emojis.find(search => search.name === item.name) as Misskey.entities.EmojiSimple ?? item);
set('emojis', customEmojis.value);
});

Expand Down
1 change: 0 additions & 1 deletion packages/frontend/src/filters/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

import * as Misskey from 'misskey-js';
import * as Misskey from 'misskey-js';
import { url } from '@/config.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const cached = miLocalStorage.getItem('instance');

// TODO: instanceをリアクティブにするかは再考の余地あり

export const instance: Misskey.entities.InstanceMetadata = reactive(cached ? JSON.parse(cached) : {
export const instance: Misskey.entities.MetaResponse = reactive(cached ? JSON.parse(cached) : {
// TODO: set default values
});

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/_error_.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const props = withDefaults(defineProps<{

let loaded = $ref(false);
let serverIsDead = $ref(false);
let meta = $ref<Misskey.entities.LiteInstanceMetadata | null>(null);
let meta = $ref<Misskey.entities.MetaResponse | null>(null);

os.api('meta', {
detail: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/about.emojis.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { $i } from '@/account.js';

const customEmojiTags = getCustomEmojiTags();
let q = $ref('');
let searchEmojis = $ref<Misskey.entities.CustomEmoji[]>(null);
let searchEmojis = $ref<Misskey.entities.EmojiSimple[]>(null);
let selectedTags = $ref(new Set());

function search() {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/auth.form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import * as os from '@/os.js';
import { i18n } from '@/i18n.js';

const props = defineProps<{
session: Misskey.entities.AuthSession;
session: Misskey.entities.AuthSessionShowResponse;
}>();

const emit = defineEmits<{
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/auth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const props = defineProps<{
}>();

let state = $ref<'waiting' | 'accepted' | 'fetch-session-error' | 'denied' | null>(null);
let session = $ref<Misskey.entities.AuthSession | null>(null);
let session = $ref<Misskey.entities.AuthSessionShowResponse | null>(null);

function accepted() {
state = 'accepted';
Expand Down
Loading
Loading