packages/server/src/types/index.ts 3.2 K raw
1
export type Bindings = {
2
  DB: D1Database;
3
  RESOLUTION_QUEUE: Queue;
4
  TAP_WEBHOOK_SECRET?: string;
5
  JETSTREAM_CONSUMER: DurableObjectNamespace;
6
};
7
8
// Jetstream WebSocket event types
9
export interface JetstreamCommitEvent {
10
  did: string;
11
  time_us: number;
12
  kind: "commit";
13
  commit: {
14
    rev: string;
15
    operation: "create" | "update" | "delete";
16
    collection: string;
17
    rkey: string;
18
    record?: Record<string, unknown>;
19
    cid?: string;
20
  };
21
}
22
23
export interface JetstreamIdentityEvent {
24
  did: string;
25
  time_us: number;
26
  kind: "identity";
27
  identity: { did: string; seq: number; time: string };
28
}
29
30
export interface JetstreamAccountEvent {
31
  did: string;
32
  time_us: number;
33
  kind: "account";
34
  account: {
35
    active: boolean;
36
    did: string;
37
    seq: number;
38
    time: string;
39
    status?: string;
40
  };
41
}
42
43
export type JetstreamEvent =
44
  | JetstreamCommitEvent
45
  | JetstreamIdentityEvent
46
  | JetstreamAccountEvent;
47
48
export interface TapRecordEvent {
49
  id: number;
50
  type: "record";
51
  record: {
52
    live: boolean;
53
    rev: string;
54
    did: string;
55
    collection: string;
56
    rkey: string;
57
    action: "create" | "update" | "delete";
58
    cid?: string;
59
    record?: Record<string, unknown>;
60
  };
61
}
62
63
export interface TapIdentityEvent {
64
  id: number;
65
  type: "identity";
66
  identity: {
67
    did: string;
68
    handle: string;
69
    isActive: boolean;
70
    status: string;
71
  };
72
}
73
74
export type TapEvent = TapRecordEvent | TapIdentityEvent;
75
76
// Strong reference to a Bluesky post
77
export interface BskyPostRef {
78
  uri: string;
79
  cid: string;
80
}
81
82
// Publication record from site.standard.publication
83
export interface Publication {
84
  url: string;  // Base publication URL
85
  name: string;
86
  description?: string;
87
  iconCid?: string;  // CID for icon blob
88
  iconUrl?: string;  // Resolved full URL to icon
89
}
90
91
// Document record from site.standard.document
92
export interface Document {
93
  uri: string;
94
  did: string;
95
  rkey: string;
96
  // Document fields
97
  title: string;
98
  description?: string;
99
  path?: string;
100
  site?: string;  // at:// URI to publication or https:// URL
101
  content?: unknown;
102
  textContent?: string;
103
  coverImageCid?: string;  // CID for cover image blob
104
  coverImageUrl?: string;  // Resolved full URL to cover image
105
  bskyPostRef?: BskyPostRef;
106
  tags?: string[];
107
  publishedAt?: string;
108
  updatedAt?: string;
109
  // Resolved publication data
110
  publication?: Publication;
111
  // Metadata
112
  viewUrl?: string;  // Canonical URL (publication.url + path)
113
  pdsEndpoint?: string;  // PDS endpoint used for blob URLs
114
}
115
116
// Database row for resolved_documents table
117
export interface ResolvedDocumentRow {
118
  uri: string;
119
  did: string;
120
  rkey: string;
121
  title: string | null;
122
  description: string | null;
123
  path: string | null;
124
  site: string | null;
125
  content: string | null;
126
  text_content: string | null;
127
  cover_image_cid: string | null;
128
  cover_image_url: string | null;
129
  bsky_post_ref: string | null;
130
  tags: string | null;
131
  published_at: string | null;
132
  updated_at: string | null;
133
  pub_url: string | null;
134
  pub_name: string | null;
135
  pub_description: string | null;
136
  pub_icon_cid: string | null;
137
  pub_icon_url: string | null;
138
  view_url: string | null;
139
  pds_endpoint: string | null;
140
  resolved_at: string | null;
141
  stale_at: string | null;
142
  verified: number | null;
143
}