Switch to vercel's biome setup (#543)

This commit is contained in:
Jared Palmer 2024-11-15 13:00:15 -05:00 committed by GitHub
parent b8643353c0
commit 43aa1c6e58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
52 changed files with 414 additions and 201 deletions

View file

@ -20,6 +20,8 @@ import {
// Optionally, if not using email/pass login, you can
// use the Drizzle adapter for Auth.js / NextAuth
// https://authjs.dev/reference/adapter/drizzle
// biome-ignore lint: Forbidden non-null assertion.
const client = postgres(`${process.env.POSTGRES_URL!}?sslmode=require`);
const db = drizzle(client);
@ -232,8 +234,8 @@ export async function deleteDocumentsByIdAfterTimestamp({
.where(
and(
eq(suggestion.documentId, id),
gt(suggestion.documentCreatedAt, timestamp)
)
gt(suggestion.documentCreatedAt, timestamp),
),
);
return await db
@ -241,7 +243,7 @@ export async function deleteDocumentsByIdAfterTimestamp({
.where(and(eq(document.id, id), gt(document.createdAt, timestamp)));
} catch (error) {
console.error(
'Failed to delete documents by id after timestamp from database'
'Failed to delete documents by id after timestamp from database',
);
throw error;
}
@ -272,7 +274,7 @@ export async function getSuggestionsByDocumentId({
.where(and(eq(suggestion.documentId, documentId)));
} catch (error) {
console.error(
'Failed to get suggestions by document version from database'
'Failed to get suggestions by document version from database',
);
throw error;
}

View file

@ -57,7 +57,7 @@ export const vote = pgTable(
return {
pk: primaryKey({ columns: [table.chatId, table.messageId] }),
};
}
},
);
export type Vote = InferSelectModel<typeof vote>;
@ -77,7 +77,7 @@ export const document = pgTable(
return {
pk: primaryKey({ columns: [table.id, table.createdAt] }),
};
}
},
);
export type Document = InferSelectModel<typeof document>;
@ -103,7 +103,7 @@ export const suggestion = pgTable(
columns: [table.documentId, table.documentCreatedAt],
foreignColumns: [document.id, document.createdAt],
}),
})
}),
);
export type Suggestion = InferSelectModel<typeof suggestion>;

View file

@ -17,7 +17,7 @@ export function headingRule(level: number) {
return textblockTypeInputRule(
new RegExp(`^(#{1,${level}})\\s$`),
documentSchema.nodes.heading,
() => ({ level })
() => ({ level }),
);
}

View file

