Add pretty formatting (#29)

* Test

* Add pretty formatting

* Fix Tests

* Fix Tests

* Fix Tests

* Fix

* Add pretty formatting fix

* Fix

* Test

* Fix tests

* Clean typeckech

* Add prettier check

* Fix api tsconfig

* Fix api tsconfig

* Fix tsconfig

* Fix

* Fix

* Prettier
This commit is contained in:
Martin Braquet
2026-02-20 17:32:27 +01:00
committed by GitHub
parent 1994697fa1
commit ba9b3cfb06
695 changed files with 22382 additions and 23209 deletions

View File

@@ -1,22 +1,28 @@
import {arraybeSchema, baseProfilesSchema, combinedProfileSchema, contentSchema, zBoolean,} from 'common/api/zod-types'
import {
arraybeSchema,
baseProfilesSchema,
combinedProfileSchema,
contentSchema,
zBoolean,
} from 'common/api/zod-types'
import {PrivateChatMessage} from 'common/chat-message'
import {Notification} from 'common/notifications'
import {CompatibilityScore} from 'common/profiles/compatibility-score'
import {MAX_COMPATIBILITY_QUESTION_LENGTH, OPTION_TABLES,} from 'common/profiles/constants'
import {MAX_COMPATIBILITY_QUESTION_LENGTH, OPTION_TABLES} from 'common/profiles/constants'
import {Profile, ProfileRow} from 'common/profiles/profile'
import {PrivateMessageChannel} from 'common/supabase/private-messages'
import {Row} from 'common/supabase/utils'
import {PrivateUser, User} from 'common/user'
import {notification_preference} from 'common/user-notification-preferences'
import {arrify} from 'common/util/array'
import {z} from 'zod'
import {LikeData, ShipData} from './profile-types'
import {FullUser} from './user-types'
import {PrivateMessageChannel} from 'common/supabase/private-messages'
import {Notification} from 'common/notifications'
import {arrify} from 'common/util/array'
import {notification_preference} from 'common/user-notification-preferences'
// mqp: very unscientific, just balancing our willingness to accept load
// with user willingness to put up with stale data
export const DEFAULT_CACHE_STRATEGY =
'public, max-age=5, stale-while-revalidate=10'
export const DEFAULT_CACHE_STRATEGY = 'public, max-age=5, stale-while-revalidate=10'
type APIGenericSchema = {
// GET is for retrieval, POST is to mutate something, PUT is idempotent mutation (can be repeated safely)
@@ -37,7 +43,7 @@ type APIGenericSchema = {
tag?: string
}
let _apiTypeCheck: { [x: string]: APIGenericSchema }
let _apiTypeCheck: {[x: string]: APIGenericSchema}
export const API = (_apiTypeCheck = {
health: {
@@ -64,7 +70,7 @@ export const API = (_apiTypeCheck = {
authed: true,
rateLimited: false,
props: z.object({}),
returns: {} as { jwt: string },
returns: {} as {jwt: string},
summary: 'Return a Supabase JWT for authenticated clients',
tag: 'Tokens',
},
@@ -146,7 +152,7 @@ export const API = (_apiTypeCheck = {
method: 'POST',
authed: true,
rateLimited: true,
returns: {} as { user: User; privateUser: PrivateUser },
returns: {} as {user: User; privateUser: PrivateUser},
props: z
.object({
deviceToken: z.string().optional(),
@@ -624,7 +630,7 @@ export const API = (_apiTypeCheck = {
}),
returns: {
channels: [] as PrivateMessageChannel[],
memberIdsByChannelId: {} as { [channelId: string]: string[] },
memberIdsByChannelId: {} as {[channelId: string]: string[]},
},
summary: 'List private message channel memberships',
tag: 'Messages',
@@ -647,10 +653,7 @@ export const API = (_apiTypeCheck = {
authed: true,
rateLimited: false,
props: z.object({
channelIds: z
.array(z.coerce.number())
.or(z.coerce.number())
.transform(arrify),
channelIds: z.array(z.coerce.number()).or(z.coerce.number()).transform(arrify),
}),
returns: [] as [number, string][],
summary: 'Get last seen times for one or more channels',
@@ -850,7 +853,7 @@ export const API = (_apiTypeCheck = {
authed: false,
rateLimited: false,
props: z.object({}),
returns: {} as { count: number },
returns: {} as {count: number},
summary: 'Get the total number of messages (public endpoint)',
tag: 'Messages',
},
@@ -904,7 +907,7 @@ export const API = (_apiTypeCheck = {
method: 'POST',
authed: true,
rateLimited: true,
returns: {} as { success: boolean },
returns: {} as {success: boolean},
props: z.object({
eventId: z.string(),
}),
@@ -915,7 +918,7 @@ export const API = (_apiTypeCheck = {
method: 'POST',
authed: true,
rateLimited: true,
returns: {} as { success: boolean },
returns: {} as {success: boolean},
props: z.object({
eventId: z.string(),
status: z.enum(['going', 'maybe', 'not_going']),
@@ -927,7 +930,7 @@ export const API = (_apiTypeCheck = {
method: 'POST',
authed: true,
rateLimited: true,
returns: {} as { success: boolean },
returns: {} as {success: boolean},
props: z.object({
eventId: z.string(),
}),
@@ -968,7 +971,7 @@ export const API = (_apiTypeCheck = {
method: 'POST',
authed: true,
rateLimited: false,
returns: {} as { success: boolean },
returns: {} as {success: boolean},
props: z
.object({
eventId: z.string(),
@@ -991,17 +994,15 @@ export type APIPath = keyof typeof API
export type APISchema<N extends APIPath> = (typeof API)[N]
export type APIParams<N extends APIPath> = z.input<APISchema<N>['props']>
export type ValidatedAPIParams<N extends APIPath> = z.output<
APISchema<N>['props']
>
export type ValidatedAPIParams<N extends APIPath> = z.output<APISchema<N>['props']>
export type APIResponse<N extends APIPath> =
APISchema<N> extends {
returns: Record<string, any>
}
returns: Record<string, any>
}
? APISchema<N>['returns']
: void
export type APIResponseOptionalContinue<N extends APIPath> =
| { continue: () => Promise<void>; result: APIResponse<N> }
| {continue: () => Promise<void>; result: APIResponse<N>}
| APIResponse<N>

View File

@@ -1,6 +1,6 @@
import { ENV_CONFIG, MOD_USERNAMES } from 'common/envs/constants'
import { User } from 'common/user'
import { removeUndefinedProps } from 'common/util/object'
import {ENV_CONFIG, MOD_USERNAMES} from 'common/envs/constants'
import {User} from 'common/user'
import {removeUndefinedProps} from 'common/util/object'
export type DisplayUser = {
id: string

View File

@@ -1,5 +1,5 @@
import {BACKEND_DOMAIN} from 'common/envs/constants'
import {IS_LOCAL} from "common/hosting/constants";
import {IS_LOCAL} from 'common/hosting/constants'
type ErrorCode =
| 400 // your input is bad (like zod is mad)

View File

@@ -1,4 +1,4 @@
import { ClientMessage, ClientMessageType, ServerMessage } from './websockets'
import {ClientMessage, ClientMessageType, ServerMessage} from './websockets'
// mqp: useful for debugging
const VERBOSE_LOGGING = false
@@ -13,11 +13,7 @@ type OpenState = typeof WebSocket.OPEN
type ClosingState = typeof WebSocket.CLOSING
type ClosedState = typeof WebSocket.CLOSED
export type ReadyState =
| OpenState
| ConnectingState
| ClosedState
| ClosingState
export type ReadyState = OpenState | ConnectingState | ClosedState | ClosingState
export function formatState(state: ReadyState) {
switch (state) {
@@ -54,7 +50,7 @@ export class APIRealtimeClient {
// subscribers by the topic they are subscribed to
subscriptions: Map<string, BroadcastHandler[]>
connectTimeout?: NodeJS.Timeout
heartbeat?: number | undefined;
heartbeat?: number | undefined
constructor(url: string) {
this.url = url
@@ -93,9 +89,9 @@ export class APIRealtimeClient {
// Send a heartbeat ping every 25s
this.heartbeat = window.setInterval(() => {
if (this.ws.readyState === WebSocket.OPEN) {
this.sendMessage('ping', {}).catch(console.error);
this.sendMessage('ping', {}).catch(console.error)
}
}, 25000);
}, 25000)
if (this.subscriptions.size > 0) {
this.sendMessage('subscribe', {
topics: Array.from(this.subscriptions.keys()),
@@ -176,7 +172,7 @@ export class APIRealtimeClient {
async sendMessage<T extends ClientMessageType>(
type: T,
data: Omit<ClientMessage<T>, 'type' | 'txid'>
data: Omit<ClientMessage<T>, 'type' | 'txid'>,
) {
if (VERBOSE_LOGGING) {
console.info(`> Outgoing API websocket ${type} message: `, data)
@@ -188,8 +184,8 @@ export class APIRealtimeClient {
this.txns.delete(txid)
reject(new Error(`Websocket message with txid ${txid} timed out.`))
}, TIMEOUT_MS)
this.txns.set(txid, { resolve, reject, timeout })
this.ws.send(JSON.stringify({ type, txid, ...data }))
this.txns.set(txid, {resolve, reject, timeout})
this.ws.send(JSON.stringify({type, txid, ...data}))
})
} else {
// expected if components in the code try to subscribe or unsubscribe
@@ -199,7 +195,7 @@ export class APIRealtimeClient {
}
async identify(uid: string) {
return await this.sendMessage('identify', { uid })
return await this.sendMessage('identify', {uid})
}
async subscribe(topics: string[], handler: BroadcastHandler) {
@@ -207,7 +203,7 @@ export class APIRealtimeClient {
let existingHandlers = this.subscriptions.get(topic)
if (existingHandlers == null) {
this.subscriptions.set(topic, (existingHandlers = [handler]))
return await this.sendMessage('subscribe', { topics: [topic] })
return await this.sendMessage('subscribe', {topics: [topic]})
} else {
existingHandlers.push(handler)
}
@@ -225,7 +221,7 @@ export class APIRealtimeClient {
this.subscriptions.set(topic, remainingHandlers)
} else {
this.subscriptions.delete(topic)
return await this.sendMessage('unsubscribe', { topics: [topic] })
return await this.sendMessage('unsubscribe', {topics: [topic]})
}
}
}

View File

@@ -1,4 +1,4 @@
import { z } from 'zod'
import {z} from 'zod'
export const CLIENT_MESSAGE_SCHEMAS = {
identify: z.object({
@@ -55,11 +55,13 @@ export const SERVER_MESSAGE_SCHEMA = z.union([
])
export type ClientMessageType = keyof typeof CLIENT_MESSAGE_SCHEMAS
export type ClientMessage<T extends ClientMessageType = ClientMessageType> =
z.infer<(typeof CLIENT_MESSAGE_SCHEMAS)[T]>
export type ClientMessage<T extends ClientMessageType = ClientMessageType> = z.infer<
(typeof CLIENT_MESSAGE_SCHEMAS)[T]
>
export type ServerMessageType = keyof typeof SERVER_MESSAGE_SCHEMAS
export type ServerMessage<T extends ServerMessageType = ServerMessageType> =
z.infer<(typeof SERVER_MESSAGE_SCHEMAS)[T]>
export type ServerMessage<T extends ServerMessageType = ServerMessageType> = z.infer<
(typeof SERVER_MESSAGE_SCHEMAS)[T]
>
export type BroadcastPayload = ServerMessage<'broadcast'>['data']

View File

@@ -1,12 +1,9 @@
import {z} from 'zod'
import {type JSONContent} from '@tiptap/core'
import {arrify} from 'common/util/array'
import {z} from 'zod'
/* GET request array can be like ?a=1 or ?a=1&a=2 */
export const arraybeSchema = z
.array(z.string())
.or(z.string())
.transform(arrify)
export const arraybeSchema = z.array(z.string()).or(z.string()).transform(arrify)
export const contentSchema: z.ZodType<JSONContent> = z.lazy(() =>
z.intersection(
@@ -22,13 +19,13 @@ export const contentSchema: z.ZodType<JSONContent> = z.lazy(() =>
z.object({
type: z.string(),
attrs: z.record(z.any()).optional(),
})
)
}),
),
)
.optional(),
text: z.string().optional(),
})
)
}),
),
)
const genderType = z.string()
@@ -110,6 +107,4 @@ const optionalProfilesSchema = z.object({
work: z.array(z.string()).optional().nullable(),
})
export const combinedProfileSchema = baseProfilesSchema.merge(
optionalProfilesSchema
)
export const combinedProfileSchema = baseProfilesSchema.merge(optionalProfilesSchema)