このコミットが含まれているのは:
2026-10-26 12:19:43 +09:00
コミット 3e8f209542
31個のファイルの変更、1676行の追加、394行の削除
+72
ファイルの表示
@@ -0,0 +1,72 @@
import type { CountField, CountsResource } from '@/lib/counts'
export type CountsAxis = { field: string; grain?: string }
export type CountsCondition = {
field: string; operator: string; value?: string; end?: string; blank?: boolean }
export type CountsFieldType = 'string' | 'integer' | 'datetime' | 'enum' | 'json'
export const countsResources: CountsResource[] = [
'posts', 'tags', 'nico_tags', 'tag_descriptions', 'tag_groups', 'materials']
export const countsGrains = ['year', 'quarter', 'month', 'week', 'day', 'hour']
export const countsOperators: Record<CountsFieldType, string[]> = {
string: ['eq', 'ne', 'like'], enum: ['eq', 'ne'], json: [],
integer: ['eq', 'ne', 'gt', 'lt', 'ge', 'le', 'range'],
datetime: ['eq', 'ne', 'gt', 'lt', 'ge', 'le', 'range'] }
export const countsAttributes: Record<CountsResource, Record<string, CountsFieldType>> = {
posts: { title: 'string', url: 'string', thumbnail_base: 'string', tags_json: 'json',
parent_post_ids: 'string', video_ms: 'integer', original_created_from: 'datetime',
original_created_before: 'datetime' },
tags: { name: 'string', names: 'json', category: 'enum', aliases: 'string',
parent_tag_ids: 'string', deprecated_at: 'datetime' },
nico_tags: { name: 'string', linked_tags: 'string' },
tag_descriptions: { language_code: 'enum', body: 'string', source_language_code: 'enum',
source_version_no: 'integer' },
tag_groups: { name: 'string', description: 'string', members: 'json', placements: 'json' },
materials: { url: 'string', parent_id: 'integer', tag_id: 'integer', tag_name: 'string',
tag_category: 'enum', discarded_at: 'datetime', updated_at: 'datetime',
updated_by_user_id: 'integer', export_paths_json: 'json', file_blob_id: 'integer',
file_filename: 'string', file_content_type: 'string', file_byte_size: 'integer',
file_checksum: 'string', file_sha256: 'string', source_kind: 'enum', source_uri: 'string',
source_path: 'string', source_file_id: 'string', normalized_source_key: 'string' } }
export const countsFilterFields = (
resource: CountsResource,
): Record<string, CountsFieldType> => ({
resource_id: 'integer' as const, version_no: 'integer' as const,
event_type: 'enum' as const, user: 'integer' as const, created_at: 'datetime' as const,
...countsAttributes[resource] })
export const countsFieldLabel = (key: string): string => {
const labels: Record<string, string> = {
resource_id: 'columns.resourceId', version_no: 'history:version',
user: 'history:actor', created_at: 'columns.changedAt', name: 'history:name',
title: 'columns.postTitle', url: 'columns.postURL', thumbnail_base: 'columns.thumbnailURL',
tags: 'columns.tags', tags_json: 'columns.tags', names: 'columns.names',
aliases: 'tags:aliases', category: 'common:categoryLabel',
language_code: 'columns.language', source_language_code: 'attributes.sourceLanguage',
changed_field: 'changedField' }
return labels[key] ?? `attributes.${key}`
}
export const countsAxisFields = (resource: CountsResource, history: boolean): CountField[] => [
...Object.entries (countsFilterFields (resource))
.filter (([, type]) => type !== 'json')
.map (([key]) => ({ key, label: countsFieldLabel (key) })),
...(resource === 'posts' ? [{ key: 'tags', label: 'columns.tags' }] : []),
...(history ? [{ key: 'changed_field', label: 'changedField' }] : [])]
export const readCountsJSON = <T,> (params: URLSearchParams, key: string, fallback: T): T => {
try
{
return JSON.parse (params.get (key) ?? JSON.stringify (fallback)) as T
}
catch
{
return fallback
}
}