@ -49,7 +49,7 @@ export const patchDocumentNode = (schema, oldNode, newNode) => {
const matchedNodes = matchNodes(
schema,
diffOldChildren,
diffNewChildren
diffNewChildren,
).sort((a, b) => b.count - a.count);
const bestMatch = matchedNodes[0];
if (bestMatch) {
@ -62,11 +62,11 @@ export const patchDocumentNode = (schema, oldNode, newNode) => {
...patchRemainNodes(
schema,
oldBeforeMatchChildren,
newBeforeMatchChildren
)
newBeforeMatchChildren,
),
);
finalLeftChildren.push(
...diffOldChildren.slice(oldStartIndex, oldEndIndex)
...diffOldChildren.slice(oldStartIndex, oldEndIndex),
);
const oldAfterMatchChildren = diffOldChildren.slice(oldEndIndex);
@ -76,17 +76,17 @@ export const patchDocumentNode = (schema, oldNode, newNode) => {
...patchRemainNodes(
schema,
oldAfterMatchChildren,
newAfterMatchChildren
)
newAfterMatchChildren,
),
);
} else {
finalLeftChildren.push(
...patchRemainNodes(schema, diffOldChildren, diffNewChildren)
...patchRemainNodes(schema, diffOldChildren, diffNewChildren),
);
}
} else {
finalLeftChildren.push(
...patchRemainNodes(schema, diffOldChildren, diffNewChildren)
...patchRemainNodes(schema, diffOldChildren, diffNewChildren),
);
}
@ -155,7 +155,7 @@ const patchRemainNodes = (schema, oldChildren, newChildren) => {
!isTextNode(rightOldNode) && matchNodeType(rightOldNode, rightNewNode);
if (Array.isArray(leftOldNode) && Array.isArray(leftNewNode)) {
finalLeftChildren.push(
...patchTextNodes(schema, leftOldNode, leftNewNode)
...patchTextNodes(schema, leftOldNode, leftNewNode),
);
left += 1;
continue;
@ -165,7 +165,7 @@ const patchRemainNodes = (schema, oldChildren, newChildren) => {
const equalityLeft = computeChildEqualityFactor(leftOldNode, leftNewNode);
const equalityRight = computeChildEqualityFactor(
rightOldNode,
rightNewNode
rightNewNode,
);
if (equalityLeft < equalityRight) {
updateLeft = false;
@ -175,21 +175,21 @@ const patchRemainNodes = (schema, oldChildren, newChildren) => {
}
if (updateLeft) {
finalLeftChildren.push(
patchDocumentNode(schema, leftOldNode, leftNewNode)
patchDocumentNode(schema, leftOldNode, leftNewNode),
);
left += 1;
} else if (updateRight) {
finalRightChildren.unshift(
patchDocumentNode(schema, rightOldNode, rightNewNode)
patchDocumentNode(schema, rightOldNode, rightNewNode),
);
right += 1;
} else {
// Delete and insert
finalLeftChildren.push(
createDiffNode(schema, leftOldNode, DiffType.Deleted)
createDiffNode(schema, leftOldNode, DiffType.Deleted),
);
finalLeftChildren.push(
createDiffNode(schema, leftNewNode, DiffType.Inserted)
createDiffNode(schema, leftNewNode, DiffType.Inserted),
);
left += 1;
}
@ -202,7 +202,7 @@ const patchRemainNodes = (schema, oldChildren, newChildren) => {
...oldChildren
.slice(left, left + deleteNodeLen)
.flat()
.map((node) => createDiffNode(schema, node, DiffType.Deleted))
.map((node) => createDiffNode(schema, node, DiffType.Deleted)),
);
}
@ -211,7 +211,7 @@ const patchRemainNodes = (schema, oldChildren, newChildren) => {
...newChildren
.slice(left, left + insertNodeLen)
.flat()
.map((node) => createDiffNode(schema, node, DiffType.Inserted))
.map((node) => createDiffNode(schema, node, DiffType.Inserted)),
);
}
@ -233,7 +233,7 @@ export const patchTextNodes = (schema, oldNode, newNode) => {
// Map sentences to unique characters
const { chars1, chars2, lineArray } = sentencesToChars(
oldSentences,
newSentences
newSentences,
);
// Perform the diff
@ -253,7 +253,7 @@ export const patchTextNodes = (schema, oldNode, newNode) => {
const node = createTextNode(
schema,
sentence,
type !== DiffType.Unchanged ? [createDiffMark(schema, type)] : []
type !== DiffType.Unchanged ? [createDiffMark(schema, type)] : [],
);
return node;
});
@ -427,7 +427,7 @@ export const createNewNode = (oldNode, children) => {
oldNode.type,
oldNode.attrs,
Fragment.fromArray(children),
oldNode.marks
oldNode.marks,
);
};
@ -448,8 +448,8 @@ function mapDocumentNode(node, mapper) {
Fragment.from(
node.content.content
.map((node) => mapDocumentNode(node, mapper))
.filter((n) => n)
)
.filter((n) => n),
),
);
return mapper(copy) || copy;
}

View file

@ -24,7 +24,7 @@ export const buildContentFromDocument = (document: Node) => {
export const createDecorations = (
suggestions: Array<UISuggestion>,
view: EditorView
view: EditorView,
) => {
const decorations: Array<Decoration> = [];
@ -39,8 +39,8 @@ export const createDecorations = (
{
suggestionId: suggestion.id,
type: 'highlight',
}
)
},
),
);
decorations.push(
@ -53,8 +53,8 @@ export const createDecorations = (
{
suggestionId: suggestion.id,
type: 'widget',
}
)
},
),
);
}

