diff --git a/packages/backend/src/core/chart/charts/entities/active-users.ts b/packages/backend/src/core/chart/charts/entities/active-users.ts index e291e37c1..1c630f209 100644 --- a/packages/backend/src/core/chart/charts/entities/active-users.ts +++ b/packages/backend/src/core/chart/charts/entities/active-users.ts @@ -1,17 +1,7 @@ import Chart from '../../core.js'; -export const name = 'activeUsers'; - -export const schema = { - 'readWrite': { intersection: ['read', 'write'] }, - 'read': { uniqueIncrement: true }, - 'write': { uniqueIncrement: true }, - 'registeredWithinWeek': { uniqueIncrement: true }, - 'registeredWithinMonth': { uniqueIncrement: true }, - 'registeredWithinYear': { uniqueIncrement: true }, - 'registeredOutsideWeek': { uniqueIncrement: true }, - 'registeredOutsideMonth': { uniqueIncrement: true }, - 'registeredOutsideYear': { uniqueIncrement: true }, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/active-users.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema); diff --git a/packages/backend/src/core/chart/charts/entities/ap-request.ts b/packages/backend/src/core/chart/charts/entities/ap-request.ts index 3a9f3dacf..1e9259235 100644 --- a/packages/backend/src/core/chart/charts/entities/ap-request.ts +++ b/packages/backend/src/core/chart/charts/entities/ap-request.ts @@ -1,11 +1,7 @@ import Chart from '../../core.js'; -export const name = 'apRequest'; - -export const schema = { - 'deliverFailed': { }, - 'deliverSucceeded': { }, - 'inboxReceived': { }, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/ap-request.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema); diff --git a/packages/backend/src/core/chart/charts/entities/drive.ts b/packages/backend/src/core/chart/charts/entities/drive.ts index 4bf5bb729..2050dba14 100644 --- a/packages/backend/src/core/chart/charts/entities/drive.ts +++ b/packages/backend/src/core/chart/charts/entities/drive.ts @@ -1,16 +1,7 @@ import Chart from '../../core.js'; -export const name = 'drive'; - -export const schema = { - 'local.incCount': {}, - 'local.incSize': {}, // in kilobyte - 'local.decCount': {}, - 'local.decSize': {}, // in kilobyte - 'remote.incCount': {}, - 'remote.incSize': {}, // in kilobyte - 'remote.decCount': {}, - 'remote.decSize': {}, // in kilobyte -} as const; +import * as _ from 'misskey-js/built/schemas/charts/drive.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema); diff --git a/packages/backend/src/core/chart/charts/entities/federation.ts b/packages/backend/src/core/chart/charts/entities/federation.ts index a8466b0b4..ec7180482 100644 --- a/packages/backend/src/core/chart/charts/entities/federation.ts +++ b/packages/backend/src/core/chart/charts/entities/federation.ts @@ -1,16 +1,7 @@ import Chart from '../../core.js'; -export const name = 'federation'; - -export const schema = { - 'deliveredInstances': { uniqueIncrement: true, range: 'small' }, - 'inboxInstances': { uniqueIncrement: true, range: 'small' }, - 'stalled': { uniqueIncrement: true, range: 'small' }, - 'sub': { accumulate: true, range: 'small' }, - 'pub': { accumulate: true, range: 'small' }, - 'pubsub': { accumulate: true, range: 'small' }, - 'subActive': { accumulate: true, range: 'small' }, - 'pubActive': { accumulate: true, range: 'small' }, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/federation.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema); diff --git a/packages/backend/src/core/chart/charts/entities/instance.ts b/packages/backend/src/core/chart/charts/entities/instance.ts index 06962120e..32d47dc67 100644 --- a/packages/backend/src/core/chart/charts/entities/instance.ts +++ b/packages/backend/src/core/chart/charts/entities/instance.ts @@ -1,32 +1,7 @@ import Chart from '../../core.js'; -export const name = 'instance'; - -export const schema = { - 'requests.failed': { range: 'small' }, - 'requests.succeeded': { range: 'small' }, - 'requests.received': { range: 'small' }, - 'notes.total': { accumulate: true }, - 'notes.inc': {}, - 'notes.dec': {}, - 'notes.diffs.normal': {}, - 'notes.diffs.reply': {}, - 'notes.diffs.renote': {}, - 'notes.diffs.withFile': {}, - 'users.total': { accumulate: true }, - 'users.inc': { range: 'small' }, - 'users.dec': { range: 'small' }, - 'following.total': { accumulate: true }, - 'following.inc': { range: 'small' }, - 'following.dec': { range: 'small' }, - 'followers.total': { accumulate: true }, - 'followers.inc': { range: 'small' }, - 'followers.dec': { range: 'small' }, - 'drive.totalFiles': { accumulate: true }, - 'drive.incFiles': {}, - 'drive.decFiles': {}, - 'drive.incUsage': {}, // in kilobyte - 'drive.decUsage': {}, // in kilobyte -} as const; +import * as _ from 'misskey-js/built/schemas/charts/instance.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema, true); diff --git a/packages/backend/src/core/chart/charts/entities/notes.ts b/packages/backend/src/core/chart/charts/entities/notes.ts index 9387dbfb2..1dc1daeee 100644 --- a/packages/backend/src/core/chart/charts/entities/notes.ts +++ b/packages/backend/src/core/chart/charts/entities/notes.ts @@ -1,22 +1,7 @@ import Chart from '../../core.js'; -export const name = 'notes'; - -export const schema = { - 'local.total': { accumulate: true }, - 'local.inc': {}, - 'local.dec': {}, - 'local.diffs.normal': {}, - 'local.diffs.reply': {}, - 'local.diffs.renote': {}, - 'local.diffs.withFile': {}, - 'remote.total': { accumulate: true }, - 'remote.inc': {}, - 'remote.dec': {}, - 'remote.diffs.normal': {}, - 'remote.diffs.reply': {}, - 'remote.diffs.renote': {}, - 'remote.diffs.withFile': {}, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/notes.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema); diff --git a/packages/backend/src/core/chart/charts/entities/per-user-drive.ts b/packages/backend/src/core/chart/charts/entities/per-user-drive.ts index 6111640ea..735d83291 100644 --- a/packages/backend/src/core/chart/charts/entities/per-user-drive.ts +++ b/packages/backend/src/core/chart/charts/entities/per-user-drive.ts @@ -1,14 +1,7 @@ import Chart from '../../core.js'; -export const name = 'perUserDrive'; - -export const schema = { - 'totalCount': { accumulate: true }, - 'totalSize': { accumulate: true }, // in kilobyte - 'incCount': { range: 'small' }, - 'incSize': {}, // in kilobyte - 'decCount': { range: 'small' }, - 'decSize': {}, // in kilobyte -} as const; +import * as _ from 'misskey-js/built/schemas/charts/per-user-drive.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema, true); diff --git a/packages/backend/src/core/chart/charts/entities/per-user-following.ts b/packages/backend/src/core/chart/charts/entities/per-user-following.ts index 4118daa47..accedb56b 100644 --- a/packages/backend/src/core/chart/charts/entities/per-user-following.ts +++ b/packages/backend/src/core/chart/charts/entities/per-user-following.ts @@ -1,20 +1,7 @@ import Chart from '../../core.js'; -export const name = 'perUserFollowing'; - -export const schema = { - 'local.followings.total': { accumulate: true }, - 'local.followings.inc': { range: 'small' }, - 'local.followings.dec': { range: 'small' }, - 'local.followers.total': { accumulate: true }, - 'local.followers.inc': { range: 'small' }, - 'local.followers.dec': { range: 'small' }, - 'remote.followings.total': { accumulate: true }, - 'remote.followings.inc': { range: 'small' }, - 'remote.followings.dec': { range: 'small' }, - 'remote.followers.total': { accumulate: true }, - 'remote.followers.inc': { range: 'small' }, - 'remote.followers.dec': { range: 'small' }, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/per-user-following.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema, true); diff --git a/packages/backend/src/core/chart/charts/entities/per-user-notes.ts b/packages/backend/src/core/chart/charts/entities/per-user-notes.ts index c1fa17445..23057fb92 100644 --- a/packages/backend/src/core/chart/charts/entities/per-user-notes.ts +++ b/packages/backend/src/core/chart/charts/entities/per-user-notes.ts @@ -1,15 +1,7 @@ import Chart from '../../core.js'; -export const name = 'perUserNotes'; - -export const schema = { - 'total': { accumulate: true }, - 'inc': { range: 'small' }, - 'dec': { range: 'small' }, - 'diffs.normal': { range: 'small' }, - 'diffs.reply': { range: 'small' }, - 'diffs.renote': { range: 'small' }, - 'diffs.withFile': { range: 'small' }, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/per-user-notes.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema, true); diff --git a/packages/backend/src/core/chart/charts/entities/per-user-pv.ts b/packages/backend/src/core/chart/charts/entities/per-user-pv.ts index 64c8ed1fb..2d8717c81 100644 --- a/packages/backend/src/core/chart/charts/entities/per-user-pv.ts +++ b/packages/backend/src/core/chart/charts/entities/per-user-pv.ts @@ -1,12 +1,7 @@ import Chart from '../../core.js'; -export const name = 'perUserPv'; - -export const schema = { - 'upv.user': { uniqueIncrement: true, range: 'small' }, - 'pv.user': { range: 'small' }, - 'upv.visitor': { uniqueIncrement: true, range: 'small' }, - 'pv.visitor': { range: 'small' }, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/per-user-pv.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema, true); diff --git a/packages/backend/src/core/chart/charts/entities/per-user-reactions.ts b/packages/backend/src/core/chart/charts/entities/per-user-reactions.ts index 5e1a6c7b3..5f1f50993 100644 --- a/packages/backend/src/core/chart/charts/entities/per-user-reactions.ts +++ b/packages/backend/src/core/chart/charts/entities/per-user-reactions.ts @@ -1,10 +1,7 @@ import Chart from '../../core.js'; -export const name = 'perUserReaction'; - -export const schema = { - 'local.count': { range: 'small' }, - 'remote.count': { range: 'small' }, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/per-user-reactions.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema, true); diff --git a/packages/backend/src/core/chart/charts/entities/test-grouped.ts b/packages/backend/src/core/chart/charts/entities/test-grouped.ts index 66b6e8e86..059047d1a 100644 --- a/packages/backend/src/core/chart/charts/entities/test-grouped.ts +++ b/packages/backend/src/core/chart/charts/entities/test-grouped.ts @@ -1,11 +1,7 @@ import Chart from '../../core.js'; -export const name = 'testGrouped'; - -export const schema = { - 'foo.total': { accumulate: true }, - 'foo.inc': {}, - 'foo.dec': {}, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/test-grouped.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema, true); diff --git a/packages/backend/src/core/chart/charts/entities/test-intersection.ts b/packages/backend/src/core/chart/charts/entities/test-intersection.ts index a3bdcb367..c9b0756c4 100644 --- a/packages/backend/src/core/chart/charts/entities/test-intersection.ts +++ b/packages/backend/src/core/chart/charts/entities/test-intersection.ts @@ -1,11 +1,7 @@ import Chart from '../../core.js'; -export const name = 'testIntersection'; - -export const schema = { - 'a': { uniqueIncrement: true }, - 'b': { uniqueIncrement: true }, - 'aAndB': { intersection: ['a', 'b'] }, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/test-intersection.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema); diff --git a/packages/backend/src/core/chart/charts/entities/test-unique.ts b/packages/backend/src/core/chart/charts/entities/test-unique.ts index b2cfb71b0..26c838c15 100644 --- a/packages/backend/src/core/chart/charts/entities/test-unique.ts +++ b/packages/backend/src/core/chart/charts/entities/test-unique.ts @@ -1,9 +1,7 @@ import Chart from '../../core.js'; -export const name = 'testUnique'; - -export const schema = { - 'foo': { uniqueIncrement: true }, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/test-unique.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema); diff --git a/packages/backend/src/core/chart/charts/entities/test.ts b/packages/backend/src/core/chart/charts/entities/test.ts index 7cba21e16..9731796b3 100644 --- a/packages/backend/src/core/chart/charts/entities/test.ts +++ b/packages/backend/src/core/chart/charts/entities/test.ts @@ -1,11 +1,7 @@ import Chart from '../../core.js'; -export const name = 'test'; - -export const schema = { - 'foo.total': { accumulate: true }, - 'foo.inc': {}, - 'foo.dec': {}, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/test.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema); diff --git a/packages/backend/src/core/chart/charts/entities/users.ts b/packages/backend/src/core/chart/charts/entities/users.ts index c0b83094a..1c8e66482 100644 --- a/packages/backend/src/core/chart/charts/entities/users.ts +++ b/packages/backend/src/core/chart/charts/entities/users.ts @@ -1,14 +1,7 @@ import Chart from '../../core.js'; -export const name = 'users'; - -export const schema = { - 'local.total': { accumulate: true }, - 'local.inc': { range: 'small' }, - 'local.dec': { range: 'small' }, - 'remote.total': { accumulate: true }, - 'remote.inc': { range: 'small' }, - 'remote.dec': { range: 'small' }, -} as const; +import * as _ from 'misskey-js/built/schemas/charts/users.js'; +export const name = _.name; +export const schema = _.schema; export const entity = Chart.schemaToEntity(name, schema); diff --git a/packages/backend/src/core/chart/core.ts b/packages/backend/src/core/chart/core.ts index d352adcc1..57faa0eb8 100644 --- a/packages/backend/src/core/chart/core.ts +++ b/packages/backend/src/core/chart/core.ts @@ -10,22 +10,12 @@ import { dateUTC, isTimeSame, isTimeBefore, subtractTime, addTime } from '@/misc import type Logger from '@/logger.js'; import { bindThis } from '@/decorators.js'; import type { Repository, DataSource } from 'typeorm'; +import type { ChartSchema as Schema, ChartResult, Unflatten } from 'misskey-js/built/schemas'; const COLUMN_PREFIX = '___' as const; const UNIQUE_TEMP_COLUMN_PREFIX = 'unique_temp___' as const; const COLUMN_DELIMITER = '_' as const; -type Schema = Record; - - range?: 'big' | 'small' | 'medium'; - - // previousな値を引き継ぐかどうか - accumulate?: boolean; -}>; - type KeyToColumnName = T extends `${infer R1}.${infer R2}` ? `${R1}${typeof COLUMN_DELIMITER}${KeyToColumnName}` : T; type Columns = { @@ -64,47 +54,6 @@ export type KVs = { [K in keyof S]: number; }; -type ChartResult = { - [P in keyof T]: number[]; -}; - -type UnionToIntersection = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never; - -type UnflattenSingleton = K extends `${infer A}.${infer B}` - ? { [_ in A]: UnflattenSingleton; } - : { [_ in K]: V; }; - -type Unflatten> = UnionToIntersection< - { - [K in Extract]: UnflattenSingleton; - }[Extract] ->; - -type ToJsonSchema = { - type: 'object'; - properties: { - [K in keyof S]: S[K] extends number[] ? { type: 'array'; items: { type: 'number'; }; } : ToJsonSchema; - }, - required: (keyof S)[]; -}; - -export function getJsonSchema(schema: S): ToJsonSchema>> { - const jsonSchema = { - type: 'object', - properties: {} as Record, - required: [], - }; - - for (const k in schema) { - jsonSchema.properties[k] = { - type: 'array', - items: { type: 'number' }, - }; - } - - return jsonSchema as ToJsonSchema>>; -} - /** * 様々なチャートの管理を司るクラス */ diff --git a/packages/backend/src/server/api/endpoints/charts/user/drive.ts b/packages/backend/src/server/api/endpoints/charts/user/drive.ts index 5e372294b..66dff34d5 100644 --- a/packages/backend/src/server/api/endpoints/charts/user/drive.ts +++ b/packages/backend/src/server/api/endpoints/charts/user/drive.ts @@ -1,36 +1,15 @@ import { Injectable } from '@nestjs/common'; -import { getJsonSchema } from '@/core/chart/core.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import PerUserDriveChart from '@/core/chart/charts/per-user-drive.js'; -import { schema } from '@/core/chart/charts/entities/per-user-drive.js'; - -export const meta = { - tags: ['charts', 'drive', 'users'], - - res: getJsonSchema(schema), - - allowGet: true, - cacheSec: 60 * 60, -} as const; - -export const paramDef = { - type: 'object', - properties: { - span: { type: 'string', enum: ['day', 'hour'] }, - limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, - offset: { type: 'integer', nullable: true, default: null }, - userId: { type: 'string', format: 'misskey:id' }, - }, - required: ['span', 'userId'], -} as const; // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'charts/user/drive'> { + name = 'charts/user/drive' as const; constructor( private perUserDriveChart: PerUserDriveChart, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { return await this.perUserDriveChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null, ps.userId); }); } diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts index 1933a0049..219bff64f 100644 --- a/packages/misskey-js/src/endpoints.ts +++ b/packages/misskey-js/src/endpoints.ts @@ -2,6 +2,9 @@ import type { JSONSchema7 } from 'schema-type'; import { IEndpointMeta } from './endpoints.types'; import { localUsernameSchema, passwordSchema } from './schemas/user'; import ms from 'ms'; +import { getJsonSchema } from './schemas'; +import * as perUserDriveChartSchema from './schemas/charts/per-user-drive'; +import * as driveChartSchema from './schemas/charts/drive'; export const endpoints = { //#region admin @@ -2984,6 +2987,29 @@ export const endpoints = { }], }, //#endregion + + //#region charts + 'charts/user/drive': { + tags: ['charts', 'drive', 'users'], + + allowGet: true, + cacheSec: 60 * 60, + + defines: [{ + req: { + type: 'object', + properties: { + span: { type: 'string', enum: ['day', 'hour'] }, + limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, + offset: { type: 'integer', nullable: true, default: null }, + userId: { type: 'string', format: 'misskey:id' }, + }, + required: ['span', 'userId'], + }, + res: getJsonSchema(perUserDriveChartSchema.schema) satisfies JSONSchema7, + }], + }, + //#endregion } as const satisfies { [x: string]: IEndpointMeta; }; /** diff --git a/packages/misskey-js/src/schemas.ts b/packages/misskey-js/src/schemas.ts index 83272bb3d..efd507dbe 100644 --- a/packages/misskey-js/src/schemas.ts +++ b/packages/misskey-js/src/schemas.ts @@ -58,7 +58,7 @@ import { import { packedModerationLogSchema } from './schemas/moderation-log.js'; import { packedAuthSessionSchema } from './schemas/auth-session.js'; import { Error, ApiError } from './schemas/error.js'; -import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray, Serialized } from 'schema-type'; +import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray, Serialized, Projected } from 'schema-type'; export const refs = { Id: IdSchema, @@ -120,3 +120,57 @@ export type References = GetRefs; export type Packed> = Serialized>; export type Def> = GetDef; + +//#reginon Chart +export type ChartSchema = Record; + + range?: 'big' | 'small' | 'medium'; + + // previousな値を引き継ぐかどうか + accumulate?: boolean; +}>; + +export type ChartResult = { + [P in keyof T]: number[]; +}; + +type UnionToIntersection = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never; + +type UnflattenSingleton = K extends `${infer A}.${infer B}` + ? { [_ in A]: UnflattenSingleton; } + : { [_ in K]: V; }; + +export type Unflatten> = Projected]: UnflattenSingleton; + }[Extract] +>>; + +type ToJsonSchema = { + type: 'object'; + properties: { + [K in keyof S]: S[K] extends number[] ? { type: 'array'; items: { type: 'number'; }; } : ToJsonSchema; + }, + required: (keyof S)[]; +}; + +export function getJsonSchema(schema: S): ToJsonSchema>> { + const jsonSchema = { + type: 'object', + properties: {} as Record, + required: [], + }; + + for (const k in schema) { + jsonSchema.properties[k] = { + type: 'array', + items: { type: 'number' }, + }; + } + + return jsonSchema as ToJsonSchema>>; +} +//#endregion diff --git a/packages/misskey-js/src/schemas/charts/active-users.ts b/packages/misskey-js/src/schemas/charts/active-users.ts new file mode 100644 index 000000000..b4c0df5ce --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/active-users.ts @@ -0,0 +1,13 @@ +export const name = 'activeUsers'; + +export const schema = { + 'readWrite': { intersection: ['read', 'write'] }, + 'read': { uniqueIncrement: true }, + 'write': { uniqueIncrement: true }, + 'registeredWithinWeek': { uniqueIncrement: true }, + 'registeredWithinMonth': { uniqueIncrement: true }, + 'registeredWithinYear': { uniqueIncrement: true }, + 'registeredOutsideWeek': { uniqueIncrement: true }, + 'registeredOutsideMonth': { uniqueIncrement: true }, + 'registeredOutsideYear': { uniqueIncrement: true }, +} as const; diff --git a/packages/misskey-js/src/schemas/charts/ap-request.ts b/packages/misskey-js/src/schemas/charts/ap-request.ts new file mode 100644 index 000000000..77e81b9b5 --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/ap-request.ts @@ -0,0 +1,7 @@ +export const name = 'apRequest'; + +export const schema = { + 'deliverFailed': { }, + 'deliverSucceeded': { }, + 'inboxReceived': { }, +} as const; diff --git a/packages/misskey-js/src/schemas/charts/drive.ts b/packages/misskey-js/src/schemas/charts/drive.ts new file mode 100644 index 000000000..ade3fae7d --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/drive.ts @@ -0,0 +1,12 @@ +export const name = 'drive'; + +export const schema = { + 'local.incCount': {}, + 'local.incSize': {}, // in kilobyte + 'local.decCount': {}, + 'local.decSize': {}, // in kilobyte + 'remote.incCount': {}, + 'remote.incSize': {}, // in kilobyte + 'remote.decCount': {}, + 'remote.decSize': {}, // in kilobyte +} as const; diff --git a/packages/misskey-js/src/schemas/charts/federation.ts b/packages/misskey-js/src/schemas/charts/federation.ts new file mode 100644 index 000000000..bd720b41b --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/federation.ts @@ -0,0 +1,12 @@ +export const name = 'federation'; + +export const schema = { + 'deliveredInstances': { uniqueIncrement: true, range: 'small' }, + 'inboxInstances': { uniqueIncrement: true, range: 'small' }, + 'stalled': { uniqueIncrement: true, range: 'small' }, + 'sub': { accumulate: true, range: 'small' }, + 'pub': { accumulate: true, range: 'small' }, + 'pubsub': { accumulate: true, range: 'small' }, + 'subActive': { accumulate: true, range: 'small' }, + 'pubActive': { accumulate: true, range: 'small' }, +} as const; diff --git a/packages/misskey-js/src/schemas/charts/instance.ts b/packages/misskey-js/src/schemas/charts/instance.ts new file mode 100644 index 000000000..06c3dda0e --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/instance.ts @@ -0,0 +1,28 @@ +export const name = 'instance'; + +export const schema = { + 'requests.failed': { range: 'small' }, + 'requests.succeeded': { range: 'small' }, + 'requests.received': { range: 'small' }, + 'notes.total': { accumulate: true }, + 'notes.inc': {}, + 'notes.dec': {}, + 'notes.diffs.normal': {}, + 'notes.diffs.reply': {}, + 'notes.diffs.renote': {}, + 'notes.diffs.withFile': {}, + 'users.total': { accumulate: true }, + 'users.inc': { range: 'small' }, + 'users.dec': { range: 'small' }, + 'following.total': { accumulate: true }, + 'following.inc': { range: 'small' }, + 'following.dec': { range: 'small' }, + 'followers.total': { accumulate: true }, + 'followers.inc': { range: 'small' }, + 'followers.dec': { range: 'small' }, + 'drive.totalFiles': { accumulate: true }, + 'drive.incFiles': {}, + 'drive.decFiles': {}, + 'drive.incUsage': {}, // in kilobyte + 'drive.decUsage': {}, // in kilobyte +} as const; diff --git a/packages/misskey-js/src/schemas/charts/notes.ts b/packages/misskey-js/src/schemas/charts/notes.ts new file mode 100644 index 000000000..3df1d1224 --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/notes.ts @@ -0,0 +1,18 @@ +export const name = 'notes'; + +export const schema = { + 'local.total': { accumulate: true }, + 'local.inc': {}, + 'local.dec': {}, + 'local.diffs.normal': {}, + 'local.diffs.reply': {}, + 'local.diffs.renote': {}, + 'local.diffs.withFile': {}, + 'remote.total': { accumulate: true }, + 'remote.inc': {}, + 'remote.dec': {}, + 'remote.diffs.normal': {}, + 'remote.diffs.reply': {}, + 'remote.diffs.renote': {}, + 'remote.diffs.withFile': {}, +} as const; diff --git a/packages/misskey-js/src/schemas/charts/per-user-drive.ts b/packages/misskey-js/src/schemas/charts/per-user-drive.ts new file mode 100644 index 000000000..ea2c67c1f --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/per-user-drive.ts @@ -0,0 +1,10 @@ +export const name = 'perUserDrive'; + +export const schema = { + 'totalCount': { accumulate: true }, + 'totalSize': { accumulate: true }, // in kilobyte + 'incCount': { range: 'small' }, + 'incSize': {}, // in kilobyte + 'decCount': { range: 'small' }, + 'decSize': {}, // in kilobyte +} as const; diff --git a/packages/misskey-js/src/schemas/charts/per-user-following.ts b/packages/misskey-js/src/schemas/charts/per-user-following.ts new file mode 100644 index 000000000..56d80c43f --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/per-user-following.ts @@ -0,0 +1,16 @@ +export const name = 'perUserFollowing'; + +export const schema = { + 'local.followings.total': { accumulate: true }, + 'local.followings.inc': { range: 'small' }, + 'local.followings.dec': { range: 'small' }, + 'local.followers.total': { accumulate: true }, + 'local.followers.inc': { range: 'small' }, + 'local.followers.dec': { range: 'small' }, + 'remote.followings.total': { accumulate: true }, + 'remote.followings.inc': { range: 'small' }, + 'remote.followings.dec': { range: 'small' }, + 'remote.followers.total': { accumulate: true }, + 'remote.followers.inc': { range: 'small' }, + 'remote.followers.dec': { range: 'small' }, +} as const; diff --git a/packages/misskey-js/src/schemas/charts/per-user-notes.ts b/packages/misskey-js/src/schemas/charts/per-user-notes.ts new file mode 100644 index 000000000..cd51b7081 --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/per-user-notes.ts @@ -0,0 +1,11 @@ +export const name = 'perUserNotes'; + +export const schema = { + 'total': { accumulate: true }, + 'inc': { range: 'small' }, + 'dec': { range: 'small' }, + 'diffs.normal': { range: 'small' }, + 'diffs.reply': { range: 'small' }, + 'diffs.renote': { range: 'small' }, + 'diffs.withFile': { range: 'small' }, +} as const; diff --git a/packages/misskey-js/src/schemas/charts/per-user-pv.ts b/packages/misskey-js/src/schemas/charts/per-user-pv.ts new file mode 100644 index 000000000..929307d4f --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/per-user-pv.ts @@ -0,0 +1,8 @@ +export const name = 'perUserPv'; + +export const schema = { + 'upv.user': { uniqueIncrement: true, range: 'small' }, + 'pv.user': { range: 'small' }, + 'upv.visitor': { uniqueIncrement: true, range: 'small' }, + 'pv.visitor': { range: 'small' }, +} as const; diff --git a/packages/misskey-js/src/schemas/charts/per-user-reactions.ts b/packages/misskey-js/src/schemas/charts/per-user-reactions.ts new file mode 100644 index 000000000..a8b9c8923 --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/per-user-reactions.ts @@ -0,0 +1,6 @@ +export const name = 'perUserReaction'; + +export const schema = { + 'local.count': { range: 'small' }, + 'remote.count': { range: 'small' }, +} as const; diff --git a/packages/misskey-js/src/schemas/charts/test-grouped.ts b/packages/misskey-js/src/schemas/charts/test-grouped.ts new file mode 100644 index 000000000..659a728af --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/test-grouped.ts @@ -0,0 +1,7 @@ +export const name = 'testGrouped'; + +export const schema = { + 'foo.total': { accumulate: true }, + 'foo.inc': {}, + 'foo.dec': {}, +} as const; diff --git a/packages/misskey-js/src/schemas/charts/test-intersection.ts b/packages/misskey-js/src/schemas/charts/test-intersection.ts new file mode 100644 index 000000000..2eb34d0dd --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/test-intersection.ts @@ -0,0 +1,7 @@ +export const name = 'testIntersection'; + +export const schema = { + 'a': { uniqueIncrement: true }, + 'b': { uniqueIncrement: true }, + 'aAndB': { intersection: ['a', 'b'] }, +} as const; diff --git a/packages/misskey-js/src/schemas/charts/test-unique.ts b/packages/misskey-js/src/schemas/charts/test-unique.ts new file mode 100644 index 000000000..7c90413ca --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/test-unique.ts @@ -0,0 +1,5 @@ +export const name = 'testUnique'; + +export const schema = { + 'foo': { uniqueIncrement: true }, +} as const; diff --git a/packages/misskey-js/src/schemas/charts/test.ts b/packages/misskey-js/src/schemas/charts/test.ts new file mode 100644 index 000000000..5e196108e --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/test.ts @@ -0,0 +1,7 @@ +export const name = 'test'; + +export const schema = { + 'foo.total': { accumulate: true }, + 'foo.inc': {}, + 'foo.dec': {}, +} as const; diff --git a/packages/misskey-js/src/schemas/charts/users.ts b/packages/misskey-js/src/schemas/charts/users.ts new file mode 100644 index 000000000..f96462c35 --- /dev/null +++ b/packages/misskey-js/src/schemas/charts/users.ts @@ -0,0 +1,10 @@ +export const name = 'users'; + +export const schema = { + 'local.total': { accumulate: true }, + 'local.inc': { range: 'small' }, + 'local.dec': { range: 'small' }, + 'remote.total': { accumulate: true }, + 'remote.inc': { range: 'small' }, + 'remote.dec': { range: 'small' }, +} as const;