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

fix(backend): use prefixItems in admin/queue/*-delayed endpoint schema #14468

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
3 changes: 3 additions & 0 deletions packages/backend/src/misc/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export interface Schema extends OfSchema {
readonly nullable?: boolean;
readonly optional?: boolean;
readonly items?: Schema;
readonly prefixItems?: ReadonlyArray<Schema>;
readonly properties?: Obj;
readonly required?: ReadonlyArray<Extract<keyof NonNullable<this['properties']>, string>>;
readonly description?: string;
Expand Down Expand Up @@ -198,6 +199,7 @@ type UnionSchemaType<a extends readonly any[], X extends Schema = a[number]> = X
//type UnionObjectSchemaType<a extends readonly any[], X extends Schema = a[number]> = X extends any ? ObjectSchemaType<X> : never;
type UnionObjType<s extends Obj, a extends readonly any[], X extends ReadonlyArray<keyof s> = a[number]> = X extends any ? ObjType<s, X> : never;
type ArrayUnion<T> = T extends any ? Array<T> : never;
type ArrayToTuple<X extends ReadonlyArray<Schema>> = { [K in keyof X]: SchemaType<X[K]> };

type ObjectSchemaTypeDef<p extends Schema> =
p['ref'] extends keyof typeof refs ? Packed<p['ref']> :
Expand Down Expand Up @@ -233,6 +235,7 @@ export type SchemaTypeDef<p extends Schema> =
never
) :
p['items'] extends NonNullable<Schema> ? SchemaType<p['items']>[] :
p['prefixItems'] extends ReadonlyArray<Schema> ? ArrayToTuple<p['prefixItems']> :
any[]
) :
p['anyOf'] extends ReadonlyArray<Schema> ? UnionSchemaType<p['anyOf']> & PartialIntersection<UnionSchemaType<p['anyOf']>> :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ export const meta = {
items: {
type: 'array',
optional: false, nullable: false,
items: {
anyOf: [
{
type: 'string',
},
{
type: 'number',
},
],
},
prefixItems: [
{
type: 'string',
},
{
type: 'number',
},
],
zyoshoka marked this conversation as resolved.
Show resolved Hide resolved
},
example: [[
'example.com',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ export const meta = {
items: {
type: 'array',
optional: false, nullable: false,
items: {
anyOf: [
{
type: 'string',
},
{
type: 'number',
},
],
},
prefixItems: [
{
type: 'string',
},
{
type: 'number',
},
],
},
example: [[
'example.com',
Expand Down
19 changes: 10 additions & 9 deletions packages/frontend/src/pages/admin/overview.queue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SPDX-License-Identifier: AGPL-3.0-only

zyoshoka marked this conversation as resolved.
Show resolved Hide resolved
<script lang="ts" setup>
import { markRaw, onMounted, onUnmounted, ref, shallowRef } from 'vue';
import * as Misskey from 'misskey-js';
import XChart from './overview.queue.chart.vue';
import number from '@/filters/number.js';
import { useStream } from '@/stream.js';
Expand All @@ -52,10 +53,10 @@ const chartDelayed = shallowRef<InstanceType<typeof XChart>>();
const chartWaiting = shallowRef<InstanceType<typeof XChart>>();

const props = defineProps<{
domain: string;
domain: 'deliver' | 'inbox';
}>();

const onStats = (stats) => {
function onStats(stats: Misskey.entities.QueueStats) {
activeSincePrevTick.value = stats[props.domain].activeSincePrevTick;
active.value = stats[props.domain].active;
delayed.value = stats[props.domain].delayed;
Expand All @@ -65,13 +66,13 @@ const onStats = (stats) => {
chartActive.value.pushData(stats[props.domain].active);
chartDelayed.value.pushData(stats[props.domain].delayed);
chartWaiting.value.pushData(stats[props.domain].waiting);
};
}

const onStatsLog = (statsLog) => {
const dataProcess = [];
const dataActive = [];
const dataDelayed = [];
const dataWaiting = [];
function onStatsLog(statsLog: Misskey.entities.QueueStatsLog) {
const dataProcess: Misskey.entities.QueueStats['deliver' | 'inbox']['activeSincePrevTick'][] = [];
const dataActive: Misskey.entities.QueueStats['deliver' | 'inbox']['active'][] = [];
const dataDelayed: Misskey.entities.QueueStats['deliver' | 'inbox']['delayed'][] = [];
const dataWaiting: Misskey.entities.QueueStats['deliver' | 'inbox']['waiting'][] = [];

for (const stats of [...statsLog].reverse()) {
dataProcess.push(stats[props.domain].activeSincePrevTick);
Expand All @@ -84,7 +85,7 @@ const onStatsLog = (statsLog) => {
chartActive.value.setData(dataActive);
chartDelayed.value.setData(dataDelayed);
chartWaiting.value.setData(dataWaiting);
};
}

onMounted(() => {
connection.on('stats', onStats);
Expand Down
29 changes: 14 additions & 15 deletions packages/frontend/src/pages/admin/queue.chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { markRaw, onMounted, onUnmounted, ref, shallowRef } from 'vue';
import * as Misskey from 'misskey-js';
import XChart from './queue.chart.chart.vue';
import number from '@/filters/number.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
Expand All @@ -62,17 +63,17 @@ const activeSincePrevTick = ref(0);
const active = ref(0);
const delayed = ref(0);
const waiting = ref(0);
const jobs = ref<(string | number)[][]>([]);
const jobs = ref<Misskey.Endpoints[`admin/queue/${'deliver' | 'inbox'}-delayed`]['res']>([]);
const chartProcess = shallowRef<InstanceType<typeof XChart>>();
const chartActive = shallowRef<InstanceType<typeof XChart>>();
const chartDelayed = shallowRef<InstanceType<typeof XChart>>();
const chartWaiting = shallowRef<InstanceType<typeof XChart>>();

const props = defineProps<{
domain: string;
domain: 'deliver' | 'inbox';
}>();

const onStats = (stats) => {
function onStats(stats: Misskey.entities.QueueStats) {
activeSincePrevTick.value = stats[props.domain].activeSincePrevTick;
active.value = stats[props.domain].active;
delayed.value = stats[props.domain].delayed;
Expand All @@ -82,13 +83,13 @@ const onStats = (stats) => {
chartActive.value.pushData(stats[props.domain].active);
chartDelayed.value.pushData(stats[props.domain].delayed);
chartWaiting.value.pushData(stats[props.domain].waiting);
};
}

const onStatsLog = (statsLog) => {
const dataProcess = [];
const dataActive = [];
const dataDelayed = [];
const dataWaiting = [];
function onStatsLog(statsLog: Misskey.entities.QueueStatsLog) {
const dataProcess: Misskey.entities.QueueStats['deliver' | 'inbox']['activeSincePrevTick'][] = [];
const dataActive: Misskey.entities.QueueStats['deliver' | 'inbox']['active'][] = [];
const dataDelayed: Misskey.entities.QueueStats['deliver' | 'inbox']['delayed'][] = [];
const dataWaiting: Misskey.entities.QueueStats['deliver' | 'inbox']['waiting'][] = [];

for (const stats of [...statsLog].reverse()) {
dataProcess.push(stats[props.domain].activeSincePrevTick);
Expand All @@ -101,14 +102,12 @@ const onStatsLog = (statsLog) => {
chartActive.value.setData(dataActive);
chartDelayed.value.setData(dataDelayed);
chartWaiting.value.setData(dataWaiting);
};
}

onMounted(() => {
if (props.domain === 'inbox' || props.domain === 'deliver') {
misskeyApi(`admin/queue/${props.domain}-delayed`).then(result => {
jobs.value = result;
});
}
misskeyApi(`admin/queue/${props.domain}-delayed`).then(result => {
jobs.value = result;
});

connection.on('stats', onStats);
connection.on('statsLog', onStatsLog);
Expand Down
4 changes: 2 additions & 2 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8217,7 +8217,7 @@ export type operations = {
/** @description OK (with results) */
200: {
content: {
'application/json': ((string | number)[])[];
'application/json': [string, number][];
};
};
/** @description Client error */
Expand Down Expand Up @@ -8263,7 +8263,7 @@ export type operations = {
/** @description OK (with results) */
200: {
content: {
'application/json': ((string | number)[])[];
'application/json': [string, number][];
};
};
/** @description Client error */
Expand Down
Loading