View file

@ -45,7 +45,7 @@ function findPositionsInDoc(doc: Node, searchText: string): Position | null {
export function projectWithPositions(
doc: Node,
suggestions: Array<Suggestion>
suggestions: Array<Suggestion>,
): Array<UISuggestion> {
return suggestions.map((suggestion) => {
const positions = findPositionsInDoc(doc, suggestion.originalText);
@ -68,7 +68,7 @@ export function projectWithPositions(
export function createSuggestionWidget(
suggestion: UISuggestion,
view: EditorView
view: EditorView,
): { dom: HTMLElement; destroy: () => void } {
const dom = document.createElement('span');
const root = createRoot(dom);
@ -90,7 +90,7 @@ export function createSuggestionWidget(
state.doc,
currentDecorations.find().filter((decoration: Decoration) => {
return decoration.spec.suggestionId !== suggestion.id;
})
}),
);
decorationTransaction.setMeta(suggestionsPluginKey, {
@ -103,7 +103,7 @@ export function createSuggestionWidget(
const textTransaction = view.state.tr.replaceWith(
suggestion.selectionStart,
suggestion.selectionEnd,
state.schema.text(suggestion.suggestedText)
state.schema.text(suggestion.suggestedText),
);
textTransaction.setMeta('no-debounce', true);

View file

@ -24,7 +24,7 @@ export const fetcher = async (url: string) => {
if (!res.ok) {
const error = new Error(
'An error occurred while fetching the data.'
'An error occurred while fetching the data.',
) as ApplicationError;
error.info = await res.json();
@ -64,7 +64,7 @@ function addToolMessageToChat({
...message,
toolInvocations: message.toolInvocations.map((toolInvocation) => {
const toolResult = toolMessage.content.find(
(tool) => tool.toolCallId === toolInvocation.toolCallId
(tool) => tool.toolCallId === toolInvocation.toolCallId,
);
if (toolResult) {
@ -85,7 +85,7 @@ function addToolMessageToChat({
}
export function convertToUIMessages(
messages: Array<DBMessage>
messages: Array<DBMessage>,
): Array<Message> {
return messages.reduce((chatMessages: Array<Message>, message) => {
if (message.role === 'tool') {
@ -127,7 +127,7 @@ export function convertToUIMessages(
}
export function sanitizeResponseMessages(
messages: Array<CoreToolMessage | CoreAssistantMessage>
messages: Array<CoreToolMessage | CoreAssistantMessage>,
): Array<CoreToolMessage | CoreAssistantMessage> {
const toolResultIds: Array<string> = [];
@ -151,7 +151,7 @@ export function sanitizeResponseMessages(
? toolResultIds.includes(content.toolCallId)
: content.type === 'text'
? content.text.length > 0
: true
: true,
);
return {
@ -161,7 +161,7 @@ export function sanitizeResponseMessages(
});
return messagesBySanitizedContent.filter(
(message) => message.content.length > 0
(message) => message.content.length > 0,
);
}
@ -182,7 +182,7 @@ export function sanitizeUIMessages(messages: Array<Message>): Array<Message> {
const sanitizedToolInvocations = message.toolInvocations.filter(
(toolInvocation) =>
toolInvocation.state === 'result' ||
toolResultIds.includes(toolInvocation.toolCallId)
toolResultIds.includes(toolInvocation.toolCallId),
);
return {
@ -194,7 +194,7 @@ export function sanitizeUIMessages(messages: Array<Message>): Array<Message> {
return messagesBySanitizedToolInvocations.filter(
(message) =>
message.content.length > 0 ||
(message.toolInvocations && message.toolInvocations.length > 0)
(message.toolInvocations && message.toolInvocations.length > 0),
);
}
@ -205,7 +205,7 @@ export function getMostRecentUserMessage(messages: Array<CoreMessage>) {
export function getDocumentTimestampByIndex(
documents: Array<Document>,
index: number
index: number,
) {
if (!documents) return new Date();
if (index > documents.length) return new Date();