wip
This commit is contained in:
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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<string, {
|
||||
uniqueIncrement?: boolean;
|
||||
|
||||
intersection?: string[] | ReadonlyArray<string>;
|
||||
|
||||
range?: 'big' | 'small' | 'medium';
|
||||
|
||||
// previousな値を引き継ぐかどうか
|
||||
accumulate?: boolean;
|
||||
}>;
|
||||
|
||||
type KeyToColumnName<T extends string> = T extends `${infer R1}.${infer R2}` ? `${R1}${typeof COLUMN_DELIMITER}${KeyToColumnName<R2>}` : T;
|
||||
|
||||
type Columns<S extends Schema> = {
|
||||
@@ -64,47 +54,6 @@ export type KVs<S extends Schema> = {
|
||||
[K in keyof S]: number;
|
||||
};
|
||||
|
||||
type ChartResult<T extends Schema> = {
|
||||
[P in keyof T]: number[];
|
||||
};
|
||||
|
||||
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
|
||||
|
||||
type UnflattenSingleton<K extends string, V> = K extends `${infer A}.${infer B}`
|
||||
? { [_ in A]: UnflattenSingleton<B, V>; }
|
||||
: { [_ in K]: V; };
|
||||
|
||||
type Unflatten<T extends Record<string, any>> = UnionToIntersection<
|
||||
{
|
||||
[K in Extract<keyof T, string>]: UnflattenSingleton<K, T[K]>;
|
||||
}[Extract<keyof T, string>]
|
||||
>;
|
||||
|
||||
type ToJsonSchema<S> = {
|
||||
type: 'object';
|
||||
properties: {
|
||||
[K in keyof S]: S[K] extends number[] ? { type: 'array'; items: { type: 'number'; }; } : ToJsonSchema<S[K]>;
|
||||
},
|
||||
required: (keyof S)[];
|
||||
};
|
||||
|
||||
export function getJsonSchema<S extends Schema>(schema: S): ToJsonSchema<Unflatten<ChartResult<S>>> {
|
||||
const jsonSchema = {
|
||||
type: 'object',
|
||||
properties: {} as Record<string, unknown>,
|
||||
required: [],
|
||||
};
|
||||
|
||||
for (const k in schema) {
|
||||
jsonSchema.properties[k] = {
|
||||
type: 'array',
|
||||
items: { type: 'number' },
|
||||
};
|
||||
}
|
||||
|
||||
return jsonSchema as ToJsonSchema<Unflatten<ChartResult<S>>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 様々なチャートの管理を司るクラス
|
||||
*/
|
||||
|
Reference in New Issue
Block a user