summaryrefslogtreecommitdiff
path: root/packages/backend/src/models/SkApFetchLog.ts
blob: 1e7d861b6cb62ea2a792d577aa29a56a2aa319fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import { Column, Index, JoinColumn, ManyToOne, PrimaryColumn, Entity } from 'typeorm';
import { SkApContext } from '@/models/SkApContext.js';
import { id } from './util/id.js';

/**
 * Records objects fetched via AP
 */
@Entity('ap_fetch_log')
export class SkApFetchLog {
	@PrimaryColumn({
		...id(),
		primaryKeyConstraintName: 'PK_ap_fetch_log',
	})
	public id: string;

	@Index('IDX_ap_fetch_log_at')
	@Column('timestamptz')
	public at: Date;

	/**
	 * Processing duration in milliseconds
	 */
	@Column('double precision', { nullable: true })
	public duration: number | null = null;

	/**
	 * DB hostname extracted from responseUri, or requestUri if fetch is incomplete
	 */
	@Index('IDX_ap_fetch_log_host')
	@Column('text')
	public host: string;

	/**
	 * Original requested URI
	 */
	@Column('text', {
		name: 'request_uri',
	})
	public requestUri: string;

	/**
	 * Canonical URI / object ID, taken from the final payload
	 */
	@Column('text', {
		name: 'object_uri',
		nullable: true,
	})
	@Index('IDX_ap_fetch_log_object_uri')
	public objectUri: string | null = null;

	@Column('boolean', { nullable: true })
	public accepted: boolean | null = null;

	@Column('text', { nullable: true })
	public result: string | null = null;

	@Column('jsonb', { nullable: true })
	// https://github.com/typeorm/typeorm/issues/8559
	// eslint-disable-next-line @typescript-eslint/no-explicit-any
	public object: any | null = null;

	@Column({
		type: 'text',
		name: 'context_hash',
		nullable: true,
	})
	public contextHash: string | null;

	@ManyToOne(() => SkApContext, {
		onDelete: 'CASCADE',
		nullable: true,
	})
	@JoinColumn({
		name: 'context_hash',
		foreignKeyConstraintName: 'FK_ap_fetch_log_context_hash',
	})
	public context: SkApContext | null;

	constructor(data?: Partial<SkApFetchLog>) {
		if (data) {
			Object.assign(this, data);
		}
	}
}