mirror of
https://github.com/outline/outline.git
synced 2026-11-22 22:02:35 +03:00
Merge branch 'main' of github.com:outline/outline into tommoor/new-permissions
This commit is contained in:
66 files changed
+2656
-457
No files matched your search
@@ -3,6 +3,7 @@ import { useState, useMemo } from "react";
|
||||
import { useTranslation, Trans } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
import type { NavigationNode } from "@shared/types";
|
||||
import { descendants, flattenTree } from "@shared/utils/tree";
|
||||
import type Document from "~/models/Document";
|
||||
import Button from "~/components/Button";
|
||||
import Text from "~/components/Text";
|
||||
@@ -23,13 +24,23 @@ function DocumentMove({ document }: Props) {
|
||||
const [selectedPath, selectPath] = useState<NavigationNode | null>(null);
|
||||
|
||||
const items = useMemo(() => {
|
||||
// Recursively filter out the document itself and its existing parent doc, if any.
|
||||
// Collect the IDs of the document itself and all of its descendants so they
|
||||
// can be excluded from the move targets (moving to self or a descendant
|
||||
// would create a cycle; moving to the exact same location is a no-op).
|
||||
const allNodes = collectionTrees.flatMap(flattenTree);
|
||||
const sourceNode = allNodes.find((node) => node.id === document.id);
|
||||
const excludedIds = new Set<string>([document.id]);
|
||||
if (sourceNode) {
|
||||
descendants(sourceNode).forEach((n) => excludedIds.add(n.id));
|
||||
}
|
||||
|
||||
// Recursively filter out the document itself and its descendants.
|
||||
// The document's current parent is intentionally kept so that siblings
|
||||
// remain visible as valid move targets.
|
||||
const filterSourceDocument = (node: NavigationNode): NavigationNode => ({
|
||||
...node,
|
||||
children: node.children
|
||||
?.filter(
|
||||
(c) => c.id !== document.id && c.id !== document.parentDocumentId
|
||||
)
|
||||
?.filter((c) => !excludedIds.has(c.id))
|
||||
.map(filterSourceDocument),
|
||||
});
|
||||
|
||||
@@ -43,7 +54,7 @@ function DocumentMove({ document }: Props) {
|
||||
);
|
||||
|
||||
return nodes;
|
||||
}, [policies, collectionTrees, document.id, document.parentDocumentId]);
|
||||
}, [policies, collectionTrees, document.id]);
|
||||
|
||||
const move = async () => {
|
||||
if (!selectedPath) {
|
||||
|
||||
@@ -265,27 +265,30 @@ function InnerDocumentLink(
|
||||
};
|
||||
});
|
||||
|
||||
const nodeChildren = React.useMemo(() => {
|
||||
const insertDraftDocument =
|
||||
activeDocument?.isDraft &&
|
||||
activeDocument?.isActive &&
|
||||
activeDocument?.parentDocumentId === node.id;
|
||||
const insertDraftChild = !!(
|
||||
activeDocument?.isDraft &&
|
||||
activeDocument?.isActive &&
|
||||
activeDocument?.parentDocumentId === node.id
|
||||
);
|
||||
|
||||
return collection && insertDraftDocument
|
||||
? sortNavigationNodes(
|
||||
[activeDocument?.asNavigationNode, ...node.children],
|
||||
collection.sort,
|
||||
false
|
||||
)
|
||||
: node.children;
|
||||
}, [
|
||||
activeDocument?.isActive,
|
||||
activeDocument?.isDraft,
|
||||
activeDocument?.parentDocumentId,
|
||||
activeDocument?.asNavigationNode,
|
||||
collection,
|
||||
node,
|
||||
]);
|
||||
// Only subscribe to asNavigationNode when this node is the parent of an
|
||||
// active draft. This avoids every DocumentLink observer re-rendering on
|
||||
// every title keystroke.
|
||||
const draftNavNode = insertDraftChild
|
||||
? activeDocument?.asNavigationNode
|
||||
: undefined;
|
||||
|
||||
const nodeChildren = React.useMemo(
|
||||
() =>
|
||||
collection && draftNavNode
|
||||
? sortNavigationNodes(
|
||||
[draftNavNode, ...node.children],
|
||||
collection.sort,
|
||||
false
|
||||
)
|
||||
: node.children,
|
||||
[draftNavNode, collection, node]
|
||||
);
|
||||
|
||||
const doc = documents.get(node.id);
|
||||
const title = doc?.title || node.title || t("Untitled");
|
||||
|
||||
@@ -7,38 +7,32 @@ export default function useCollectionDocuments(
|
||||
collection: Collection | undefined,
|
||||
activeDocument: Document | undefined
|
||||
) {
|
||||
const insertDraftDocument = useMemo(
|
||||
() =>
|
||||
activeDocument &&
|
||||
activeDocument.isActive &&
|
||||
activeDocument.isDraft &&
|
||||
activeDocument.collectionId === collection?.id &&
|
||||
!activeDocument.parentDocumentId,
|
||||
[
|
||||
activeDocument?.isActive,
|
||||
activeDocument?.isDraft,
|
||||
activeDocument?.collectionId,
|
||||
activeDocument?.parentDocumentId,
|
||||
collection?.id,
|
||||
]
|
||||
const insertDraftDocument = !!(
|
||||
activeDocument &&
|
||||
activeDocument.isActive &&
|
||||
activeDocument.isDraft &&
|
||||
activeDocument.collectionId === collection?.id &&
|
||||
!activeDocument.parentDocumentId
|
||||
);
|
||||
|
||||
// Only subscribe to asNavigationNode when we actually need to insert a draft
|
||||
// into the sorted list. This avoids every CollectionLinkChildren observer
|
||||
// re-rendering on every title keystroke.
|
||||
const draftNavNode = insertDraftDocument
|
||||
? activeDocument?.asNavigationNode
|
||||
: undefined;
|
||||
|
||||
return useMemo(() => {
|
||||
if (!collection?.sortedDocuments) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return insertDraftDocument && activeDocument
|
||||
return draftNavNode
|
||||
? sortNavigationNodes(
|
||||
[activeDocument.asNavigationNode, ...collection.sortedDocuments],
|
||||
[draftNavNode, ...collection.sortedDocuments],
|
||||
collection.sort,
|
||||
false
|
||||
)
|
||||
: collection.sortedDocuments;
|
||||
}, [
|
||||
insertDraftDocument,
|
||||
activeDocument?.asNavigationNode,
|
||||
collection?.sortedDocuments,
|
||||
collection?.sort,
|
||||
]);
|
||||
}, [draftNavNode, collection?.sortedDocuments, collection?.sort]);
|
||||
}
|
||||
@@ -944,7 +944,7 @@ const EditorContainer = styled(Styles)<{
|
||||
a#comment-${props.focusedCommentId}
|
||||
~ span.component-image
|
||||
div.image-wrapper {
|
||||
outline: ${props.theme.commentMarkBackground} solid 2px;
|
||||
outline: ${props.theme.commentedImageOutlineDark} solid 2px;
|
||||
}
|
||||
`}
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ import Icon from "@shared/components/Icon";
|
||||
import { richExtensions } from "@shared/editor/nodes";
|
||||
import { canUseElementFullscreen } from "@shared/utils/browser";
|
||||
import { s, depths, hover } from "@shared/styles";
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
import type { ProsemirrorData } from "@shared/types";
|
||||
import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
||||
import { colorPalette } from "@shared/utils/collections";
|
||||
import Editor from "~/components/Editor";
|
||||
import NudeButton from "~/components/NudeButton";
|
||||
@@ -130,8 +132,16 @@ function PresentationMode({ title, icon, iconColor, data, onClose }: Props) {
|
||||
const supportsFullscreen = React.useMemo(() => canUseElementFullscreen(), []);
|
||||
const isIdle = useIdle(3000, idleEvents);
|
||||
|
||||
const strippedData = React.useMemo(
|
||||
() =>
|
||||
ProsemirrorHelper.removeMarks(cloneDeep(data), [
|
||||
"comment",
|
||||
]) as ProsemirrorData,
|
||||
[data]
|
||||
);
|
||||
|
||||
const slides = React.useMemo(() => {
|
||||
const result = splitIntoSlides(data, title, icon, iconColor);
|
||||
const result = splitIntoSlides(strippedData, title, icon, iconColor);
|
||||
const contentSlides = result.filter((s) => s.type === "content");
|
||||
const hasContent =
|
||||
contentSlides.length > 0 &&
|
||||
@@ -144,7 +154,7 @@ function PresentationMode({ title, icon, iconColor, data, onClose }: Props) {
|
||||
}
|
||||
|
||||
return result;
|
||||
}, [data, title, icon, iconColor]);
|
||||
}, [strippedData, title, icon, iconColor]);
|
||||
|
||||
const totalSlides = slides.length;
|
||||
|
||||
|
||||
@@ -89,12 +89,16 @@ function AuthenticationProvider(props: Props) {
|
||||
|
||||
// Populate hidden form fields with authentication data
|
||||
if (formRef.current) {
|
||||
const createInputs = (obj: any, prefix = "") => {
|
||||
const createInputs = (obj: Record<string, unknown>, prefix = "") => {
|
||||
Object.entries(obj).forEach(([key, value]) => {
|
||||
if (value === undefined || value === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fieldName = prefix ? `${prefix}[${key}]` : key;
|
||||
|
||||
if (value && typeof value === "object" && !Array.isArray(value)) {
|
||||
createInputs(value, fieldName);
|
||||
if (typeof value === "object" && !Array.isArray(value)) {
|
||||
createInputs(value as Record<string, unknown>, fieldName);
|
||||
} else {
|
||||
// Create hidden input for primitive values
|
||||
const input = document.createElement("input");
|
||||
|
||||
@@ -24,7 +24,11 @@ class UnfurlsStore extends Store<Unfurl<any>> {
|
||||
}): Promise<Unfurl<UnfurlType> | undefined> => {
|
||||
try {
|
||||
const protocol = new URL(url).protocol;
|
||||
if (protocol !== "http:" && protocol !== "https:" && protocol !== "mention:") {
|
||||
if (
|
||||
protocol !== "http:" &&
|
||||
protocol !== "https:" &&
|
||||
protocol !== "mention:"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
} catch (_err) {
|
||||
|
||||
Vendored
+2
@@ -141,6 +141,8 @@ declare module "styled-components" {
|
||||
textDiffDeletedBackground: string;
|
||||
placeholder: string;
|
||||
commentMarkBackground: string;
|
||||
commentedImageOutlineLight: string;
|
||||
commentedImageOutlineDark: string;
|
||||
sidebarBackground: string;
|
||||
sidebarHoverBackground: string;
|
||||
sidebarActiveBackground: string;
|
||||
|
||||
+1
-1
@@ -169,7 +169,7 @@
|
||||
"markdown-it": "^14.1.0",
|
||||
"markdown-it-container": "^3.0.0",
|
||||
"markdown-it-emoji": "^3.0.0",
|
||||
"mermaid": "11.12.1",
|
||||
"mermaid": "11.13.0",
|
||||
"mime-types": "^3.0.1",
|
||||
"mobx": "^4.15.4",
|
||||
"mobx-react": "^6.3.1",
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import { Trans } from "react-i18next";
|
||||
|
||||
export const Translations = () => (
|
||||
<>
|
||||
<Trans defaults={`New attribute`} />
|
||||
<Trans defaults={`Paper size`} />
|
||||
<Trans defaults={`Ask AI "{{question}}"`} />
|
||||
<Trans defaults={`Are you sure you want to delete?`} />
|
||||
<Trans
|
||||
defaults={`Deleting this version of the document will permanently and irrevocably remove it from the history.`}
|
||||
/>
|
||||
<Trans defaults={`Format`} />
|
||||
<Trans defaults={`Add option`} />
|
||||
<Trans defaults={`Optional`} />
|
||||
<Trans defaults={`Choose a size for your exported document`} />
|
||||
<Trans defaults={`Revision renamed`} />
|
||||
<Trans defaults={`Failed to save revision`} />
|
||||
<Trans defaults={`Invite to document`} />
|
||||
<Trans defaults={`Sorry, invalid embed link`} />
|
||||
<Trans defaults={`Data Attributes`} />
|
||||
<Trans defaults={`Edit attribute`} />
|
||||
<Trans defaults={`Property`} />
|
||||
<Trans defaults={`Yes`} />
|
||||
<Trans defaults={`No`} />
|
||||
<Trans defaults={`Search or ask a question`} />
|
||||
<Trans
|
||||
defaults={`Invited {{roleName}} will not receive access to any collections or documents unless explicitly shared.`}
|
||||
/>
|
||||
<Trans defaults={`Can view only what is explicitly shared`} />
|
||||
<Trans
|
||||
defaults={`SAML assertion was invalid or missing fields, please check your configuration`}
|
||||
/>
|
||||
<Trans
|
||||
defaults={`AI generated answer based on related documents in your workspace`}
|
||||
/>
|
||||
<Trans defaults={`References`} />
|
||||
<Trans
|
||||
defaults={`Enable AI answers to get direct answers to searched questions.`}
|
||||
/>
|
||||
<Trans defaults={`Go to settings`} />
|
||||
<Trans defaults={`Where do I find the file?`} />
|
||||
<Trans
|
||||
defaults={`In a Confluence space, navigate to <em>Space Settings -> Manage space -> Export space</em> and choose to export as HTML with the "Normal Export" option.`}
|
||||
/>
|
||||
<Trans
|
||||
defaults={`Drag and drop the zip file from Confluence's HTML export option, or click to upload`}
|
||||
/>
|
||||
<Trans defaults={`Guests`} />
|
||||
<Trans defaults={`New Attribute`} />
|
||||
<Trans
|
||||
defaults={`Attributes allow you to define data to be stored with your documents. They can be used to store custom properties, metadata, or any other structured information that is common across documents.`}
|
||||
/>
|
||||
<Trans defaults={`Custom domain`} />
|
||||
<Trans defaults={`AI answers`} />
|
||||
<Trans
|
||||
defaults={`Use AI to directly answer searched questions using content in your workspace.`}
|
||||
/>
|
||||
<Trans defaults={`API access`} />
|
||||
<Trans
|
||||
defaults={`Allow members to create API keys for programmatic access`}
|
||||
/>
|
||||
<Trans defaults={`Public document embedding`} />
|
||||
<Trans
|
||||
defaults={`When enabled, publicly shared documents can be embedded in third-party websites`}
|
||||
/>
|
||||
<Trans defaults={`Include previews in emails`} />
|
||||
<Trans
|
||||
defaults={`When enabled, email notifications will include content previews`}
|
||||
/>
|
||||
<Trans defaults={`Boolean`} />
|
||||
<Trans defaults={`Number`} />
|
||||
<Trans defaults={`Text`} />
|
||||
<Trans defaults={`List`} />
|
||||
<Trans defaults={`Could not load events`} />
|
||||
<Trans defaults={`Audit Log`} />
|
||||
<Trans
|
||||
defaults={`The audit log details the history of security related and other events across your knowledge base.`}
|
||||
/>
|
||||
<Trans defaults={`IP address`} />
|
||||
<Trans defaults={`Actor`} />
|
||||
<Trans defaults={`Event`} />
|
||||
<Trans defaults={`Timestamp`} />
|
||||
<Trans defaults={`IP`} />
|
||||
<Trans defaults={`a group`} />
|
||||
<Trans defaults={`All users`} />
|
||||
<Trans defaults={`Private`} />
|
||||
<Trans defaults={`View and edit`} />
|
||||
<Trans defaults={`Sharing enabled`} />
|
||||
<Trans defaults={`Date archived`} />
|
||||
<Trans defaults={`Could not load collections`} />
|
||||
<Trans
|
||||
defaults={`Manage the permissions and settings of all collections in the knowledge base. As a workspace admin you can also administer private collections.`}
|
||||
/>
|
||||
<Trans
|
||||
defaults={`Automatically index and search document content from {{appName}} inside <4>Glean</4> in realtime.`}
|
||||
/>
|
||||
<Trans defaults={`API Endpoint`} />
|
||||
<Trans defaults={`API Secret`} />
|
||||
<Trans defaults={`Datasource`} />
|
||||
<Trans
|
||||
defaults={`Details of the current {{appName}} license. To arrange contract renewal as expiry or seat limits approach or increase licensed seats please contact your account manager or email <4>priority@getoutline.com</4>.`}
|
||||
/>
|
||||
<Trans
|
||||
defaults={`Sorry, an answer could not be found in the collection, try widening your search.`}
|
||||
/>
|
||||
<Trans
|
||||
defaults={`Sorry, an answer could not be found in the workspace, try widening your search.`}
|
||||
/>
|
||||
<Trans defaults={`Looking for answers`} />
|
||||
<Trans defaults={`Answer to "{{ query }}"`} />
|
||||
</>
|
||||
);
|
||||
@@ -95,12 +95,20 @@ router.post(
|
||||
const { user } = ctx.state.auth;
|
||||
authorize(user, "createUserPasskey", user.team);
|
||||
|
||||
// Fetch existing passkeys to exclude them from registration
|
||||
const existingPasskeys = await UserPasskey.findAll({
|
||||
where: { userId: user.id },
|
||||
});
|
||||
|
||||
const options = await generateRegistrationOptions({
|
||||
rpName,
|
||||
rpID: getRpID(ctx),
|
||||
userID: isoBase64URL.toBuffer(user.id),
|
||||
userName: user.email || user.name,
|
||||
// Don't exclude credentials, so we can detect if one is already registered (optional)
|
||||
excludeCredentials: existingPasskeys.map((pk) => ({
|
||||
id: pk.credentialId,
|
||||
transports: pk.transports as AuthenticatorTransportFuture[],
|
||||
})),
|
||||
authenticatorSelection: {
|
||||
residentKey: "preferred",
|
||||
userVerification: "preferred",
|
||||
@@ -154,6 +162,7 @@ router.post(
|
||||
}
|
||||
|
||||
const { verified, registrationInfo } = verification;
|
||||
const ZERO_AAGUID = "00000000-0000-0000-0000-000000000000";
|
||||
|
||||
if (verified && registrationInfo) {
|
||||
const { credential, aaguid } = registrationInfo;
|
||||
@@ -166,7 +175,7 @@ router.post(
|
||||
const userAgent = ctx.request.get("user-agent");
|
||||
const transports = body.response.transports || [];
|
||||
|
||||
// Check if already exists
|
||||
// Check if already exists by credential ID
|
||||
const existing = await UserPasskey.findOne({
|
||||
where: { credentialId: credentialIdBase64 },
|
||||
});
|
||||
@@ -183,6 +192,17 @@ router.post(
|
||||
aaguid,
|
||||
});
|
||||
} else {
|
||||
// Check if user already has a passkey from the same authenticator
|
||||
if (aaguid && aaguid !== ZERO_AAGUID) {
|
||||
const duplicateDevice = await UserPasskey.findOne({
|
||||
where: { userId: user.id, aaguid },
|
||||
});
|
||||
|
||||
if (duplicateDevice) {
|
||||
throw ValidationError("You already have a passkey on this device");
|
||||
}
|
||||
}
|
||||
|
||||
await UserPasskey.createWithCtx(ctx, {
|
||||
userId: user.id,
|
||||
credentialId: credentialIdBase64,
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"id": "search-postgres",
|
||||
"name": "PostgreSQL Search",
|
||||
"priority": 0,
|
||||
"description": "Full-text search powered by PostgreSQL tsvector."
|
||||
}
|
||||
+71
-68
@@ -4,7 +4,6 @@ import {
|
||||
SortFilter,
|
||||
StatusFilter,
|
||||
} from "@shared/types";
|
||||
import SearchHelper from "@server/models/helpers/SearchHelper";
|
||||
import {
|
||||
buildDocument,
|
||||
buildDraftDocument,
|
||||
@@ -14,15 +13,19 @@ import {
|
||||
buildShare,
|
||||
buildGroup,
|
||||
} from "@server/test/factories";
|
||||
import UserMembership from "../UserMembership";
|
||||
import GroupMembership from "../GroupMembership";
|
||||
import UserMembership from "@server/models/UserMembership";
|
||||
import GroupMembership from "@server/models/GroupMembership";
|
||||
import SearchProviderManager from "@server/utils/SearchProviderManager";
|
||||
import PostgresSearchProvider from "./PostgresSearchProvider";
|
||||
|
||||
const provider = SearchProviderManager.getProvider();
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.resetAllMocks();
|
||||
await buildDocument();
|
||||
});
|
||||
|
||||
describe("SearchHelper", () => {
|
||||
describe("PostgresSearchProvider", () => {
|
||||
describe("#searchForTeam", () => {
|
||||
it("should return search results from public collections", async () => {
|
||||
const team = await buildTeam();
|
||||
@@ -34,7 +37,7 @@ describe("SearchHelper", () => {
|
||||
collectionId: collection.id,
|
||||
title: "test",
|
||||
});
|
||||
const { results } = await SearchHelper.searchForTeam(team, {
|
||||
const { results } = await provider.searchForTeam(team, {
|
||||
query: "test",
|
||||
});
|
||||
expect(results.length).toBe(1);
|
||||
@@ -58,7 +61,7 @@ describe("SearchHelper", () => {
|
||||
title: "document 2",
|
||||
}),
|
||||
]);
|
||||
const { results } = await SearchHelper.searchForTeam(team);
|
||||
const { results } = await provider.searchForTeam(team);
|
||||
expect(results.length).toBe(2);
|
||||
expect(results.map((r) => r.document.id).sort()).toEqual(
|
||||
documents.map((doc) => doc.id).sort()
|
||||
@@ -76,7 +79,7 @@ describe("SearchHelper", () => {
|
||||
collectionId: collection.id,
|
||||
title: "test",
|
||||
});
|
||||
const { results } = await SearchHelper.searchForTeam(team, {
|
||||
const { results } = await provider.searchForTeam(team, {
|
||||
query: "test",
|
||||
});
|
||||
expect(results.length).toBe(0);
|
||||
@@ -93,7 +96,7 @@ describe("SearchHelper", () => {
|
||||
collectionId: collection.id,
|
||||
title: "test",
|
||||
});
|
||||
const { results } = await SearchHelper.searchForTeam(team, {
|
||||
const { results } = await provider.searchForTeam(team, {
|
||||
query: "test",
|
||||
collectionId: collection.id,
|
||||
});
|
||||
@@ -122,7 +125,7 @@ describe("SearchHelper", () => {
|
||||
includeChildDocuments: true,
|
||||
});
|
||||
|
||||
const { results } = await SearchHelper.searchForTeam(team, {
|
||||
const { results } = await provider.searchForTeam(team, {
|
||||
query: "test",
|
||||
collectionId: collection.id,
|
||||
share,
|
||||
@@ -132,7 +135,7 @@ describe("SearchHelper", () => {
|
||||
|
||||
it("should handle no collections", async () => {
|
||||
const team = await buildTeam();
|
||||
const { results } = await SearchHelper.searchForTeam(team, {
|
||||
const { results } = await provider.searchForTeam(team, {
|
||||
query: "test",
|
||||
});
|
||||
expect(results.length).toBe(0);
|
||||
@@ -148,7 +151,7 @@ describe("SearchHelper", () => {
|
||||
collectionId: collection.id,
|
||||
title: "test with backslash \\",
|
||||
});
|
||||
const { results } = await SearchHelper.searchForTeam(team, {
|
||||
const { results } = await provider.searchForTeam(team, {
|
||||
query: "test with backslash \\",
|
||||
});
|
||||
expect(results.length).toBe(1);
|
||||
@@ -170,7 +173,7 @@ describe("SearchHelper", () => {
|
||||
collectionId: collection.id,
|
||||
title: "test number 2",
|
||||
});
|
||||
const { total } = await SearchHelper.searchForTeam(team, {
|
||||
const { total } = await provider.searchForTeam(team, {
|
||||
query: "test",
|
||||
});
|
||||
expect(total).toBe(2);
|
||||
@@ -188,7 +191,7 @@ describe("SearchHelper", () => {
|
||||
});
|
||||
document.title = "change";
|
||||
await document.save();
|
||||
const { total } = await SearchHelper.searchForTeam(team, {
|
||||
const { total } = await provider.searchForTeam(team, {
|
||||
query: "test number",
|
||||
});
|
||||
expect(total).toBe(1);
|
||||
@@ -206,7 +209,7 @@ describe("SearchHelper", () => {
|
||||
});
|
||||
document.title = "change";
|
||||
await document.save();
|
||||
const { total } = await SearchHelper.searchForTeam(team, {
|
||||
const { total } = await provider.searchForTeam(team, {
|
||||
query: "title doesn't exist",
|
||||
});
|
||||
expect(total).toBe(0);
|
||||
@@ -234,7 +237,7 @@ describe("SearchHelper", () => {
|
||||
deletedAt: new Date(),
|
||||
title: "test",
|
||||
});
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
query: "test",
|
||||
});
|
||||
expect(results.length).toBe(1);
|
||||
@@ -263,7 +266,7 @@ describe("SearchHelper", () => {
|
||||
title: "document 2",
|
||||
}),
|
||||
]);
|
||||
const { results } = await SearchHelper.searchForUser(user);
|
||||
const { results } = await provider.searchForUser(user);
|
||||
expect(results.length).toBe(2);
|
||||
expect(results.map((r) => r.document.id).sort()).toEqual(
|
||||
documents.map((doc) => doc.id).sort()
|
||||
@@ -291,7 +294,7 @@ describe("SearchHelper", () => {
|
||||
title: "document 2",
|
||||
}),
|
||||
]);
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
collectionId: collection.id,
|
||||
});
|
||||
expect(results.length).toBe(2);
|
||||
@@ -339,7 +342,7 @@ describe("SearchHelper", () => {
|
||||
title: "document 2 in collection 2",
|
||||
}),
|
||||
]);
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
collectionId: collection1.id,
|
||||
});
|
||||
expect(results.length).toBe(2);
|
||||
@@ -351,7 +354,7 @@ describe("SearchHelper", () => {
|
||||
it("should handle no collections", async () => {
|
||||
const team = await buildTeam();
|
||||
const user = await buildUser({ teamId: team.id });
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
query: "test",
|
||||
});
|
||||
expect(results.length).toBe(0);
|
||||
@@ -381,7 +384,7 @@ describe("SearchHelper", () => {
|
||||
title: "test",
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
query: "test",
|
||||
statusFilter: [StatusFilter.Draft],
|
||||
});
|
||||
@@ -406,7 +409,7 @@ describe("SearchHelper", () => {
|
||||
permission: DocumentPermission.Read,
|
||||
});
|
||||
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
query: "test",
|
||||
statusFilter: [StatusFilter.Published, StatusFilter.Archived],
|
||||
});
|
||||
@@ -437,7 +440,7 @@ describe("SearchHelper", () => {
|
||||
title: "test",
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
query: "test",
|
||||
statusFilter: [StatusFilter.Published],
|
||||
});
|
||||
@@ -474,7 +477,7 @@ describe("SearchHelper", () => {
|
||||
title: "test",
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
query: "test",
|
||||
statusFilter: [StatusFilter.Archived],
|
||||
});
|
||||
@@ -502,7 +505,7 @@ describe("SearchHelper", () => {
|
||||
title: "test",
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
query: "test",
|
||||
statusFilter: [StatusFilter.Archived, StatusFilter.Published],
|
||||
});
|
||||
@@ -530,7 +533,7 @@ describe("SearchHelper", () => {
|
||||
title: "archived not draft",
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
query: "draft",
|
||||
statusFilter: [StatusFilter.Published, StatusFilter.Draft],
|
||||
});
|
||||
@@ -558,7 +561,7 @@ describe("SearchHelper", () => {
|
||||
title: "archived not draft",
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
query: "draft",
|
||||
statusFilter: [StatusFilter.Draft, StatusFilter.Archived],
|
||||
});
|
||||
@@ -584,7 +587,7 @@ describe("SearchHelper", () => {
|
||||
collectionId: collection.id,
|
||||
title: "test number 2",
|
||||
});
|
||||
const { total } = await SearchHelper.searchForUser(user, {
|
||||
const { total } = await provider.searchForUser(user, {
|
||||
query: "test",
|
||||
});
|
||||
expect(total).toBe(2);
|
||||
@@ -605,7 +608,7 @@ describe("SearchHelper", () => {
|
||||
});
|
||||
document.title = "change";
|
||||
await document.save();
|
||||
const { total } = await SearchHelper.searchForUser(user, {
|
||||
const { total } = await provider.searchForUser(user, {
|
||||
query: "test number",
|
||||
});
|
||||
expect(total).toBe(1);
|
||||
@@ -626,7 +629,7 @@ describe("SearchHelper", () => {
|
||||
});
|
||||
document.title = "change";
|
||||
await document.save();
|
||||
const { total } = await SearchHelper.searchForUser(user, {
|
||||
const { total } = await provider.searchForUser(user, {
|
||||
query: "title doesn't exist",
|
||||
});
|
||||
expect(total).toBe(0);
|
||||
@@ -647,7 +650,7 @@ describe("SearchHelper", () => {
|
||||
});
|
||||
document.title = "change";
|
||||
await document.save();
|
||||
const { total } = await SearchHelper.searchForUser(user, {
|
||||
const { total } = await provider.searchForUser(user, {
|
||||
query: `"test number"`,
|
||||
});
|
||||
expect(total).toBe(1);
|
||||
@@ -668,7 +671,7 @@ describe("SearchHelper", () => {
|
||||
});
|
||||
document.title = "change";
|
||||
await document.save();
|
||||
const { total } = await SearchHelper.searchForUser(user, {
|
||||
const { total } = await provider.searchForUser(user, {
|
||||
query: "env: ",
|
||||
});
|
||||
expect(total).toBe(1);
|
||||
@@ -681,7 +684,7 @@ describe("SearchHelper", () => {
|
||||
const collection = await buildCollection({
|
||||
userId: otherUser.id,
|
||||
teamId: team.id,
|
||||
permission: null, // private collection
|
||||
permission: null,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
userId: otherUser.id,
|
||||
@@ -690,7 +693,6 @@ describe("SearchHelper", () => {
|
||||
title: "group test document",
|
||||
});
|
||||
|
||||
// Document with no access should not appear in results
|
||||
await buildDocument({
|
||||
userId: otherUser.id,
|
||||
teamId: team.id,
|
||||
@@ -698,7 +700,6 @@ describe("SearchHelper", () => {
|
||||
title: "group test document 2",
|
||||
});
|
||||
|
||||
// Create a group and add the user to it
|
||||
const group = await buildGroup({
|
||||
teamId: team.id,
|
||||
});
|
||||
@@ -708,14 +709,13 @@ describe("SearchHelper", () => {
|
||||
},
|
||||
});
|
||||
|
||||
// Add group membership to the document
|
||||
await GroupMembership.create({
|
||||
createdById: otherUser.id,
|
||||
groupId: group.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
query: "group test",
|
||||
});
|
||||
|
||||
@@ -739,7 +739,7 @@ describe("SearchHelper", () => {
|
||||
collectionId: collection.id,
|
||||
title: "test",
|
||||
});
|
||||
const documents = await SearchHelper.searchTitlesForUser(user, {
|
||||
const documents = await provider.searchTitlesForUser(user, {
|
||||
query: "test",
|
||||
});
|
||||
expect(documents.length).toBe(1);
|
||||
@@ -774,7 +774,7 @@ describe("SearchHelper", () => {
|
||||
collectionId: collection1.id,
|
||||
title: "test",
|
||||
});
|
||||
const documents = await SearchHelper.searchTitlesForUser(user, {
|
||||
const documents = await provider.searchTitlesForUser(user, {
|
||||
query: "test",
|
||||
collectionId: collection.id,
|
||||
});
|
||||
@@ -785,7 +785,7 @@ describe("SearchHelper", () => {
|
||||
it("should handle no collections", async () => {
|
||||
const team = await buildTeam();
|
||||
const user = await buildUser({ teamId: team.id });
|
||||
const documents = await SearchHelper.searchTitlesForUser(user, {
|
||||
const documents = await provider.searchTitlesForUser(user, {
|
||||
query: "test",
|
||||
});
|
||||
expect(documents.length).toBe(0);
|
||||
@@ -815,7 +815,7 @@ describe("SearchHelper", () => {
|
||||
title: "test",
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const documents = await SearchHelper.searchTitlesForUser(user, {
|
||||
const documents = await provider.searchTitlesForUser(user, {
|
||||
query: "test",
|
||||
statusFilter: [StatusFilter.Draft],
|
||||
});
|
||||
@@ -846,7 +846,7 @@ describe("SearchHelper", () => {
|
||||
title: "test",
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const documents = await SearchHelper.searchTitlesForUser(user, {
|
||||
const documents = await provider.searchTitlesForUser(user, {
|
||||
query: "test",
|
||||
statusFilter: [StatusFilter.Published],
|
||||
});
|
||||
@@ -883,7 +883,7 @@ describe("SearchHelper", () => {
|
||||
title: "test",
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const documents = await SearchHelper.searchTitlesForUser(user, {
|
||||
const documents = await provider.searchTitlesForUser(user, {
|
||||
query: "test",
|
||||
statusFilter: [StatusFilter.Archived],
|
||||
});
|
||||
@@ -911,7 +911,7 @@ describe("SearchHelper", () => {
|
||||
title: "test",
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const documents = await SearchHelper.searchTitlesForUser(user, {
|
||||
const documents = await provider.searchTitlesForUser(user, {
|
||||
query: "test",
|
||||
statusFilter: [StatusFilter.Archived, StatusFilter.Published],
|
||||
});
|
||||
@@ -939,7 +939,7 @@ describe("SearchHelper", () => {
|
||||
title: "archived not draft",
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const documents = await SearchHelper.searchTitlesForUser(user, {
|
||||
const documents = await provider.searchTitlesForUser(user, {
|
||||
query: "draft",
|
||||
statusFilter: [StatusFilter.Published, StatusFilter.Draft],
|
||||
});
|
||||
@@ -967,7 +967,7 @@ describe("SearchHelper", () => {
|
||||
title: "archived not draft",
|
||||
archivedAt: new Date(),
|
||||
});
|
||||
const documents = await SearchHelper.searchTitlesForUser(user, {
|
||||
const documents = await provider.searchTitlesForUser(user, {
|
||||
query: "draft",
|
||||
statusFilter: [StatusFilter.Draft, StatusFilter.Archived],
|
||||
});
|
||||
@@ -981,7 +981,7 @@ describe("SearchHelper", () => {
|
||||
const collection = await buildCollection({
|
||||
userId: otherUser.id,
|
||||
teamId: team.id,
|
||||
permission: null, // private collection
|
||||
permission: null,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
userId: otherUser.id,
|
||||
@@ -990,7 +990,6 @@ describe("SearchHelper", () => {
|
||||
title: "group title test document",
|
||||
});
|
||||
|
||||
// Document with no access should not appear in results
|
||||
await buildDocument({
|
||||
userId: otherUser.id,
|
||||
teamId: team.id,
|
||||
@@ -998,7 +997,6 @@ describe("SearchHelper", () => {
|
||||
title: "group title test document 2",
|
||||
});
|
||||
|
||||
// Create a group and add the user to it
|
||||
const group = await buildGroup({
|
||||
teamId: team.id,
|
||||
});
|
||||
@@ -1008,14 +1006,13 @@ describe("SearchHelper", () => {
|
||||
},
|
||||
});
|
||||
|
||||
// Add group membership to the document
|
||||
await GroupMembership.create({
|
||||
createdById: otherUser.id,
|
||||
groupId: group.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
|
||||
const documents = await SearchHelper.searchTitlesForUser(user, {
|
||||
const documents = await provider.searchTitlesForUser(user, {
|
||||
query: "group title",
|
||||
});
|
||||
|
||||
@@ -1039,7 +1036,7 @@ describe("SearchHelper", () => {
|
||||
name: "Other Collection",
|
||||
});
|
||||
|
||||
const results = await SearchHelper.searchCollectionsForUser(user, {
|
||||
const results = await provider.searchCollectionsForUser(user, {
|
||||
query: "test",
|
||||
});
|
||||
|
||||
@@ -1061,7 +1058,7 @@ describe("SearchHelper", () => {
|
||||
name: "Beta",
|
||||
});
|
||||
|
||||
const results = await SearchHelper.searchCollectionsForUser(user);
|
||||
const results = await provider.searchCollectionsForUser(user);
|
||||
|
||||
expect(results.length).toBe(2);
|
||||
expect(results[0].id).toBe(collection1.id);
|
||||
@@ -1096,7 +1093,7 @@ describe("SearchHelper", () => {
|
||||
title: "Beta Document",
|
||||
});
|
||||
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
sort: SortFilter.Title,
|
||||
direction: DirectionFilter.ASC,
|
||||
});
|
||||
@@ -1133,7 +1130,7 @@ describe("SearchHelper", () => {
|
||||
title: "Beta Document",
|
||||
});
|
||||
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
sort: SortFilter.Title,
|
||||
direction: DirectionFilter.DESC,
|
||||
});
|
||||
@@ -1176,7 +1173,7 @@ describe("SearchHelper", () => {
|
||||
updatedAt: new Date("2023-12-01"),
|
||||
});
|
||||
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
sort: SortFilter.CreatedAt,
|
||||
direction: DirectionFilter.ASC,
|
||||
});
|
||||
@@ -1216,7 +1213,7 @@ describe("SearchHelper", () => {
|
||||
updatedAt: new Date("2023-06-01"),
|
||||
});
|
||||
|
||||
const { results } = await SearchHelper.searchForUser(user);
|
||||
const { results } = await provider.searchForUser(user);
|
||||
|
||||
expect(results.length).toBe(3);
|
||||
expect(results[0].document.id).toBe(doc2.id);
|
||||
@@ -1252,7 +1249,7 @@ describe("SearchHelper", () => {
|
||||
updatedAt: new Date("2023-01-01"),
|
||||
});
|
||||
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
query: "search",
|
||||
});
|
||||
|
||||
@@ -1288,7 +1285,7 @@ describe("SearchHelper", () => {
|
||||
updatedAt: new Date("2025-12-01"),
|
||||
});
|
||||
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await provider.searchForUser(user, {
|
||||
query: "search",
|
||||
sort: SortFilter.UpdatedAt,
|
||||
direction: DirectionFilter.DESC,
|
||||
@@ -1326,7 +1323,7 @@ describe("SearchHelper", () => {
|
||||
});
|
||||
|
||||
// Without popularity boost, pure relevance should win
|
||||
const { results: withoutBoost } = await SearchHelper.searchForTeam(team, {
|
||||
const { results: withoutBoost } = await provider.searchForTeam(team, {
|
||||
query: "testing",
|
||||
usePopularityBoost: false,
|
||||
});
|
||||
@@ -1335,7 +1332,7 @@ describe("SearchHelper", () => {
|
||||
expect(withoutBoost[0].document.id).toBe(relevantDoc.id);
|
||||
|
||||
// With popularity boost, the popular document may rank higher
|
||||
const { results: withBoost } = await SearchHelper.searchForTeam(team, {
|
||||
const { results: withBoost } = await provider.searchForTeam(team, {
|
||||
query: "testing",
|
||||
usePopularityBoost: true,
|
||||
});
|
||||
@@ -1350,22 +1347,28 @@ describe("SearchHelper", () => {
|
||||
|
||||
describe("webSearchQuery", () => {
|
||||
it("should correctly sanitize query", () => {
|
||||
expect(SearchHelper.webSearchQuery("one/two")).toBe("one/two:*");
|
||||
expect(SearchHelper.webSearchQuery("one\\two")).toBe("one\\\\two:*");
|
||||
expect(SearchHelper.webSearchQuery("test''")).toBe("test");
|
||||
expect(PostgresSearchProvider.webSearchQuery("one/two")).toBe(
|
||||
"one/two:*"
|
||||
);
|
||||
expect(PostgresSearchProvider.webSearchQuery("one\\two")).toBe(
|
||||
"one\\\\two:*"
|
||||
);
|
||||
expect(PostgresSearchProvider.webSearchQuery("test''")).toBe("test");
|
||||
});
|
||||
it("should wildcard unquoted queries", () => {
|
||||
expect(SearchHelper.webSearchQuery("test")).toBe("test:*");
|
||||
expect(SearchHelper.webSearchQuery("'")).toBe("");
|
||||
expect(SearchHelper.webSearchQuery("'quoted'")).toBe(`"quoted":*`);
|
||||
expect(PostgresSearchProvider.webSearchQuery("test")).toBe("test:*");
|
||||
expect(PostgresSearchProvider.webSearchQuery("'")).toBe("");
|
||||
expect(PostgresSearchProvider.webSearchQuery("'quoted'")).toBe(
|
||||
`"quoted":*`
|
||||
);
|
||||
});
|
||||
it("should wildcard multi-word queries", () => {
|
||||
expect(SearchHelper.webSearchQuery("this is a test")).toBe(
|
||||
expect(PostgresSearchProvider.webSearchQuery("this is a test")).toBe(
|
||||
"this&is&a&test:*"
|
||||
);
|
||||
});
|
||||
it("should not wildcard quoted queries", () => {
|
||||
expect(SearchHelper.webSearchQuery(`"this is a test"`)).toBe(
|
||||
expect(PostgresSearchProvider.webSearchQuery(`"this is a test"`)).toBe(
|
||||
`"this<->is<->a<->test"`
|
||||
);
|
||||
});
|
||||
+102
-84
@@ -11,63 +11,23 @@ import type {
|
||||
WhereOptions,
|
||||
} from "sequelize";
|
||||
import { Op, Sequelize } from "sequelize";
|
||||
import type { DateFilter } from "@shared/types";
|
||||
import { DirectionFilter, SortFilter } from "@shared/types";
|
||||
import { StatusFilter } from "@shared/types";
|
||||
import type { SearchableModel } from "@shared/types";
|
||||
import { DirectionFilter, SortFilter, StatusFilter } from "@shared/types";
|
||||
import { regexIndexOf, regexLastIndexOf } from "@shared/utils/string";
|
||||
import { getUrls } from "@shared/utils/urls";
|
||||
import { ValidationError } from "@server/errors";
|
||||
import Collection from "@server/models/Collection";
|
||||
import type Comment from "@server/models/Comment";
|
||||
import Document from "@server/models/Document";
|
||||
import type Share from "@server/models/Share";
|
||||
import Team from "@server/models/Team";
|
||||
import User from "@server/models/User";
|
||||
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
|
||||
import { sequelize } from "@server/storage/database";
|
||||
import { DocumentHelper } from "./DocumentHelper";
|
||||
|
||||
type SearchResponse = {
|
||||
results: {
|
||||
/** The search ranking, for sorting results */
|
||||
ranking: number;
|
||||
/** A snippet of contextual text around the search result */
|
||||
context?: string;
|
||||
/** The document result */
|
||||
document: Document;
|
||||
}[];
|
||||
/** The total number of results for the search query without pagination */
|
||||
total: number;
|
||||
};
|
||||
|
||||
type SearchOptions = {
|
||||
/** The query limit for pagination */
|
||||
limit?: number;
|
||||
/** The query offset for pagination */
|
||||
offset?: number;
|
||||
/** The text to search for */
|
||||
query?: string;
|
||||
/** Limit results to a collection. Authorization is presumed to have been done before passing to this helper. */
|
||||
collectionId?: string | null;
|
||||
/** Limit results to a shared document. */
|
||||
share?: Share;
|
||||
/** Limit results to a date range. */
|
||||
dateFilter?: DateFilter;
|
||||
/** Status of the documents to return */
|
||||
statusFilter?: StatusFilter[];
|
||||
/** Limit results to a list of documents. */
|
||||
documentIds?: string[];
|
||||
/** Limit results to a list of users that collaborated on the document. */
|
||||
collaboratorIds?: string[];
|
||||
/** The minimum number of words to be returned in the contextual snippet */
|
||||
snippetMinWords?: number;
|
||||
/** The maximum number of words to be returned in the contextual snippet */
|
||||
snippetMaxWords?: number;
|
||||
/** The field to sort results by */
|
||||
sort?: SortFilter;
|
||||
/** The sort direction */
|
||||
direction?: DirectionFilter;
|
||||
/** Whether to boost results by popularity score. Defaults to true. */
|
||||
usePopularityBoost?: boolean;
|
||||
};
|
||||
import type {
|
||||
SearchOptions,
|
||||
SearchResponse,
|
||||
} from "@server/utils/BaseSearchProvider";
|
||||
import { BaseSearchProvider } from "@server/utils/BaseSearchProvider";
|
||||
|
||||
type RankedDocument = Document & {
|
||||
id: string;
|
||||
@@ -76,24 +36,31 @@ type RankedDocument = Document & {
|
||||
};
|
||||
};
|
||||
|
||||
export default class SearchHelper {
|
||||
/**
|
||||
* Search provider that uses PostgreSQL full-text search via tsvector.
|
||||
* Indexing is handled by database triggers, so index/remove/updateMetadata
|
||||
* are no-ops.
|
||||
*/
|
||||
export default class PostgresSearchProvider extends BaseSearchProvider {
|
||||
id = "postgres";
|
||||
|
||||
/**
|
||||
* The maximum length of a search query.
|
||||
*/
|
||||
public static maxQueryLength = 1000;
|
||||
|
||||
/**
|
||||
* Cached regex pattern for single quotes to avoid recompilation
|
||||
* Cached regex pattern for single quotes to avoid recompilation.
|
||||
*/
|
||||
private static readonly SINGLE_QUOTE_REGEX = /'+/g;
|
||||
|
||||
/**
|
||||
* Cached regex pattern for quoted queries
|
||||
* Cached regex pattern for quoted queries.
|
||||
*/
|
||||
private static readonly QUOTED_QUERY_REGEX = /"([^"]*)"/g;
|
||||
|
||||
/**
|
||||
* Cached regex pattern for break characters
|
||||
* Cached regex pattern for break characters.
|
||||
*/
|
||||
private static readonly BREAK_CHARS_REGEX = new RegExp(
|
||||
`[ .,"'\n。!?!?…]`,
|
||||
@@ -101,7 +68,7 @@ export default class SearchHelper {
|
||||
);
|
||||
|
||||
/**
|
||||
* Cached stop words set for efficient lookup
|
||||
* Cached stop words set for efficient lookup.
|
||||
* Based on: https://github.com/postgres/postgres/blob/fc0d0ce978752493868496be6558fa17b7c4c3cf/src/backend/snowball/stopwords/english.stop
|
||||
*/
|
||||
private static readonly STOP_WORDS = new Set([
|
||||
@@ -215,13 +182,13 @@ export default class SearchHelper {
|
||||
"should",
|
||||
]);
|
||||
|
||||
public static async searchForTeam(
|
||||
async searchForTeam(
|
||||
team: Team,
|
||||
options: SearchOptions = {}
|
||||
): Promise<SearchResponse> {
|
||||
const { limit = 15, offset = 0, query } = options;
|
||||
|
||||
const where = await this.buildWhere(team, {
|
||||
const where = await PostgresSearchProvider.buildWhere(team, {
|
||||
...options,
|
||||
statusFilter: [...(options.statusFilter || []), StatusFilter.Published],
|
||||
});
|
||||
@@ -256,7 +223,7 @@ export default class SearchHelper {
|
||||
});
|
||||
}
|
||||
|
||||
const findOptions = this.buildFindOptions({
|
||||
const findOptions = PostgresSearchProvider.buildFindOptions({
|
||||
query,
|
||||
sort: options.sort,
|
||||
direction: options.direction,
|
||||
@@ -292,7 +259,7 @@ export default class SearchHelper {
|
||||
],
|
||||
});
|
||||
|
||||
return this.buildResponse({
|
||||
return PostgresSearchProvider.buildResponse({
|
||||
query,
|
||||
results,
|
||||
documents,
|
||||
@@ -306,12 +273,12 @@ export default class SearchHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static async searchTitlesForUser(
|
||||
async searchTitlesForUser(
|
||||
user: User,
|
||||
options: SearchOptions = {}
|
||||
): Promise<Document[]> {
|
||||
const { limit = 15, offset = 0, query, ...rest } = options;
|
||||
const where = await this.buildWhere(user, rest);
|
||||
const where = await PostgresSearchProvider.buildWhere(user, rest);
|
||||
|
||||
if (query) {
|
||||
where[Op.and].push({
|
||||
@@ -379,7 +346,7 @@ export default class SearchHelper {
|
||||
});
|
||||
}
|
||||
|
||||
public static async searchCollectionsForUser(
|
||||
async searchCollectionsForUser(
|
||||
user: User,
|
||||
options: SearchOptions = {}
|
||||
): Promise<Collection[]> {
|
||||
@@ -408,15 +375,15 @@ export default class SearchHelper {
|
||||
});
|
||||
}
|
||||
|
||||
public static async searchForUser(
|
||||
async searchForUser(
|
||||
user: User,
|
||||
options: SearchOptions = {}
|
||||
): Promise<SearchResponse> {
|
||||
const { limit = 15, offset = 0, query } = options;
|
||||
|
||||
const where = await this.buildWhere(user, options);
|
||||
const where = await PostgresSearchProvider.buildWhere(user, options);
|
||||
|
||||
const findOptions = this.buildFindOptions({
|
||||
const findOptions = PostgresSearchProvider.buildFindOptions({
|
||||
query,
|
||||
sort: options.sort,
|
||||
direction: options.direction,
|
||||
@@ -484,7 +451,7 @@ export default class SearchHelper {
|
||||
: countQuery,
|
||||
]);
|
||||
|
||||
return this.buildResponse({
|
||||
return PostgresSearchProvider.buildResponse({
|
||||
query,
|
||||
results,
|
||||
documents,
|
||||
@@ -498,6 +465,49 @@ export default class SearchHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* No-op for PostgreSQL — indexing is handled by database triggers.
|
||||
*
|
||||
* @param _model - unused.
|
||||
* @param _item - unused.
|
||||
*/
|
||||
async index(
|
||||
_model: SearchableModel,
|
||||
_item: Document | Collection | Comment
|
||||
): Promise<void> {
|
||||
// PostgreSQL uses tsvector triggers for indexing
|
||||
}
|
||||
|
||||
/**
|
||||
* No-op for PostgreSQL — removal is handled by database cascades.
|
||||
*
|
||||
* @param _model - unused.
|
||||
* @param _id - unused.
|
||||
* @param _teamId - unused.
|
||||
*/
|
||||
async remove(
|
||||
_model: SearchableModel,
|
||||
_id: string,
|
||||
_teamId: string
|
||||
): Promise<void> {
|
||||
// PostgreSQL handles removal via cascading deletes
|
||||
}
|
||||
|
||||
/**
|
||||
* No-op for PostgreSQL — metadata is stored in the same tables.
|
||||
*
|
||||
* @param _model - unused.
|
||||
* @param _id - unused.
|
||||
* @param _metadata - unused.
|
||||
*/
|
||||
async updateMetadata(
|
||||
_model: SearchableModel,
|
||||
_id: string,
|
||||
_metadata: Record<string, unknown>
|
||||
): Promise<void> {
|
||||
// PostgreSQL metadata lives in the same row as the document
|
||||
}
|
||||
|
||||
private static buildFindOptions({
|
||||
query,
|
||||
sort,
|
||||
@@ -519,7 +529,7 @@ export default class SearchHelper {
|
||||
: `ts_rank("searchVector", to_tsquery('english', :query))`;
|
||||
|
||||
attributes.push([Sequelize.literal(rankExpression), "searchRanking"]);
|
||||
replacements["query"] = this.webSearchQuery(query);
|
||||
replacements["query"] = PostgresSearchProvider.webSearchQuery(query);
|
||||
}
|
||||
|
||||
// When searching with a query and no explicit sort, prioritize search
|
||||
@@ -551,8 +561,10 @@ export default class SearchHelper {
|
||||
|
||||
private static buildResultContext(document: Document, query: string) {
|
||||
// Reset regex lastIndex to avoid state issues with global regex
|
||||
this.QUOTED_QUERY_REGEX.lastIndex = 0;
|
||||
const quotedQueries = Array.from(query.matchAll(this.QUOTED_QUERY_REGEX));
|
||||
PostgresSearchProvider.QUOTED_QUERY_REGEX.lastIndex = 0;
|
||||
const quotedQueries = Array.from(
|
||||
query.matchAll(PostgresSearchProvider.QUOTED_QUERY_REGEX)
|
||||
);
|
||||
const text = DocumentHelper.toPlainText(document);
|
||||
|
||||
// Regex to highlight quoted queries as ts_headline will not do this by default due to stemming.
|
||||
@@ -562,7 +574,7 @@ export default class SearchHelper {
|
||||
fullMatchRegex.source,
|
||||
...(quotedQueries.length
|
||||
? quotedQueries.map((match) => escapeRegExp(match[1]))
|
||||
: this.removeStopWords(query)
|
||||
: PostgresSearchProvider.removeStopWords(query)
|
||||
.trim()
|
||||
.split(" ")
|
||||
.map((match) => `\\b${escapeRegExp(match)}\\b`)),
|
||||
@@ -571,8 +583,8 @@ export default class SearchHelper {
|
||||
);
|
||||
|
||||
// Reset regex lastIndex to avoid state issues with global regex
|
||||
this.BREAK_CHARS_REGEX.lastIndex = 0;
|
||||
const breakCharsRegex = this.BREAK_CHARS_REGEX;
|
||||
PostgresSearchProvider.BREAK_CHARS_REGEX.lastIndex = 0;
|
||||
const breakCharsRegex = PostgresSearchProvider.BREAK_CHARS_REGEX;
|
||||
|
||||
// chop text around the first match, prefer the first full match if possible.
|
||||
const fullMatchIndex = text.search(fullMatchRegex);
|
||||
@@ -717,15 +729,17 @@ export default class SearchHelper {
|
||||
let likelyUrls = getUrls(options.query);
|
||||
|
||||
// remove likely urls, and escape the rest of the query.
|
||||
let limitedQuery = this.escapeQuery(
|
||||
let limitedQuery = PostgresSearchProvider.escapeQuery(
|
||||
likelyUrls
|
||||
.reduce((q, url) => q.replace(url, ""), options.query)
|
||||
.slice(0, this.maxQueryLength)
|
||||
.slice(0, PostgresSearchProvider.maxQueryLength)
|
||||
.trim()
|
||||
);
|
||||
|
||||
// Escape the URLs
|
||||
likelyUrls = likelyUrls.map((url) => this.escapeQuery(url));
|
||||
likelyUrls = likelyUrls.map((url) =>
|
||||
PostgresSearchProvider.escapeQuery(url)
|
||||
);
|
||||
|
||||
// Extract quoted queries and add them to the where clause, up to a maximum of 3 total.
|
||||
const quotedQueries = Array.from(limitedQuery.matchAll(/"([^"]*)"/g)).map(
|
||||
@@ -787,7 +801,9 @@ export default class SearchHelper {
|
||||
|
||||
return {
|
||||
ranking: result.dataValues.searchRanking,
|
||||
context: query ? this.buildResultContext(document, query) : undefined,
|
||||
context: query
|
||||
? PostgresSearchProvider.buildResultContext(document, query)
|
||||
: undefined,
|
||||
document,
|
||||
};
|
||||
}),
|
||||
@@ -796,22 +812,26 @@ export default class SearchHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a user search query into a format that can be used by Postgres
|
||||
* Convert a user search query into a format that can be used by Postgres.
|
||||
*
|
||||
* @param query The user search query
|
||||
* @returns The query formatted for Postgres ts_query
|
||||
* @param query - the user search query.
|
||||
* @returns the query formatted for Postgres ts_query.
|
||||
*/
|
||||
public static webSearchQuery(query: string): string {
|
||||
// limit length of search queries as we're using regex against untrusted input
|
||||
let limitedQuery = this.escapeQuery(query.slice(0, this.maxQueryLength));
|
||||
let limitedQuery = PostgresSearchProvider.escapeQuery(
|
||||
query.slice(0, PostgresSearchProvider.maxQueryLength)
|
||||
);
|
||||
|
||||
const quotedSearch =
|
||||
limitedQuery.startsWith('"') && limitedQuery.endsWith('"');
|
||||
|
||||
// Replace single quote characters with &.
|
||||
// Reset regex lastIndex to avoid state issues with global regex
|
||||
this.SINGLE_QUOTE_REGEX.lastIndex = 0;
|
||||
const singleQuotes = limitedQuery.matchAll(this.SINGLE_QUOTE_REGEX);
|
||||
PostgresSearchProvider.SINGLE_QUOTE_REGEX.lastIndex = 0;
|
||||
const singleQuotes = limitedQuery.matchAll(
|
||||
PostgresSearchProvider.SINGLE_QUOTE_REGEX
|
||||
);
|
||||
|
||||
for (const match of singleQuotes) {
|
||||
if (
|
||||
@@ -853,11 +873,9 @@ export default class SearchHelper {
|
||||
}
|
||||
|
||||
private static removeStopWords(query: string): string {
|
||||
// Based on:
|
||||
// https://github.com/postgres/postgres/blob/fc0d0ce978752493868496be6558fa17b7c4c3cf/src/backend/snowball/stopwords/english.stop
|
||||
return query
|
||||
.split(" ")
|
||||
.filter((word) => !this.STOP_WORDS.has(word))
|
||||
.filter((word) => !PostgresSearchProvider.STOP_WORDS.has(word))
|
||||
.join(" ");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { PluginManager, Hook } from "@server/utils/PluginManager";
|
||||
import config from "../plugin.json";
|
||||
import PostgresSearchProvider from "./PostgresSearchProvider";
|
||||
|
||||
const provider = new PostgresSearchProvider();
|
||||
|
||||
PluginManager.add([
|
||||
{
|
||||
...config,
|
||||
type: Hook.SearchProvider,
|
||||
value: provider,
|
||||
},
|
||||
]);
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
AuthenticationProvider,
|
||||
Comment,
|
||||
} from "@server/models";
|
||||
import SearchHelper from "@server/models/helpers/SearchHelper";
|
||||
import SearchProviderManager from "@server/utils/SearchProviderManager";
|
||||
import { can } from "@server/policies";
|
||||
import type { APIContext } from "@server/types";
|
||||
import { safeEqual } from "@server/utils/crypto";
|
||||
@@ -238,7 +238,7 @@ router.post(
|
||||
return;
|
||||
}
|
||||
|
||||
const { results, total } = await SearchHelper.searchForUser(user, options);
|
||||
const { results, total } = await SearchProviderManager.getProvider().searchForUser(user, options);
|
||||
|
||||
await SearchQuery.create({
|
||||
userId: user ? user.id : null,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Optional } from "utility-types";
|
||||
import { ProsemirrorHelper as SharedProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
||||
import { TextHelper } from "@shared/utils/TextHelper";
|
||||
import { Document, type Template } from "@server/models";
|
||||
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
|
||||
@@ -26,6 +25,8 @@ type Props = Optional<
|
||||
| "publishedAt"
|
||||
| "createdAt"
|
||||
| "updatedAt"
|
||||
| "createdById"
|
||||
| "lastModifiedById"
|
||||
>
|
||||
> & {
|
||||
state?: Buffer;
|
||||
@@ -59,6 +60,8 @@ export default async function documentCreator(
|
||||
editorVersion,
|
||||
publishedAt,
|
||||
sourceMetadata,
|
||||
createdById,
|
||||
lastModifiedById,
|
||||
}: Props
|
||||
): Promise<Document> {
|
||||
const { user } = ctx.state.auth;
|
||||
@@ -94,7 +97,7 @@ export default async function documentCreator(
|
||||
: text
|
||||
? ProsemirrorHelper.toProsemirror(text).toJSON()
|
||||
: template
|
||||
? SharedProsemirrorHelper.replaceTemplateVariables(
|
||||
? ProsemirrorHelper.replaceTemplateVariables(
|
||||
await DocumentHelper.toJSON(template),
|
||||
user
|
||||
)
|
||||
@@ -109,8 +112,8 @@ export default async function documentCreator(
|
||||
teamId: user.teamId,
|
||||
createdAt,
|
||||
updatedAt: updatedAt ?? createdAt,
|
||||
lastModifiedById: user.id,
|
||||
createdById: user.id,
|
||||
lastModifiedById: lastModifiedById ?? createdById ?? user.id,
|
||||
createdById: createdById ?? user.id,
|
||||
templateId,
|
||||
publishedAt,
|
||||
importId,
|
||||
|
||||
@@ -772,6 +772,14 @@ export class Environment {
|
||||
environment.ALLOWED_PRIVATE_IP_ADDRESSES
|
||||
);
|
||||
|
||||
/**
|
||||
* The search provider to use. Defaults to "postgres" which uses PostgreSQL
|
||||
* full-text search. Alternative providers can be registered via plugins.
|
||||
*/
|
||||
@IsOptional()
|
||||
public SEARCH_PROVIDER =
|
||||
this.toOptionalString(environment.SEARCH_PROVIDER) ?? "postgres";
|
||||
|
||||
/**
|
||||
* The product name
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { randomString } from "@shared/random";
|
||||
import { Scope } from "@shared/types";
|
||||
import { buildApiKey } from "@server/test/factories";
|
||||
import ApiKey from "./ApiKey";
|
||||
|
||||
@@ -110,5 +111,23 @@ describe("#ApiKey", () => {
|
||||
expect(apiKey.canAccess("/api/documents.create")).toBe(false);
|
||||
expect(apiKey.canAccess("/api/collections.create")).toBe(false);
|
||||
});
|
||||
|
||||
it("should allow MCP access for scoped API keys", async () => {
|
||||
const apiKey = await buildApiKey({
|
||||
name: "Dev",
|
||||
scope: [Scope.Read],
|
||||
});
|
||||
|
||||
expect(apiKey.canAccess("/mcp")).toBe(true);
|
||||
expect(apiKey.canAccess("/mcp/")).toBe(true);
|
||||
});
|
||||
|
||||
it("should allow MCP access for unscoped API keys", async () => {
|
||||
const apiKey = await buildApiKey({
|
||||
name: "Dev",
|
||||
});
|
||||
|
||||
expect(apiKey.canAccess("/mcp")).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -176,6 +176,12 @@ class ApiKey extends ParanoidModel<
|
||||
return true;
|
||||
}
|
||||
|
||||
// MCP endpoint access is allowed if the key has any valid scope.
|
||||
// Fine-grained scope enforcement happens at the tool level.
|
||||
if (path.startsWith("/mcp")) {
|
||||
return this.scope.length > 0;
|
||||
}
|
||||
|
||||
return AuthenticationHelper.canAccess(path, this.scope);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { MentionType } from "@shared/types";
|
||||
import { buildComment, buildDocument, buildUser } from "@server/test/factories";
|
||||
import Comment from "./Comment";
|
||||
|
||||
describe("Comment", () => {
|
||||
describe("toPlainText", () => {
|
||||
it("should convert simple text to plain text", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const comment = await buildComment({
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
|
||||
const text = comment.toPlainText();
|
||||
expect(text).toBe("test");
|
||||
});
|
||||
|
||||
it("should convert comment with mention to plain text", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const comment = await Comment.create({
|
||||
documentId: document.id,
|
||||
createdById: user.id,
|
||||
data: {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "Hello ",
|
||||
},
|
||||
{
|
||||
type: "mention",
|
||||
attrs: {
|
||||
type: MentionType.User,
|
||||
label: "Jane",
|
||||
modelId: uuidv4(),
|
||||
id: uuidv4(),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const text = comment.toPlainText();
|
||||
expect(text).toBe("Hello @Jane");
|
||||
});
|
||||
|
||||
it("should convert comment with document mention to plain text", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const comment = await Comment.create({
|
||||
documentId: document.id,
|
||||
createdById: user.id,
|
||||
data: {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "See ",
|
||||
},
|
||||
{
|
||||
type: "mention",
|
||||
attrs: {
|
||||
type: MentionType.Document,
|
||||
label: "My Document",
|
||||
modelId: uuidv4(),
|
||||
id: uuidv4(),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const text = comment.toPlainText();
|
||||
expect(text).toBe("See My Document");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolve", () => {
|
||||
it("should resolve the comment", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const comment = await buildComment({
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
|
||||
comment.resolve(user);
|
||||
|
||||
expect(comment.isResolved).toBe(true);
|
||||
expect(comment.resolvedById).toBe(user.id);
|
||||
expect(comment.resolvedAt).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should throw if already resolved", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const comment = await buildComment({
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
|
||||
comment.resolve(user);
|
||||
|
||||
expect(() => comment.resolve(user)).toThrow();
|
||||
});
|
||||
|
||||
it("should throw if comment is a reply", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const parent = await buildComment({
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
const reply = await buildComment({
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
parentCommentId: parent.id,
|
||||
});
|
||||
|
||||
expect(() => reply.resolve(user)).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("unresolve", () => {
|
||||
it("should unresolve the comment", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const comment = await buildComment({
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
|
||||
comment.resolve(user);
|
||||
comment.unresolve();
|
||||
|
||||
expect(comment.isResolved).toBe(false);
|
||||
expect(comment.resolvedById).toBeNull();
|
||||
expect(comment.resolvedAt).toBeNull();
|
||||
});
|
||||
|
||||
it("should throw if not resolved", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const comment = await buildComment({
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
|
||||
expect(() => comment.unresolve()).toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
import type { ProsemirrorData, ReactionSummary } from "@shared/types";
|
||||
import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
||||
import { CommentValidation } from "@shared/validations";
|
||||
import { basicSchema } from "@server/editor";
|
||||
import { commentSchema } from "@server/editor";
|
||||
import { ValidationError } from "@server/errors";
|
||||
import Document from "./Document";
|
||||
import User from "./User";
|
||||
@@ -137,7 +137,7 @@ class Comment extends ParanoidModel<
|
||||
* @returns The plain text representation of the comment data
|
||||
*/
|
||||
public toPlainText() {
|
||||
const node = Node.fromJSON(basicSchema, this.data);
|
||||
const node = Node.fromJSON(commentSchema, this.data);
|
||||
return ProsemirrorHelper.toPlainText(node);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { buildTeam, buildCollection } from "@server/test/factories";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { buildTeam, buildCollection, buildAttachment } from "@server/test/factories";
|
||||
|
||||
describe("Team", () => {
|
||||
describe("collectionIds", () => {
|
||||
@@ -40,4 +41,52 @@ describe("Team", () => {
|
||||
expect(team.previousSubdomains?.[1]).toEqual(subdomain);
|
||||
});
|
||||
});
|
||||
|
||||
describe("publicAvatarUrl", () => {
|
||||
it("should return null when no avatarUrl is set", async () => {
|
||||
const team = await buildTeam({ avatarUrl: null });
|
||||
const result = await team.publicAvatarUrl();
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("should return external URL unchanged", async () => {
|
||||
const url = "https://example.com/logo.png";
|
||||
const team = await buildTeam({ avatarUrl: url });
|
||||
const result = await team.publicAvatarUrl();
|
||||
expect(result).toEqual(url);
|
||||
});
|
||||
|
||||
it("should return signed URL for private-bucket attachment redirect", async () => {
|
||||
const team = await buildTeam();
|
||||
const attachment = await buildAttachment({
|
||||
teamId: team.id,
|
||||
acl: "private",
|
||||
});
|
||||
|
||||
await team.update({
|
||||
avatarUrl: `/api/attachments.redirect?id=${attachment.id}`,
|
||||
});
|
||||
|
||||
const result = await team.publicAvatarUrl();
|
||||
expect(result).toEqual(await attachment.signedUrl);
|
||||
});
|
||||
|
||||
it("should return canonical URL for public-bucket attachment redirect", async () => {
|
||||
const team = await buildTeam();
|
||||
const id = randomUUID();
|
||||
const attachment = await buildAttachment({
|
||||
id,
|
||||
teamId: team.id,
|
||||
key: `avatars/${team.id}/${id}/logo.png`,
|
||||
acl: "public-read",
|
||||
});
|
||||
|
||||
await team.update({
|
||||
avatarUrl: `/api/attachments.redirect?id=${attachment.id}`,
|
||||
});
|
||||
|
||||
const result = await team.publicAvatarUrl();
|
||||
expect(result).toEqual(attachment.canonicalUrl);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -29,6 +29,7 @@ import { TeamPreferenceDefaults } from "@shared/constants";
|
||||
import type { TeamPreferences } from "@shared/types";
|
||||
import { TeamPreference, UserRole } from "@shared/types";
|
||||
import { getBaseDomain, RESERVED_SUBDOMAINS } from "@shared/utils/domains";
|
||||
import { attachmentRedirectRegex } from "@shared/utils/ProsemirrorHelper";
|
||||
import { parseEmail } from "@shared/utils/email";
|
||||
import { TeamValidation } from "@shared/validations";
|
||||
import env from "@server/env";
|
||||
@@ -57,6 +58,8 @@ export enum TeamFlag {
|
||||
MarkedSafe = "markedSafe",
|
||||
}
|
||||
|
||||
const avatarRedirectPattern = new RegExp(attachmentRedirectRegex.source, "i");
|
||||
|
||||
@Scopes(() => ({
|
||||
withDomains: {
|
||||
include: [{ model: TeamDomain }],
|
||||
@@ -145,6 +148,37 @@ class Team extends ParanoidModel<
|
||||
this.setDataValue("avatarUrl", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a directly-accessible URL for the team's avatar suitable for use
|
||||
* in contexts without authentication. Attachment is loaded and a signed (or
|
||||
* canonical) URL is returned; any other URL is returned unchanged.
|
||||
*
|
||||
* @returns A promise resolving to a direct URL, or null when no avatar is set.
|
||||
*/
|
||||
async publicAvatarUrl(): Promise<string | null> {
|
||||
const url = this.avatarUrl;
|
||||
if (!url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const match = avatarRedirectPattern.exec(url);
|
||||
if (!match?.groups?.id) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const attachment = await Attachment.findOne({
|
||||
where: { id: match.groups.id, teamId: this.id },
|
||||
});
|
||||
|
||||
if (!attachment) {
|
||||
return url;
|
||||
}
|
||||
|
||||
return attachment.isStoredInPublicBucket
|
||||
? attachment.canonicalUrl
|
||||
: await attachment.signedUrl;
|
||||
}
|
||||
|
||||
@Default(true)
|
||||
@Column
|
||||
sharing: boolean;
|
||||
|
||||
@@ -2,7 +2,6 @@ import { faker } from "@faker-js/faker";
|
||||
import type { DeepPartial } from "utility-types";
|
||||
import type { ProsemirrorData } from "@shared/types";
|
||||
import { MentionType } from "@shared/types";
|
||||
import { ProsemirrorHelper as SharedProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
||||
import { createContext } from "@server/context";
|
||||
import { buildProseMirrorDoc, buildUser } from "@server/test/factories";
|
||||
import type { MentionAttrs } from "./ProsemirrorHelper";
|
||||
@@ -973,7 +972,7 @@ describe("ProsemirrorHelper", () => {
|
||||
},
|
||||
]);
|
||||
|
||||
const images = SharedProsemirrorHelper.getImages(doc);
|
||||
const images = ProsemirrorHelper.getImages(doc);
|
||||
expect(images.length).toBe(1);
|
||||
expect(images[0].attrs.src).toBe("https://example.com/image.png");
|
||||
expect(images[0].attrs.alt).toBe("Test image");
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
attachmentRedirectRegex,
|
||||
ProsemirrorHelper as SharedProsemirrorHelper,
|
||||
} from "@shared/utils/ProsemirrorHelper";
|
||||
|
||||
import parseDocumentSlug from "@shared/utils/parseDocumentSlug";
|
||||
import { isRTL } from "@shared/utils/rtl";
|
||||
import { isInternalUrl } from "@shared/utils/urls";
|
||||
@@ -62,7 +63,7 @@ export type MentionAttrs = {
|
||||
};
|
||||
|
||||
@trace()
|
||||
export class ProsemirrorHelper {
|
||||
export class ProsemirrorHelper extends SharedProsemirrorHelper {
|
||||
/**
|
||||
* Returns the input text as a Y.Doc.
|
||||
*
|
||||
@@ -255,33 +256,6 @@ export class ProsemirrorHelper {
|
||||
return blockNode ? doc.copy(Fragment.fromArray([blockNode])) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all marks from the node that match the given types.
|
||||
*
|
||||
* @param data The ProsemirrorData object to remove marks from
|
||||
* @param marks The mark types to remove
|
||||
* @returns The content with marks removed
|
||||
*/
|
||||
static removeMarks(doc: Node | ProsemirrorData, marks: string[]) {
|
||||
const json = "toJSON" in doc ? (doc.toJSON() as ProsemirrorData) : doc;
|
||||
|
||||
function removeMarksInner(node: ProsemirrorData) {
|
||||
if (node.marks) {
|
||||
node.marks = node.marks.filter((mark) => !marks.includes(mark.type));
|
||||
}
|
||||
if (node.attrs?.marks) {
|
||||
node.attrs.marks = (node.attrs.marks as { type: string }[])?.filter(
|
||||
(mark) => !marks.includes(mark.type)
|
||||
);
|
||||
}
|
||||
if (node.content) {
|
||||
node.content.forEach(removeMarksInner);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
return removeMarksInner(json);
|
||||
}
|
||||
|
||||
static async replaceInternalUrls(
|
||||
doc: Node | ProsemirrorData,
|
||||
basePath: string
|
||||
@@ -875,8 +849,8 @@ export class ProsemirrorHelper {
|
||||
doc: Node,
|
||||
user: User
|
||||
): Promise<Node> {
|
||||
const images = SharedProsemirrorHelper.getImages(doc);
|
||||
const videos = SharedProsemirrorHelper.getVideos(doc);
|
||||
const images = ProsemirrorHelper.getImages(doc);
|
||||
const videos = ProsemirrorHelper.getVideos(doc);
|
||||
const nodes = [...images, ...videos];
|
||||
|
||||
if (!nodes.length) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { ProsemirrorHelper as SharedProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
||||
import { createContext } from "@server/context";
|
||||
import { buildProseMirrorDoc, buildUser } from "@server/test/factories";
|
||||
import { ProsemirrorHelper } from "./ProsemirrorHelper";
|
||||
@@ -43,7 +42,7 @@ describe("ProsemirrorHelper", () => {
|
||||
},
|
||||
]);
|
||||
|
||||
const images = SharedProsemirrorHelper.getImages(doc);
|
||||
const images = ProsemirrorHelper.getImages(doc);
|
||||
expect(images.length).toBe(1);
|
||||
expect(images[0].attrs.src).toBe("https://example.com/image.png");
|
||||
expect(images[0].attrs.alt).toBe("Test image");
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { Scope } from "@shared/types";
|
||||
import { buildOAuthAuthentication, buildUser } from "@server/test/factories";
|
||||
|
||||
describe("OAuthAuthentication", () => {
|
||||
describe("canAccess", () => {
|
||||
it("should allow MCP access for scoped tokens", async () => {
|
||||
const user = await buildUser();
|
||||
const authentication = await buildOAuthAuthentication({
|
||||
user,
|
||||
scope: [Scope.Read],
|
||||
});
|
||||
|
||||
expect(authentication.canAccess("/mcp")).toBe(true);
|
||||
expect(authentication.canAccess("/mcp/")).toBe(true);
|
||||
});
|
||||
|
||||
it("should deny MCP access for tokens with empty scope", async () => {
|
||||
const user = await buildUser();
|
||||
const authentication = await buildOAuthAuthentication({
|
||||
user,
|
||||
scope: [],
|
||||
});
|
||||
|
||||
expect(authentication.canAccess("/mcp")).toBe(false);
|
||||
});
|
||||
|
||||
it("should always allow the revoke endpoint", async () => {
|
||||
const user = await buildUser();
|
||||
const authentication = await buildOAuthAuthentication({
|
||||
user,
|
||||
scope: [Scope.Read],
|
||||
});
|
||||
|
||||
expect(authentication.canAccess("/oauth/revoke")).toBe(true);
|
||||
});
|
||||
|
||||
it("should check scopes for API paths", async () => {
|
||||
const user = await buildUser();
|
||||
const authentication = await buildOAuthAuthentication({
|
||||
user,
|
||||
scope: [Scope.Read],
|
||||
});
|
||||
|
||||
expect(authentication.canAccess("/api/documents.list")).toBe(true);
|
||||
expect(authentication.canAccess("/api/documents.update")).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,7 @@
|
||||
import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
||||
import {
|
||||
ProsemirrorHelper,
|
||||
type CommentMark,
|
||||
} from "@shared/utils/ProsemirrorHelper";
|
||||
import type { Comment } from "@server/models";
|
||||
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
|
||||
import presentUser from "./user";
|
||||
@@ -6,22 +9,23 @@ import presentUser from "./user";
|
||||
type Options = {
|
||||
/** Whether to include anchor text, if it exists */
|
||||
includeAnchorText?: boolean;
|
||||
/** Precomputed comment marks to avoid reparsing the document. */
|
||||
commentMarks?: CommentMark[];
|
||||
};
|
||||
|
||||
export default function present(
|
||||
comment: Comment,
|
||||
{ includeAnchorText }: Options = {}
|
||||
{ includeAnchorText, commentMarks }: Options = {}
|
||||
) {
|
||||
let anchorText: string | undefined;
|
||||
|
||||
if (includeAnchorText && comment.document) {
|
||||
const commentMarks = ProsemirrorHelper.getComments(
|
||||
DocumentHelper.toProsemirror(comment.document)
|
||||
);
|
||||
anchorText = ProsemirrorHelper.getAnchorTextForComment(
|
||||
commentMarks,
|
||||
comment.id
|
||||
);
|
||||
const marks =
|
||||
commentMarks ??
|
||||
ProsemirrorHelper.getComments(
|
||||
DocumentHelper.toProsemirror(comment.document)
|
||||
);
|
||||
anchorText = ProsemirrorHelper.getAnchorTextForComment(marks, comment.id);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -16,7 +16,7 @@ describe("DocumentArchivedProcessor", () => {
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
|
||||
|
||||
// Verify the star exists
|
||||
expect(
|
||||
await Star.count({
|
||||
@@ -56,7 +56,7 @@ describe("DocumentArchivedProcessor", () => {
|
||||
teamId: actor.teamId,
|
||||
userId: actor.id,
|
||||
});
|
||||
|
||||
|
||||
// Create stars for both users
|
||||
await buildStar({
|
||||
userId: actor.id,
|
||||
@@ -95,7 +95,7 @@ describe("DocumentArchivedProcessor", () => {
|
||||
},
|
||||
})
|
||||
).toBe(0);
|
||||
|
||||
|
||||
// Verify the other user's star still exists
|
||||
expect(
|
||||
await Star.count({
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import { SearchableModel } from "@shared/types";
|
||||
import {
|
||||
buildDocument,
|
||||
buildCollection,
|
||||
buildUser,
|
||||
} from "@server/test/factories";
|
||||
import SearchProviderManager from "@server/utils/SearchProviderManager";
|
||||
import SearchIndexProcessor from "./SearchIndexProcessor";
|
||||
|
||||
const processor = new SearchIndexProcessor();
|
||||
|
||||
describe("SearchIndexProcessor", () => {
|
||||
it("should have the expected applicable events", () => {
|
||||
expect(SearchIndexProcessor.applicableEvents).toContain(
|
||||
"documents.publish"
|
||||
);
|
||||
expect(SearchIndexProcessor.applicableEvents).toContain(
|
||||
"documents.update.delayed"
|
||||
);
|
||||
expect(SearchIndexProcessor.applicableEvents).toContain(
|
||||
"documents.permanent_delete"
|
||||
);
|
||||
expect(SearchIndexProcessor.applicableEvents).toContain(
|
||||
"collections.create"
|
||||
);
|
||||
expect(SearchIndexProcessor.applicableEvents).toContain("comments.create");
|
||||
expect(SearchIndexProcessor.applicableEvents).toContain("comments.delete");
|
||||
});
|
||||
|
||||
it("should call provider.index for documents.publish", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
teamId: user.teamId,
|
||||
collectionId: collection.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
const provider = SearchProviderManager.getProvider();
|
||||
const indexSpy = jest.spyOn(provider, "index");
|
||||
|
||||
await processor.perform({
|
||||
name: "documents.publish",
|
||||
documentId: document.id,
|
||||
collectionId: collection.id,
|
||||
teamId: user.teamId,
|
||||
actorId: user.id,
|
||||
} as any);
|
||||
|
||||
expect(indexSpy).toHaveBeenCalledWith(
|
||||
SearchableModel.Document,
|
||||
expect.objectContaining({ id: document.id })
|
||||
);
|
||||
|
||||
indexSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("should call provider.remove for documents.permanent_delete", async () => {
|
||||
const user = await buildUser();
|
||||
const provider = SearchProviderManager.getProvider();
|
||||
const removeSpy = jest.spyOn(provider, "remove");
|
||||
|
||||
await processor.perform({
|
||||
name: "documents.permanent_delete",
|
||||
documentId: "deleted-doc-id",
|
||||
collectionId: "some-collection-id",
|
||||
teamId: user.teamId,
|
||||
actorId: user.id,
|
||||
} as any);
|
||||
|
||||
expect(removeSpy).toHaveBeenCalledWith(
|
||||
SearchableModel.Document,
|
||||
"deleted-doc-id",
|
||||
user.teamId
|
||||
);
|
||||
|
||||
removeSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,139 @@
|
||||
import { SearchableModel } from "@shared/types";
|
||||
import { Document, Collection, Comment } from "@server/models";
|
||||
import BaseProcessor from "@server/queues/processors/BaseProcessor";
|
||||
import type {
|
||||
DocumentEvent,
|
||||
DocumentMovedEvent,
|
||||
CollectionEvent,
|
||||
CommentEvent,
|
||||
CommentUpdateEvent,
|
||||
Event,
|
||||
} from "@server/types";
|
||||
import SearchProviderManager from "@server/utils/SearchProviderManager";
|
||||
|
||||
/**
|
||||
* Processor that keeps the search index in sync with data changes.
|
||||
* For PostgreSQL this is largely a no-op since tsvector triggers handle
|
||||
* indexing, but external providers (Elasticsearch, etc.) rely on these
|
||||
* events to maintain their indexes.
|
||||
*/
|
||||
export default class SearchIndexProcessor extends BaseProcessor {
|
||||
static applicableEvents: Event["name"][] = [
|
||||
"documents.publish",
|
||||
"documents.update.delayed",
|
||||
"documents.archive",
|
||||
"documents.unarchive",
|
||||
"documents.delete",
|
||||
"documents.permanent_delete",
|
||||
"documents.move",
|
||||
"collections.create",
|
||||
"collections.update",
|
||||
"collections.delete",
|
||||
"comments.create",
|
||||
"comments.update",
|
||||
"comments.delete",
|
||||
];
|
||||
|
||||
async perform(
|
||||
event: DocumentEvent | DocumentMovedEvent | CollectionEvent | CommentEvent
|
||||
): Promise<void> {
|
||||
const provider = SearchProviderManager.getProvider();
|
||||
|
||||
// When using the built-in Postgres search provider, tsvector triggers
|
||||
// handle indexing directly and the provider methods are effectively no-ops for now.
|
||||
if (process.env.SEARCH_PROVIDER === "postgres") {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.name) {
|
||||
case "documents.publish":
|
||||
case "documents.update.delayed":
|
||||
case "documents.unarchive": {
|
||||
const document = await Document.findByPk(
|
||||
(event as DocumentEvent).documentId
|
||||
);
|
||||
if (document) {
|
||||
await provider.index(SearchableModel.Document, document);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "documents.archive":
|
||||
case "documents.delete": {
|
||||
const document = await Document.findByPk(
|
||||
(event as DocumentEvent).documentId,
|
||||
{ paranoid: false }
|
||||
);
|
||||
if (document) {
|
||||
await provider.updateMetadata(SearchableModel.Document, document.id, {
|
||||
archivedAt: document.archivedAt,
|
||||
deletedAt: document.deletedAt,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "documents.permanent_delete": {
|
||||
await provider.remove(
|
||||
SearchableModel.Document,
|
||||
(event as DocumentEvent).documentId,
|
||||
event.teamId
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case "documents.move": {
|
||||
const movedEvent = event as DocumentMovedEvent;
|
||||
for (const documentId of movedEvent.data.documentIds) {
|
||||
await provider.updateMetadata(SearchableModel.Document, documentId, {
|
||||
collectionId: movedEvent.collectionId,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "collections.create":
|
||||
case "collections.update": {
|
||||
const collection = await Collection.findByPk(
|
||||
(event as CollectionEvent).collectionId
|
||||
);
|
||||
if (collection) {
|
||||
await provider.index(SearchableModel.Collection, collection);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "collections.delete": {
|
||||
await provider.remove(
|
||||
SearchableModel.Collection,
|
||||
(event as CollectionEvent).collectionId,
|
||||
event.teamId
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case "comments.create":
|
||||
case "comments.update": {
|
||||
const comment = await Comment.findByPk(
|
||||
(event as CommentEvent | CommentUpdateEvent).modelId
|
||||
);
|
||||
if (comment) {
|
||||
await provider.index(SearchableModel.Comment, comment);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "comments.delete": {
|
||||
await provider.remove(
|
||||
SearchableModel.Comment,
|
||||
(event as CommentEvent).modelId,
|
||||
event.teamId
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import type {
|
||||
ProsemirrorDoc,
|
||||
} from "@shared/types";
|
||||
import { AttachmentPreset, ImportState, ImportTaskState } from "@shared/types";
|
||||
import { ProsemirrorHelper as SharedProseMirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
||||
import { createContext } from "@server/context";
|
||||
import { schema } from "@server/editor";
|
||||
import Logger from "@server/logging/Logger";
|
||||
@@ -262,9 +261,9 @@ export default abstract class APIImportTask<
|
||||
}): Promise<ProsemirrorDoc> {
|
||||
const docNode = ProsemirrorHelper.toProsemirror(doc);
|
||||
const nodes = [
|
||||
...SharedProseMirrorHelper.getImages(docNode),
|
||||
...SharedProseMirrorHelper.getVideos(docNode),
|
||||
...SharedProseMirrorHelper.getAttachments(docNode),
|
||||
...ProsemirrorHelper.getImages(docNode),
|
||||
...ProsemirrorHelper.getVideos(docNode),
|
||||
...ProsemirrorHelper.getAttachments(docNode),
|
||||
];
|
||||
|
||||
if (!nodes.length) {
|
||||
|
||||
@@ -1,37 +1,155 @@
|
||||
import path from "node:path";
|
||||
import { FileOperation } from "@server/models";
|
||||
import { buildFileOperation } from "@server/test/factories";
|
||||
import { FileOperation, User } from "@server/models";
|
||||
import {
|
||||
buildFileOperation,
|
||||
buildUser,
|
||||
buildTeam,
|
||||
buildAdmin,
|
||||
} from "@server/test/factories";
|
||||
import ImportJSONTask from "./ImportJSONTask";
|
||||
|
||||
// The fixture has these values for both documents:
|
||||
// createdById: "ccec260a-e060-4925-ade8-17cfabaf2cac"
|
||||
// createdByEmail: "hmac.devo@gmail.com"
|
||||
const fixtureCreatedById = "ccec260a-e060-4925-ade8-17cfabaf2cac";
|
||||
const fixtureCreatedByEmail = "hmac.devo@gmail.com";
|
||||
|
||||
const fixturePath = path.resolve(
|
||||
__dirname,
|
||||
"..",
|
||||
"..",
|
||||
"test",
|
||||
"fixtures",
|
||||
"outline-json.zip"
|
||||
);
|
||||
|
||||
function mockHandle(fileOperation: FileOperation) {
|
||||
Object.defineProperty(fileOperation, "handle", {
|
||||
get() {
|
||||
return {
|
||||
path: fixturePath,
|
||||
cleanup: async () => {},
|
||||
};
|
||||
},
|
||||
});
|
||||
jest.spyOn(FileOperation, "findByPk").mockResolvedValue(fileOperation);
|
||||
}
|
||||
|
||||
describe("ImportJSONTask", () => {
|
||||
it("should import the documents, attachments", async () => {
|
||||
const fileOperation = await buildFileOperation();
|
||||
Object.defineProperty(fileOperation, "handle", {
|
||||
get() {
|
||||
return {
|
||||
path: path.resolve(
|
||||
__dirname,
|
||||
"..",
|
||||
"..",
|
||||
"test",
|
||||
"fixtures",
|
||||
"outline-json.zip"
|
||||
),
|
||||
cleanup: async () => {},
|
||||
};
|
||||
},
|
||||
});
|
||||
jest.spyOn(FileOperation, "findByPk").mockResolvedValue(fileOperation);
|
||||
|
||||
const props = {
|
||||
fileOperationId: fileOperation.id,
|
||||
};
|
||||
mockHandle(fileOperation);
|
||||
|
||||
const task = new ImportJSONTask();
|
||||
const response = await task.perform(props);
|
||||
const response = await task.perform({
|
||||
fileOperationId: fileOperation.id,
|
||||
});
|
||||
|
||||
expect(response.collections.size).toEqual(1);
|
||||
expect(response.documents.size).toEqual(2);
|
||||
expect(response.attachments.size).toEqual(1);
|
||||
});
|
||||
|
||||
describe("user mapping", () => {
|
||||
it("should map createdById to an existing user by ID", async () => {
|
||||
// Ensure a user exists with the fixture's createdById, handling the
|
||||
// case where it may already exist from a prior test run.
|
||||
let originalAuthor = await User.findByPk(fixtureCreatedById);
|
||||
const teamId = originalAuthor?.teamId ?? (await buildTeam()).id;
|
||||
|
||||
if (!originalAuthor) {
|
||||
originalAuthor = await buildUser({
|
||||
id: fixtureCreatedById,
|
||||
teamId,
|
||||
});
|
||||
}
|
||||
|
||||
const admin = await buildAdmin({ teamId });
|
||||
const fileOperation = await buildFileOperation({
|
||||
userId: admin.id,
|
||||
teamId,
|
||||
});
|
||||
mockHandle(fileOperation);
|
||||
|
||||
const task = new ImportJSONTask();
|
||||
const response = await task.perform({
|
||||
fileOperationId: fileOperation.id,
|
||||
});
|
||||
|
||||
for (const document of response.documents.values()) {
|
||||
expect(document.createdById).toEqual(originalAuthor.id);
|
||||
expect(document.lastModifiedById).toEqual(originalAuthor.id);
|
||||
}
|
||||
});
|
||||
|
||||
it("should fall back to email matching when ID does not match", async () => {
|
||||
const team = await buildTeam();
|
||||
// User has matching email but a different ID
|
||||
const originalAuthor = await buildUser({
|
||||
teamId: team.id,
|
||||
email: fixtureCreatedByEmail,
|
||||
});
|
||||
const admin = await buildAdmin({ teamId: team.id });
|
||||
const fileOperation = await buildFileOperation({
|
||||
userId: admin.id,
|
||||
teamId: team.id,
|
||||
});
|
||||
mockHandle(fileOperation);
|
||||
|
||||
const task = new ImportJSONTask();
|
||||
const response = await task.perform({
|
||||
fileOperationId: fileOperation.id,
|
||||
});
|
||||
|
||||
for (const document of response.documents.values()) {
|
||||
expect(document.createdById).toEqual(originalAuthor.id);
|
||||
expect(document.lastModifiedById).toEqual(originalAuthor.id);
|
||||
}
|
||||
});
|
||||
|
||||
it("should fall back to importing user when no match is found", async () => {
|
||||
const team = await buildTeam();
|
||||
const admin = await buildAdmin({ teamId: team.id });
|
||||
const fileOperation = await buildFileOperation({
|
||||
userId: admin.id,
|
||||
teamId: team.id,
|
||||
});
|
||||
mockHandle(fileOperation);
|
||||
|
||||
const task = new ImportJSONTask();
|
||||
const response = await task.perform({
|
||||
fileOperationId: fileOperation.id,
|
||||
});
|
||||
|
||||
for (const document of response.documents.values()) {
|
||||
expect(document.createdById).toEqual(admin.id);
|
||||
expect(document.lastModifiedById).toEqual(admin.id);
|
||||
}
|
||||
});
|
||||
|
||||
it("should not match users from a different team", async () => {
|
||||
const team = await buildTeam();
|
||||
const otherTeam = await buildTeam();
|
||||
// Create user with matching email in a different team
|
||||
await buildUser({
|
||||
teamId: otherTeam.id,
|
||||
email: fixtureCreatedByEmail,
|
||||
});
|
||||
const admin = await buildAdmin({ teamId: team.id });
|
||||
const fileOperation = await buildFileOperation({
|
||||
userId: admin.id,
|
||||
teamId: team.id,
|
||||
});
|
||||
mockHandle(fileOperation);
|
||||
|
||||
const task = new ImportJSONTask();
|
||||
const response = await task.perform({
|
||||
fileOperationId: fileOperation.id,
|
||||
});
|
||||
|
||||
for (const document of response.documents.values()) {
|
||||
expect(document.createdById).toEqual(admin.id);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -305,6 +305,7 @@ export default abstract class ImportTask extends BaseTask<Props> {
|
||||
const collections = new Map<string, Collection>();
|
||||
const documents = new Map<string, Document>();
|
||||
const attachments = new Map<string, Attachment>();
|
||||
const userIdCache = new Map<string, string | undefined>();
|
||||
|
||||
const user = await User.findByPk(fileOperation.userId, {
|
||||
rejectOnEmpty: true,
|
||||
@@ -437,6 +438,13 @@ export default abstract class ImportTask extends BaseTask<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
const resolvedUserId =
|
||||
(await this.resolveUserId(
|
||||
item,
|
||||
fileOperation.teamId,
|
||||
userIdCache
|
||||
)) ?? fileOperation.userId;
|
||||
|
||||
const document = await documentCreator(ctx, {
|
||||
sourceMetadata: {
|
||||
fileName: path.basename(item.path),
|
||||
@@ -457,6 +465,8 @@ export default abstract class ImportTask extends BaseTask<Props> {
|
||||
publishedAt: item.updatedAt ?? item.createdAt ?? new Date(),
|
||||
parentDocumentId: item.parentDocumentId,
|
||||
importId: fileOperation.id,
|
||||
createdById: resolvedUserId,
|
||||
lastModifiedById: resolvedUserId,
|
||||
});
|
||||
documents.set(item.id, document);
|
||||
|
||||
@@ -535,6 +545,60 @@ export default abstract class ImportTask extends BaseTask<Props> {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the original document author to an internal user, using a cache
|
||||
* to avoid redundant database queries. Attempts to match by user ID first,
|
||||
* then by email. Both hits and misses are cached.
|
||||
*
|
||||
* @param item the document import item containing createdById and createdByEmail.
|
||||
* @param teamId the team ID to scope the lookup to.
|
||||
* @param cache a map used to cache resolved user IDs across calls.
|
||||
* @returns the resolved user ID, or undefined if no match was found.
|
||||
*/
|
||||
private async resolveUserId(
|
||||
item: { createdById?: string; createdByEmail?: string | null },
|
||||
teamId: string,
|
||||
cache: Map<string, string | undefined>
|
||||
): Promise<string | undefined> {
|
||||
if (item.createdById) {
|
||||
const cacheKey = `id:${item.createdById}`;
|
||||
if (cache.has(cacheKey)) {
|
||||
return cache.get(cacheKey);
|
||||
}
|
||||
|
||||
const user = await User.findOne({
|
||||
where: { id: item.createdById, teamId },
|
||||
});
|
||||
if (user) {
|
||||
cache.set(cacheKey, user.id);
|
||||
return user.id;
|
||||
}
|
||||
cache.set(cacheKey, undefined);
|
||||
}
|
||||
|
||||
if (item.createdByEmail) {
|
||||
const email = item.createdByEmail.toLowerCase().trim();
|
||||
const cacheKey = `email:${email}`;
|
||||
if (cache.has(cacheKey)) {
|
||||
return cache.get(cacheKey);
|
||||
}
|
||||
|
||||
const user = await User.findOne({
|
||||
where: { email, teamId },
|
||||
});
|
||||
if (user) {
|
||||
cache.set(cacheKey, user.id);
|
||||
if (item.createdById) {
|
||||
cache.set(`id:${item.createdById}`, user.id);
|
||||
}
|
||||
return user.id;
|
||||
}
|
||||
cache.set(cacheKey, undefined);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private async preprocessDocUrlIds(data: StructuredImportData) {
|
||||
for (const doc of data.documents) {
|
||||
// check DB only if urlId is present in the input.
|
||||
|
||||
@@ -65,7 +65,7 @@ import {
|
||||
import AttachmentHelper from "@server/models/helpers/AttachmentHelper";
|
||||
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
|
||||
import { ProsemirrorHelper } from "@server/models/helpers/ProsemirrorHelper";
|
||||
import SearchHelper from "@server/models/helpers/SearchHelper";
|
||||
import SearchProviderManager from "@server/utils/SearchProviderManager";
|
||||
import { TextHelper } from "@server/models/helpers/TextHelper";
|
||||
import { authorize, cannot } from "@server/policies";
|
||||
import {
|
||||
@@ -1047,17 +1047,18 @@ router.post(
|
||||
collaboratorIds = [userId];
|
||||
}
|
||||
|
||||
const documents = await SearchHelper.searchTitlesForUser(user, {
|
||||
query,
|
||||
dateFilter,
|
||||
statusFilter,
|
||||
collectionId,
|
||||
collaboratorIds,
|
||||
offset,
|
||||
limit,
|
||||
sort: sort as SortFilter,
|
||||
direction: direction as DirectionFilter,
|
||||
});
|
||||
const documents =
|
||||
await SearchProviderManager.getProvider().searchTitlesForUser(user, {
|
||||
query,
|
||||
dateFilter,
|
||||
statusFilter,
|
||||
collectionId,
|
||||
collaboratorIds,
|
||||
offset,
|
||||
limit,
|
||||
sort: sort as SortFilter,
|
||||
direction: direction as DirectionFilter,
|
||||
});
|
||||
const policies = presentPolicies(user, documents);
|
||||
const data = await presentDocuments(ctx, documents);
|
||||
|
||||
@@ -1131,7 +1132,7 @@ router.post(
|
||||
const team = await share.$get("team");
|
||||
invariant(team, "Share must belong to a team");
|
||||
|
||||
response = await SearchHelper.searchForTeam(team, {
|
||||
response = await SearchProviderManager.getProvider().searchForTeam(team, {
|
||||
query,
|
||||
collectionId: collection?.id || document?.collectionId,
|
||||
share,
|
||||
@@ -1177,7 +1178,7 @@ router.post(
|
||||
collaboratorIds = [userId];
|
||||
}
|
||||
|
||||
response = await SearchHelper.searchForUser(user, {
|
||||
response = await SearchProviderManager.getProvider().searchForUser(user, {
|
||||
query,
|
||||
collaboratorIds,
|
||||
collectionId,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { StatusFilter } from "@shared/types";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import validate from "@server/middlewares/validate";
|
||||
import { Group, User } from "@server/models";
|
||||
import SearchHelper from "@server/models/helpers/SearchHelper";
|
||||
import SearchProviderManager from "@server/utils/SearchProviderManager";
|
||||
import { can } from "@server/policies";
|
||||
import {
|
||||
presentDocuments,
|
||||
@@ -29,7 +29,7 @@ router.post(
|
||||
const actor = ctx.state.auth.user;
|
||||
|
||||
const [documents, users, groups, collections] = await Promise.all([
|
||||
SearchHelper.searchTitlesForUser(actor, {
|
||||
SearchProviderManager.getProvider().searchTitlesForUser(actor, {
|
||||
query,
|
||||
offset,
|
||||
limit,
|
||||
@@ -74,7 +74,7 @@ router.post(
|
||||
offset,
|
||||
limit,
|
||||
}),
|
||||
SearchHelper.searchCollectionsForUser(actor, { query, offset, limit }),
|
||||
SearchProviderManager.getProvider().searchCollectionsForUser(actor, { query, offset, limit }),
|
||||
]);
|
||||
|
||||
ctx.body = {
|
||||
|
||||
@@ -340,7 +340,9 @@ export const renderShare = async (ctx: Context, next: Next) => {
|
||||
(publicBranding && team?.description ? team.description : undefined),
|
||||
content,
|
||||
shortcutIcon:
|
||||
publicBranding && team?.avatarUrl ? team.avatarUrl : undefined,
|
||||
publicBranding && team?.avatarUrl
|
||||
? (await team.publicAvatarUrl()) ?? undefined
|
||||
: undefined,
|
||||
analytics,
|
||||
isShare: true,
|
||||
rootShareId,
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { Scope, TeamPreference } from "@shared/types";
|
||||
import type { ProsemirrorData } from "@shared/types";
|
||||
import {
|
||||
buildUser,
|
||||
buildAdmin,
|
||||
buildCollection,
|
||||
buildDocument,
|
||||
buildComment,
|
||||
buildCommentMark,
|
||||
buildOAuthAuthentication,
|
||||
} from "@server/test/factories";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
@@ -620,6 +622,148 @@ describe("POST /mcp/", () => {
|
||||
expect(data.text).toContain("Updated comment text");
|
||||
});
|
||||
|
||||
it("list_comments includes anchorText when comment is anchored", async () => {
|
||||
const { user, accessToken } = await buildOAuthUser();
|
||||
const collection = await buildCollection({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
const comment = await buildComment({
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
|
||||
const anchorText = "highlighted text";
|
||||
const content = {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: anchorText,
|
||||
marks: [buildCommentMark({ id: comment.id, userId: user.id })],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
} as ProsemirrorData;
|
||||
await document.update({ content });
|
||||
|
||||
const res = await callMcpTool(server, accessToken, "list_comments", {
|
||||
documentId: document.id,
|
||||
});
|
||||
const data = (res?.result?.content ?? []).map((c: { text: string }) =>
|
||||
JSON.parse(c.text)
|
||||
);
|
||||
|
||||
const match = data.find((c: { id: string }) => c.id === comment.id) as {
|
||||
anchorText: string;
|
||||
};
|
||||
expect(match).toBeDefined();
|
||||
expect(match.anchorText).toEqual(anchorText);
|
||||
});
|
||||
|
||||
it("list_comments returns undefined anchorText for non-anchored comment", async () => {
|
||||
const { user, accessToken } = await buildOAuthUser();
|
||||
const collection = await buildCollection({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
await buildComment({
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
|
||||
const res = await callMcpTool(server, accessToken, "list_comments", {
|
||||
documentId: document.id,
|
||||
});
|
||||
const data = (res?.result?.content ?? []).map((c: { text: string }) =>
|
||||
JSON.parse(c.text)
|
||||
);
|
||||
|
||||
expect(data.length).toBeGreaterThanOrEqual(1);
|
||||
expect(data[0].anchorText).toBeUndefined();
|
||||
});
|
||||
|
||||
it("create_comment includes anchorText in response", async () => {
|
||||
const { user, accessToken } = await buildOAuthUser();
|
||||
const collection = await buildCollection({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
|
||||
const res = await callMcpTool(server, accessToken, "create_comment", {
|
||||
documentId: document.id,
|
||||
text: "A new comment",
|
||||
});
|
||||
const data = JSON.parse(res?.result?.content?.[0]?.text ?? "{}");
|
||||
|
||||
// New comments have no anchor mark in the document, so anchorText is undefined
|
||||
expect(data.id).toBeDefined();
|
||||
expect(data.anchorText).toBeUndefined();
|
||||
});
|
||||
|
||||
it("update_comment includes anchorText in response", async () => {
|
||||
const { user, accessToken } = await buildOAuthUser();
|
||||
const collection = await buildCollection({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
const comment = await buildComment({
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
|
||||
const anchorText = "anchored content";
|
||||
const content = {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: anchorText,
|
||||
marks: [buildCommentMark({ id: comment.id, userId: user.id })],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
} as ProsemirrorData;
|
||||
await document.update({ content });
|
||||
|
||||
const res = await callMcpTool(server, accessToken, "update_comment", {
|
||||
id: comment.id,
|
||||
text: "Updated text",
|
||||
});
|
||||
const data = JSON.parse(res?.result?.content?.[0]?.text ?? "{}");
|
||||
|
||||
expect(data.id).toEqual(comment.id);
|
||||
expect(data.anchorText).toEqual(anchorText);
|
||||
});
|
||||
|
||||
it("delete_comment deletes own comment", async () => {
|
||||
const { user, accessToken } = await buildOAuthUser();
|
||||
const collection = await buildCollection({
|
||||
|
||||
@@ -23,15 +23,21 @@ import { version } from "../../../package.json";
|
||||
const app = new Koa();
|
||||
const router = new Router();
|
||||
|
||||
const defaultInstructions = `Document and collection markdown support @mentions using the syntax: @[Display Name](mention://user/userId). For example: @[John Doe](mention://user/c9a1b2e3-...). Use the list_users tool to find user IDs.`;
|
||||
|
||||
/**
|
||||
* Creates a fresh MCP server instance with tools filtered by the OAuth
|
||||
* scopes granted to the current token.
|
||||
*
|
||||
* @param scopes - the OAuth scopes granted to the access token.
|
||||
* @param instructions - optional workspace guidance to send to clients.
|
||||
* @param guidance - optional workspace guidance to append to default instructions.
|
||||
* @returns a configured McpServer ready to be connected to a transport.
|
||||
*/
|
||||
function createMcpServer(scopes: string[], instructions?: string): McpServer {
|
||||
function createMcpServer(scopes: string[], guidance?: string): McpServer {
|
||||
const instructions = guidance
|
||||
? `${defaultInstructions}\n\n${guidance}`
|
||||
: defaultInstructions;
|
||||
|
||||
const server = new McpServer(
|
||||
{
|
||||
name: "outline",
|
||||
@@ -41,7 +47,7 @@ function createMcpServer(scopes: string[], instructions?: string): McpServer {
|
||||
capabilities: {
|
||||
tools: {},
|
||||
},
|
||||
...(instructions ? { instructions } : {}),
|
||||
instructions,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -4,7 +4,10 @@ import type { FindOptions, WhereOptions } from "sequelize";
|
||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
||||
import { CommentStatusFilter } from "@shared/types";
|
||||
import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
||||
import type { CommentMark } from "@shared/utils/ProsemirrorHelper";
|
||||
import { commentParser } from "@server/editor";
|
||||
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
|
||||
import { Comment, Collection, Document } from "@server/models";
|
||||
import { authorize } from "@server/policies";
|
||||
import { presentComment } from "@server/presenters";
|
||||
@@ -23,10 +26,17 @@ import {
|
||||
* ProseMirror JSON.
|
||||
*
|
||||
* @param comment - the comment model instance.
|
||||
* @param commentMarks - optional precomputed comment marks to avoid reparsing.
|
||||
* @returns the presented comment with an additional `text` field.
|
||||
*/
|
||||
function presentCommentWithText(comment: Comment) {
|
||||
const presented = presentComment(comment);
|
||||
function presentCommentWithText(
|
||||
comment: Comment,
|
||||
commentMarks?: CommentMark[]
|
||||
) {
|
||||
const presented = presentComment(comment, {
|
||||
includeAnchorText: true,
|
||||
commentMarks,
|
||||
});
|
||||
return {
|
||||
...presented,
|
||||
text: comment.toPlainText(),
|
||||
@@ -182,7 +192,25 @@ export function commentTools(server: McpServer, scopes: string[]) {
|
||||
});
|
||||
}
|
||||
|
||||
const presented = comments.map(presentCommentWithText);
|
||||
// Precompute comment marks per document to avoid reparsing
|
||||
// the same document for every comment.
|
||||
const marksCache = new Map<string, CommentMark[]>();
|
||||
const presented = comments.map((comment) => {
|
||||
const doc = comment.document;
|
||||
let marks: CommentMark[] | undefined;
|
||||
if (doc) {
|
||||
if (!marksCache.has(doc.id)) {
|
||||
marksCache.set(
|
||||
doc.id,
|
||||
ProsemirrorHelper.getComments(
|
||||
DocumentHelper.toProsemirror(doc)
|
||||
)
|
||||
);
|
||||
}
|
||||
marks = marksCache.get(doc.id);
|
||||
}
|
||||
return presentCommentWithText(comment, marks);
|
||||
});
|
||||
return success(presented);
|
||||
} catch (err) {
|
||||
return error(err);
|
||||
@@ -238,6 +266,7 @@ export function commentTools(server: McpServer, scopes: string[]) {
|
||||
});
|
||||
|
||||
comment.createdBy = user;
|
||||
comment.document = document!;
|
||||
|
||||
const presented = presentCommentWithText(comment);
|
||||
return {
|
||||
@@ -292,6 +321,9 @@ export function commentTools(server: McpServer, scopes: string[]) {
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
authorize(user, "read", comment);
|
||||
authorize(user, "read", document);
|
||||
|
||||
if (text !== undefined) {
|
||||
authorize(user, "update", comment);
|
||||
authorize(user, "comment", document);
|
||||
@@ -312,6 +344,7 @@ export function commentTools(server: McpServer, scopes: string[]) {
|
||||
|
||||
await comment.saveWithCtx(ctx, status ? { silent: true } : undefined);
|
||||
|
||||
comment.document = document!;
|
||||
const presented = presentCommentWithText(comment);
|
||||
return {
|
||||
content: [
|
||||
|
||||
@@ -7,7 +7,6 @@ import documentUpdater from "@server/commands/documentUpdater";
|
||||
import { Op } from "sequelize";
|
||||
import { Collection, Document } from "@server/models";
|
||||
import { sequelize } from "@server/storage/database";
|
||||
import SearchHelper from "@server/models/helpers/SearchHelper";
|
||||
import { authorize } from "@server/policies";
|
||||
import { presentDocument } from "@server/presenters";
|
||||
import AuthenticationHelper from "@shared/helpers/AuthenticationHelper";
|
||||
@@ -22,6 +21,7 @@ import {
|
||||
withTracing,
|
||||
} from "./util";
|
||||
import { TextEditMode } from "@shared/types";
|
||||
import SearchProviderManager from "@server/utils/SearchProviderManager";
|
||||
|
||||
/**
|
||||
* Registers document-related MCP tools on the given server, filtered by
|
||||
@@ -93,6 +93,8 @@ export function documentTools(server: McpServer, scopes: string[]) {
|
||||
}
|
||||
|
||||
if (query) {
|
||||
const searchProvider = SearchProviderManager.getProvider();
|
||||
|
||||
// If the query looks like a document ID or urlId, try direct
|
||||
// lookup first so exact matches appear at the top of results.
|
||||
let exactMatch: Document | null = null;
|
||||
@@ -109,7 +111,7 @@ export function documentTools(server: McpServer, scopes: string[]) {
|
||||
}
|
||||
}
|
||||
|
||||
const { results } = await SearchHelper.searchForUser(user, {
|
||||
const { results } = await searchProvider.searchForUser(user, {
|
||||
query,
|
||||
collectionId,
|
||||
offset: effectiveOffset,
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
import type { DateFilter } from "@shared/types";
|
||||
import type { SearchableModel } from "@shared/types";
|
||||
import type { DirectionFilter, SortFilter, StatusFilter } from "@shared/types";
|
||||
import type Collection from "@server/models/Collection";
|
||||
import type Comment from "@server/models/Comment";
|
||||
import type Document from "@server/models/Document";
|
||||
import type Share from "@server/models/Share";
|
||||
import type Team from "@server/models/Team";
|
||||
import type User from "@server/models/User";
|
||||
|
||||
export interface SearchResponse {
|
||||
results: {
|
||||
/** The search ranking, for sorting results. */
|
||||
ranking: number;
|
||||
/** A snippet of contextual text around the search result. */
|
||||
context?: string;
|
||||
/** The document result. */
|
||||
document: Document;
|
||||
}[];
|
||||
/** The total number of results for the search query without pagination. */
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface SearchOptions {
|
||||
/** The query limit for pagination. */
|
||||
limit?: number;
|
||||
/** The query offset for pagination. */
|
||||
offset?: number;
|
||||
/** The text to search for. */
|
||||
query?: string;
|
||||
/** Limit results to a collection. Authorization is presumed to have been done before passing to this provider. */
|
||||
collectionId?: string | null;
|
||||
/** Limit results to a shared document. */
|
||||
share?: Share;
|
||||
/** Limit results to a date range. */
|
||||
dateFilter?: DateFilter;
|
||||
/** Status of the documents to return. */
|
||||
statusFilter?: StatusFilter[];
|
||||
/** Limit results to a list of documents. */
|
||||
documentIds?: string[];
|
||||
/** Limit results to a list of users that collaborated on the document. */
|
||||
collaboratorIds?: string[];
|
||||
/** The minimum number of words to be returned in the contextual snippet. */
|
||||
snippetMinWords?: number;
|
||||
/** The maximum number of words to be returned in the contextual snippet. */
|
||||
snippetMaxWords?: number;
|
||||
/** The field to sort results by. */
|
||||
sort?: SortFilter;
|
||||
/** The sort direction. */
|
||||
direction?: DirectionFilter;
|
||||
/** Whether to boost results by popularity score. Defaults to true. */
|
||||
usePopularityBoost?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract base class for search providers. Implementations handle full-text
|
||||
* search, title search, collection search, and index management.
|
||||
*/
|
||||
export abstract class BaseSearchProvider {
|
||||
/** Unique identifier for this provider, matched against `SEARCH_PROVIDER` env var. */
|
||||
abstract id: string;
|
||||
|
||||
/**
|
||||
* Perform a full-text search scoped to a user's accessible documents.
|
||||
*
|
||||
* @param user - the user performing the search.
|
||||
* @param options - search options.
|
||||
* @returns search results with ranking and context.
|
||||
*/
|
||||
abstract searchForUser(
|
||||
user: User,
|
||||
options?: SearchOptions
|
||||
): Promise<SearchResponse>;
|
||||
|
||||
/**
|
||||
* Perform a full-text search scoped to a team (used for shared document search).
|
||||
*
|
||||
* @param team - the team to search within.
|
||||
* @param options - search options.
|
||||
* @returns search results with ranking and context.
|
||||
*/
|
||||
abstract searchForTeam(
|
||||
team: Team,
|
||||
options?: SearchOptions
|
||||
): Promise<SearchResponse>;
|
||||
|
||||
/**
|
||||
* Search document titles for a user (used for link suggestions, quick search).
|
||||
*
|
||||
* @param user - the user performing the search.
|
||||
* @param options - search options.
|
||||
* @returns matching documents.
|
||||
*/
|
||||
abstract searchTitlesForUser(
|
||||
user: User,
|
||||
options?: SearchOptions
|
||||
): Promise<Document[]>;
|
||||
|
||||
/**
|
||||
* Search collections for a user.
|
||||
*
|
||||
* @param user - the user performing the search.
|
||||
* @param options - search options.
|
||||
* @returns matching collections.
|
||||
*/
|
||||
abstract searchCollectionsForUser(
|
||||
user: User,
|
||||
options?: SearchOptions
|
||||
): Promise<Collection[]>;
|
||||
|
||||
/**
|
||||
* Index or re-index a searchable item. For providers that rely on database
|
||||
* triggers (e.g. PostgreSQL tsvector), this may be a no-op.
|
||||
*
|
||||
* @param model - the type of model being indexed.
|
||||
* @param item - the model instance to index.
|
||||
*/
|
||||
abstract index(
|
||||
model: SearchableModel,
|
||||
item: Document | Collection | Comment
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* Remove an item from the search index.
|
||||
*
|
||||
* @param model - the type of model being removed.
|
||||
* @param id - the id of the item to remove.
|
||||
* @param teamId - the team id the item belongs to.
|
||||
*/
|
||||
abstract remove(
|
||||
model: SearchableModel,
|
||||
id: string,
|
||||
teamId: string
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* Update metadata for an indexed item without re-indexing the full content.
|
||||
* Useful for permission changes, moves, archive/unarchive.
|
||||
*
|
||||
* @param model - the type of model being updated.
|
||||
* @param id - the id of the item to update.
|
||||
* @param metadata - the metadata fields to update.
|
||||
*/
|
||||
abstract updateMetadata(
|
||||
model: SearchableModel,
|
||||
id: string,
|
||||
metadata: Record<string, unknown>
|
||||
): Promise<void>;
|
||||
}
|
||||
@@ -395,5 +395,109 @@ Content`;
|
||||
expect(image.attrs.width).toBe(400);
|
||||
expect(image.attrs.height).toBe(300);
|
||||
});
|
||||
|
||||
it("should extract dimensions from PNG data URI images", () => {
|
||||
// Minimal 2x3 PNG (IHDR: width=2, height=3)
|
||||
const pngBuffer = Buffer.alloc(33);
|
||||
// PNG signature
|
||||
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]).copy(
|
||||
pngBuffer
|
||||
);
|
||||
// IHDR chunk length (13 bytes)
|
||||
pngBuffer.writeUInt32BE(13, 8);
|
||||
// "IHDR"
|
||||
Buffer.from("IHDR").copy(pngBuffer, 12);
|
||||
// Width = 200
|
||||
pngBuffer.writeUInt32BE(200, 16);
|
||||
// Height = 150
|
||||
pngBuffer.writeUInt32BE(150, 20);
|
||||
|
||||
const base64 = pngBuffer.toString("base64");
|
||||
const html = `<p><img src="data:image/png;base64,${base64}"></p>`;
|
||||
|
||||
const doc = DocumentConverter.htmlToProsemirror(html);
|
||||
|
||||
const paragraph = doc.content.child(0);
|
||||
const image = paragraph.content.child(0);
|
||||
expect(image.type.name).toBe("image");
|
||||
expect(image.attrs.width).toBe(200);
|
||||
expect(image.attrs.height).toBe(150);
|
||||
});
|
||||
|
||||
it("should extract dimensions from JPEG data URI images", () => {
|
||||
// Minimal JPEG with SOF0 marker
|
||||
const jpegBuffer = Buffer.alloc(20);
|
||||
// JPEG SOI marker
|
||||
jpegBuffer[0] = 0xff;
|
||||
jpegBuffer[1] = 0xd8;
|
||||
// SOF0 marker
|
||||
jpegBuffer[2] = 0xff;
|
||||
jpegBuffer[3] = 0xc0;
|
||||
// Segment length
|
||||
jpegBuffer.writeUInt16BE(17, 4);
|
||||
// Precision
|
||||
jpegBuffer[6] = 8;
|
||||
// Height = 300
|
||||
jpegBuffer.writeUInt16BE(300, 7);
|
||||
// Width = 400
|
||||
jpegBuffer.writeUInt16BE(400, 9);
|
||||
|
||||
const base64 = jpegBuffer.toString("base64");
|
||||
const html = `<p><img src="data:image/jpeg;base64,${base64}"></p>`;
|
||||
|
||||
const doc = DocumentConverter.htmlToProsemirror(html);
|
||||
|
||||
const paragraph = doc.content.child(0);
|
||||
const image = paragraph.content.child(0);
|
||||
expect(image.type.name).toBe("image");
|
||||
expect(image.attrs.width).toBe(400);
|
||||
expect(image.attrs.height).toBe(300);
|
||||
});
|
||||
|
||||
it("should extract dimensions from GIF data URI images", () => {
|
||||
// Minimal GIF header
|
||||
const gifBuffer = Buffer.alloc(10);
|
||||
// GIF signature
|
||||
Buffer.from("GIF89a").copy(gifBuffer);
|
||||
// Width = 320 (little-endian)
|
||||
gifBuffer.writeUInt16LE(320, 6);
|
||||
// Height = 240 (little-endian)
|
||||
gifBuffer.writeUInt16LE(240, 8);
|
||||
|
||||
const base64 = gifBuffer.toString("base64");
|
||||
const html = `<p><img src="data:image/gif;base64,${base64}"></p>`;
|
||||
|
||||
const doc = DocumentConverter.htmlToProsemirror(html);
|
||||
|
||||
const paragraph = doc.content.child(0);
|
||||
const image = paragraph.content.child(0);
|
||||
expect(image.type.name).toBe("image");
|
||||
expect(image.attrs.width).toBe(320);
|
||||
expect(image.attrs.height).toBe(240);
|
||||
});
|
||||
|
||||
it("should not override existing width/height on data URI images", () => {
|
||||
// PNG with dimensions 200x150 but HTML attributes say 100x75
|
||||
const pngBuffer = Buffer.alloc(33);
|
||||
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]).copy(
|
||||
pngBuffer
|
||||
);
|
||||
pngBuffer.writeUInt32BE(13, 8);
|
||||
Buffer.from("IHDR").copy(pngBuffer, 12);
|
||||
pngBuffer.writeUInt32BE(200, 16);
|
||||
pngBuffer.writeUInt32BE(150, 20);
|
||||
|
||||
const base64 = pngBuffer.toString("base64");
|
||||
const html = `<p><img src="data:image/png;base64,${base64}" width="100" height="75"></p>`;
|
||||
|
||||
const doc = DocumentConverter.htmlToProsemirror(html);
|
||||
|
||||
const paragraph = doc.content.child(0);
|
||||
const image = paragraph.content.child(0);
|
||||
expect(image.type.name).toBe("image");
|
||||
// Should use the HTML attributes, not the parsed dimensions
|
||||
expect(image.attrs.width).toBe(100);
|
||||
expect(image.attrs.height).toBe(75);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,6 @@ import mammoth from "mammoth";
|
||||
import type { Node } from "prosemirror-model";
|
||||
import { DOMParser as ProsemirrorDOMParser } from "prosemirror-model";
|
||||
import yaml from "js-yaml";
|
||||
import { ProsemirrorHelper as SharedProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
||||
import { schema, serializer } from "@server/editor";
|
||||
import { FileImportError } from "@server/errors";
|
||||
import { trace, traceFunction } from "@server/logging/tracing";
|
||||
@@ -55,7 +54,7 @@ export class DocumentConverter {
|
||||
|
||||
// Extract title from first H1 heading
|
||||
let title = "";
|
||||
const headings = SharedProsemirrorHelper.getHeadings(doc);
|
||||
const headings = ProsemirrorHelper.getHeadings(doc);
|
||||
if (headings.length > 0 && headings[0].level === 1) {
|
||||
title = headings[0].title;
|
||||
doc = ProsemirrorHelper.removeFirstHeading(doc);
|
||||
@@ -148,6 +147,30 @@ export class DocumentConverter {
|
||||
const calculatedHeight = Math.round(parseInt(dataHeight) / ratio);
|
||||
img.setAttribute("height", String(calculatedHeight));
|
||||
}
|
||||
|
||||
// Extract dimensions from data URI images that lack width/height
|
||||
// (e.g. images embedded by mammoth during docx import).
|
||||
// Only decode a small prefix of the base64 data — headers for all
|
||||
// supported formats live within the first 64 KB of the file.
|
||||
if (!img.getAttribute("width") && !img.getAttribute("height")) {
|
||||
const src = img.getAttribute("src") || "";
|
||||
if (src.startsWith("data:") && src.includes(";base64,")) {
|
||||
const base64Start = src.indexOf(";base64,") + 8;
|
||||
// 4 base64 chars → 3 bytes; decode at most ~64 KB of image data.
|
||||
const maxBase64Chars = Math.ceil(65536 / 3) * 4;
|
||||
const base64Prefix = src.slice(
|
||||
base64Start,
|
||||
base64Start + maxBase64Chars
|
||||
);
|
||||
const dimensions = this.getImageDimensionsFromBuffer(
|
||||
Buffer.from(base64Prefix, "base64")
|
||||
);
|
||||
if (dimensions) {
|
||||
img.setAttribute("width", String(dimensions.width));
|
||||
img.setAttribute("height", String(dimensions.height));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -444,4 +467,98 @@ export class DocumentConverter {
|
||||
|
||||
return yamlCodeblock + remainingContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse image dimensions from a binary buffer. Supports PNG, JPEG, and GIF.
|
||||
*
|
||||
* @param buffer The image data.
|
||||
* @returns The width and height if parseable, otherwise undefined.
|
||||
*/
|
||||
private static getImageDimensionsFromBuffer(
|
||||
buffer: Buffer
|
||||
): { width: number; height: number } | undefined {
|
||||
try {
|
||||
// PNG: signature + IHDR chunk
|
||||
if (
|
||||
buffer.length >= 24 &&
|
||||
buffer[0] === 0x89 &&
|
||||
buffer[1] === 0x50 &&
|
||||
buffer[2] === 0x4e &&
|
||||
buffer[3] === 0x47
|
||||
) {
|
||||
return {
|
||||
width: buffer.readUInt32BE(16),
|
||||
height: buffer.readUInt32BE(20),
|
||||
};
|
||||
}
|
||||
|
||||
// GIF: signature + logical screen descriptor
|
||||
if (
|
||||
buffer.length >= 10 &&
|
||||
buffer[0] === 0x47 &&
|
||||
buffer[1] === 0x49 &&
|
||||
buffer[2] === 0x46
|
||||
) {
|
||||
return {
|
||||
width: buffer.readUInt16LE(6),
|
||||
height: buffer.readUInt16LE(8),
|
||||
};
|
||||
}
|
||||
|
||||
// JPEG: scan for SOF marker (cap at 64 KB to bound work)
|
||||
if (buffer.length >= 2 && buffer[0] === 0xff && buffer[1] === 0xd8) {
|
||||
const scanLimit = Math.min(buffer.length, 65536);
|
||||
let offset = 2;
|
||||
while (offset + 1 < scanLimit) {
|
||||
if (buffer[offset] !== 0xff) {
|
||||
offset++;
|
||||
continue;
|
||||
}
|
||||
const marker = buffer[offset + 1];
|
||||
offset += 2;
|
||||
|
||||
// Standalone markers without a payload
|
||||
if (
|
||||
marker === 0x00 ||
|
||||
marker === 0x01 ||
|
||||
(marker >= 0xd0 && marker <= 0xd9)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (offset + 2 > scanLimit) {
|
||||
break;
|
||||
}
|
||||
const segmentLength = buffer.readUInt16BE(offset);
|
||||
|
||||
// SOF markers contain the frame dimensions — check before
|
||||
// the advance guard since this returns immediately.
|
||||
if (
|
||||
(marker >= 0xc0 && marker <= 0xc3) ||
|
||||
(marker >= 0xc5 && marker <= 0xc7) ||
|
||||
(marker >= 0xc9 && marker <= 0xcb) ||
|
||||
(marker >= 0xcd && marker <= 0xcf)
|
||||
) {
|
||||
if (offset + 7 <= buffer.length) {
|
||||
return {
|
||||
height: buffer.readUInt16BE(offset + 3),
|
||||
width: buffer.readUInt16BE(offset + 5),
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Length includes itself and must be >= 2; bail on malformed data.
|
||||
if (segmentLength < 2 || offset + segmentLength > buffer.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
offset += segmentLength;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Return undefined if parsing fails
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import type { BaseTask } from "@server/queues/tasks/base/BaseTask";
|
||||
import type { UnfurlSignature, UninstallSignature } from "@server/types";
|
||||
import type { BaseIssueProvider } from "./BaseIssueProvider";
|
||||
import type { GroupSyncProvider } from "./GroupSyncProvider";
|
||||
import type { BaseSearchProvider } from "./BaseSearchProvider";
|
||||
|
||||
export enum PluginPriority {
|
||||
VeryHigh = 0,
|
||||
@@ -29,6 +30,7 @@ export enum Hook {
|
||||
EmailTemplate = "emailTemplate",
|
||||
IssueProvider = "issueProvider",
|
||||
Processor = "processor",
|
||||
SearchProvider = "searchProvider",
|
||||
Task = "task",
|
||||
UnfurlProvider = "unfurl",
|
||||
Uninstall = "uninstall",
|
||||
@@ -45,6 +47,7 @@ type PluginValueMap = {
|
||||
[Hook.EmailTemplate]: typeof BaseEmail<any>;
|
||||
[Hook.IssueProvider]: BaseIssueProvider;
|
||||
[Hook.Processor]: typeof BaseProcessor;
|
||||
[Hook.SearchProvider]: BaseSearchProvider;
|
||||
[Hook.Task]: typeof BaseTask<any>;
|
||||
[Hook.Uninstall]: UninstallSignature;
|
||||
[Hook.UnfurlProvider]: { unfurl: UnfurlSignature; cacheExpiry: number };
|
||||
@@ -106,9 +109,10 @@ export class PluginManager {
|
||||
|
||||
/**
|
||||
* Returns all the plugins of a given type in order of priority.
|
||||
* Triggers loading of all plugins from disk if not already loaded.
|
||||
*
|
||||
* @param type The type of plugin to filter by
|
||||
* @returns A list of plugins
|
||||
* @param type - the type of plugin to filter by.
|
||||
* @returns a list of plugins.
|
||||
*/
|
||||
public static getHooks<T extends Hook>(type: T) {
|
||||
this.loadPlugins();
|
||||
@@ -139,9 +143,9 @@ export class PluginManager {
|
||||
|
||||
glob
|
||||
.sync(path.join(rootDir, "plugins/*/server/!(*.test|schema).[jt]s"))
|
||||
.forEach((filePath: string) => {
|
||||
require(path.join(process.cwd(), filePath));
|
||||
});
|
||||
.forEach((filePath: string) =>
|
||||
require(path.join(process.cwd(), filePath))
|
||||
);
|
||||
this.loaded = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import env from "@server/env";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import type { BaseSearchProvider } from "./BaseSearchProvider";
|
||||
import { Hook, PluginManager } from "./PluginManager";
|
||||
|
||||
/**
|
||||
* Manages selection and caching of the active search provider based on the
|
||||
* `SEARCH_PROVIDER` environment variable.
|
||||
*/
|
||||
export default class SearchProviderManager {
|
||||
private static cachedProvider: BaseSearchProvider | undefined;
|
||||
|
||||
/**
|
||||
* Returns the active search provider. The provider is determined by matching
|
||||
* `SEARCH_PROVIDER` env var against registered `Hook.SearchProvider` plugins.
|
||||
*
|
||||
* @returns the active search provider instance.
|
||||
* @throws if no matching provider is found.
|
||||
*/
|
||||
public static getProvider(): BaseSearchProvider {
|
||||
if (this.cachedProvider) {
|
||||
return this.cachedProvider;
|
||||
}
|
||||
|
||||
const providerId = env.SEARCH_PROVIDER;
|
||||
const plugins = PluginManager.getHooks(Hook.SearchProvider);
|
||||
|
||||
for (const plugin of plugins) {
|
||||
if (plugin.value.id === providerId) {
|
||||
this.cachedProvider = plugin.value;
|
||||
Logger.debug("plugins", `Using search provider: ${plugin.value.id}`);
|
||||
return this.cachedProvider;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Search provider "${providerId}" not found. Available providers: ${plugins
|
||||
.map((p) => p.value.id)
|
||||
.join(", ")}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the cached provider. Useful for testing.
|
||||
*/
|
||||
public static reset(): void {
|
||||
this.cachedProvider = undefined;
|
||||
}
|
||||
}
|
||||
@@ -251,9 +251,10 @@ export class ValidateURL {
|
||||
|
||||
const { id, mentionType, modelId } = parseMentionUrl(url);
|
||||
return (
|
||||
id &&
|
||||
isUUID(id) &&
|
||||
(!id || isUUID(id)) &&
|
||||
!!mentionType &&
|
||||
Object.values(MentionType).includes(mentionType as MentionType) &&
|
||||
!!modelId &&
|
||||
isUUID(modelId)
|
||||
);
|
||||
} catch (_err) {
|
||||
|
||||
@@ -959,6 +959,10 @@ img.ProseMirror-separator {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.image-commented .image-wrapper {
|
||||
outline: ${props.theme.commentedImageOutlineLight} solid 2px;
|
||||
}
|
||||
|
||||
// Removes forced paragraph spaces below images, this is needed to images
|
||||
// being inline nodes that are displayed like blocks
|
||||
.component-image + img.ProseMirror-separator,
|
||||
@@ -1949,11 +1953,6 @@ table {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
tr:first-child {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
tr:first-child th,
|
||||
tr:first-child td {
|
||||
border-top: 0;
|
||||
@@ -2310,7 +2309,12 @@ table {
|
||||
}
|
||||
|
||||
.${EditorStyleHelper.tableStickyHeader} {
|
||||
tr:first-child th {
|
||||
> .${EditorStyleHelper.tableScrollable} > table > tbody > tr:first-child {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
> .${EditorStyleHelper.tableScrollable} > table > tbody > tr:first-child > th {
|
||||
transform: translateY(calc(var(--header-offset, 64px) + var(--sticky-scroll-offset, 0px)));
|
||||
border-bottom: 1px solid ${props.theme.divider};
|
||||
|
||||
@@ -2326,7 +2330,7 @@ table {
|
||||
}
|
||||
}
|
||||
|
||||
.${EditorStyleHelper.tableGrip} {
|
||||
> .${EditorStyleHelper.tableGrip} {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import { findParentNode } from "../queries/findParentNode";
|
||||
import type { NodeWithPos } from "../types";
|
||||
import type { Editor } from "../../../app/editor";
|
||||
import { LightboxImageFactory } from "../lib/Lightbox";
|
||||
import { hashString } from "../../utils/string";
|
||||
import { sanitizeUrl } from "../../utils/urls";
|
||||
|
||||
export const pluginKey = new PluginKey("mermaid");
|
||||
@@ -25,21 +26,72 @@ export type MermaidState = {
|
||||
editingId?: string;
|
||||
};
|
||||
|
||||
const STORAGE_PREFIX = "mermaid:";
|
||||
const MAX_STORAGE_ENTRIES = 20;
|
||||
|
||||
class Cache {
|
||||
static get(key: string) {
|
||||
return this.data.get(key);
|
||||
/** Get a cached SVG by diagram text and theme. */
|
||||
static get(key: string): string | undefined {
|
||||
try {
|
||||
const hash = hashString(key);
|
||||
const value = sessionStorage.getItem(STORAGE_PREFIX + hash);
|
||||
if (value) {
|
||||
this.touchLru(hash);
|
||||
return value;
|
||||
}
|
||||
} catch {
|
||||
// sessionStorage unavailable
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Cache a rendered SVG in sessionStorage. */
|
||||
static set(key: string, value: string) {
|
||||
this.data.set(key, value);
|
||||
|
||||
if (this.data.size > this.maxSize) {
|
||||
this.data.delete(this.data.keys().next().value);
|
||||
try {
|
||||
const hash = hashString(key);
|
||||
this.touchLru(hash);
|
||||
this.pruneStorage();
|
||||
sessionStorage.setItem(STORAGE_PREFIX + hash, value);
|
||||
} catch {
|
||||
// sessionStorage full or unavailable
|
||||
}
|
||||
}
|
||||
|
||||
private static maxSize = 20;
|
||||
private static data: Map<string, string> = new Map();
|
||||
/** Move or append a hash to the end (most recent) of the LRU list. */
|
||||
private static touchLru(hash: string) {
|
||||
const lru = this.getLru();
|
||||
const idx = lru.indexOf(hash);
|
||||
if (idx !== -1) {
|
||||
lru.splice(idx, 1);
|
||||
}
|
||||
lru.push(hash);
|
||||
sessionStorage.setItem(STORAGE_PREFIX + "lru", JSON.stringify(lru));
|
||||
}
|
||||
|
||||
/** Evict least-recently-used entries when over the limit. */
|
||||
private static pruneStorage() {
|
||||
const lru = this.getLru();
|
||||
|
||||
while (lru.length > MAX_STORAGE_ENTRIES) {
|
||||
const evict = lru.shift()!;
|
||||
sessionStorage.removeItem(STORAGE_PREFIX + evict);
|
||||
}
|
||||
|
||||
sessionStorage.setItem(STORAGE_PREFIX + "lru", JSON.stringify(lru));
|
||||
}
|
||||
|
||||
/** Read the LRU order list from sessionStorage. */
|
||||
private static getLru(): string[] {
|
||||
try {
|
||||
const raw = sessionStorage.getItem(STORAGE_PREFIX + "lru");
|
||||
if (raw) {
|
||||
return JSON.parse(raw);
|
||||
}
|
||||
} catch {
|
||||
// corrupted or unavailable
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
let mermaid: typeof MermaidUnsafe;
|
||||
@@ -104,16 +156,20 @@ class MermaidRenderer {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a temporary element that will render the diagram off-screen. This is necessary
|
||||
// as Mermaid will error if the element is not visible or the element is removed while the
|
||||
// diagram is being rendered.
|
||||
// Create a temporary element for rendering. We use visibility:hidden instead of
|
||||
// offscreen positioning so the browser computes correct bounding boxes for SVG
|
||||
// elements — offscreen elements can produce incorrect getBBox() results, leading
|
||||
// to wrong viewBox dimensions (see mermaid-js/mermaid#6146).
|
||||
const renderElement = document.createElement("div");
|
||||
const tempId =
|
||||
"offscreen-mermaid-" + Math.random().toString(36).substr(2, 9);
|
||||
renderElement.id = tempId;
|
||||
renderElement.style.position = "absolute";
|
||||
renderElement.style.left = "-9999px";
|
||||
renderElement.style.top = "-9999px";
|
||||
renderElement.style.position = "fixed";
|
||||
renderElement.style.visibility = "hidden";
|
||||
renderElement.style.top = "0";
|
||||
renderElement.style.left = "0";
|
||||
renderElement.style.width = "100%";
|
||||
renderElement.style.zIndex = "-1";
|
||||
document.body.appendChild(renderElement);
|
||||
|
||||
try {
|
||||
|
||||
@@ -20,6 +20,7 @@ import { ImageSource } from "../lib/FileHelper";
|
||||
import { DiagramPlaceholder } from "../components/DiagramPlaceholder";
|
||||
import { addComment } from "../commands/comment";
|
||||
import { addLink } from "../commands/link";
|
||||
import { commentedImagePlugin } from "../plugins/CommentedImagePlugin";
|
||||
|
||||
const imageSizeRegex = /\s=(\d+)?x(\d+)?$/;
|
||||
|
||||
@@ -241,6 +242,7 @@ export default class Image extends SimpleImage {
|
||||
get plugins() {
|
||||
return [
|
||||
...super.plugins,
|
||||
commentedImagePlugin(),
|
||||
new Plugin({
|
||||
props: {
|
||||
handleKeyDown: (view, event) => {
|
||||
|
||||
@@ -114,7 +114,8 @@ export class TableView extends ProsemirrorTableView {
|
||||
private static readonly HEADER_HEIGHT = 60;
|
||||
|
||||
/**
|
||||
* Sets up the scroll listener for sticky header behavior.
|
||||
* Sets up the scroll listener for sticky header behavior. Nested tables
|
||||
* (tables within another table) are excluded from sticky header behavior.
|
||||
*/
|
||||
private setupStickyHeader() {
|
||||
if (!isBrowser) {
|
||||
@@ -123,6 +124,11 @@ export class TableView extends ProsemirrorTableView {
|
||||
|
||||
// Defer setup to ensure DOM is fully rendered
|
||||
setTimeout(() => {
|
||||
// Skip sticky header for nested tables
|
||||
if (this.dom.closest(`table .${EditorStyleHelper.table}`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.scrollHandler = () => {
|
||||
this.updateStickyHeader();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import type { EditorState } from "prosemirror-state";
|
||||
import { Plugin } from "prosemirror-state";
|
||||
import { Decoration, DecorationSet } from "prosemirror-view";
|
||||
|
||||
/**
|
||||
* Plugin that applies a light outline decoration to image nodes that have
|
||||
* comment marks, providing a visual indicator that the image has been commented
|
||||
* on.
|
||||
*/
|
||||
export class CommentedImagePlugin extends Plugin {
|
||||
constructor() {
|
||||
super({
|
||||
state: {
|
||||
init: (_, state: EditorState) => ({
|
||||
decorations: this.createDecorations(state),
|
||||
}),
|
||||
apply: (tr, pluginState, _oldState, newState) => {
|
||||
if (tr.docChanged) {
|
||||
return { decorations: this.createDecorations(newState) };
|
||||
}
|
||||
return pluginState;
|
||||
},
|
||||
},
|
||||
props: {
|
||||
decorations: (state) => {
|
||||
const pluginState = this.getState(state);
|
||||
return pluginState ? pluginState.decorations : null;
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private createDecorations(state: EditorState) {
|
||||
const decorations: Decoration[] = [];
|
||||
|
||||
state.doc.descendants((node, pos) => {
|
||||
if (
|
||||
node.type.name === "image" &&
|
||||
Array.isArray(node.attrs.marks) &&
|
||||
node.attrs.marks.some(
|
||||
(mark: { type: string; attrs?: { resolved?: boolean } }) =>
|
||||
mark.type === "comment" && !mark.attrs?.resolved
|
||||
)
|
||||
) {
|
||||
decorations.push(
|
||||
Decoration.node(pos, pos + node.nodeSize, {
|
||||
class: "image-commented",
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return DecorationSet.create(state.doc, decorations);
|
||||
}
|
||||
}
|
||||
|
||||
export const commentedImagePlugin = () => new CommentedImagePlugin();
|
||||
@@ -0,0 +1,155 @@
|
||||
import markdownit from "markdown-it";
|
||||
import mentionRule from "./mention";
|
||||
|
||||
function findMentionTokens(tokens: ReturnType<markdownit["parse"]>) {
|
||||
const mentions: Array<{
|
||||
id: string | null;
|
||||
type: string | null;
|
||||
modelId: string | null;
|
||||
label: string;
|
||||
}> = [];
|
||||
|
||||
for (const tok of tokens) {
|
||||
if (tok.type === "inline" && tok.children) {
|
||||
for (const child of tok.children) {
|
||||
if (child.type === "mention") {
|
||||
mentions.push({
|
||||
id: child.attrGet("id"),
|
||||
type: child.attrGet("type"),
|
||||
modelId: child.attrGet("modelId"),
|
||||
label: child.content,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mentions;
|
||||
}
|
||||
|
||||
describe("mention rule", () => {
|
||||
const md = markdownit().use(mentionRule);
|
||||
|
||||
describe("3-segment format (existing)", () => {
|
||||
it("should parse a user mention", () => {
|
||||
const result = md.parse(
|
||||
"@[John Doe](mention://a1b2c3d4-e5f6-7890-abcd-ef1234567890/user/f0e1d2c3-b4a5-6789-0abc-def123456789)",
|
||||
{}
|
||||
);
|
||||
const mentions = findMentionTokens(result);
|
||||
|
||||
expect(mentions).toHaveLength(1);
|
||||
expect(mentions[0]).toEqual({
|
||||
id: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
||||
type: "user",
|
||||
modelId: "f0e1d2c3-b4a5-6789-0abc-def123456789",
|
||||
label: "John Doe",
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse a group mention", () => {
|
||||
const result = md.parse(
|
||||
"@[Engineering](mention://a1b2c3d4-e5f6-7890-abcd-ef1234567890/group/f0e1d2c3-b4a5-6789-0abc-def123456789)",
|
||||
{}
|
||||
);
|
||||
const mentions = findMentionTokens(result);
|
||||
|
||||
expect(mentions).toHaveLength(1);
|
||||
expect(mentions[0].type).toBe("group");
|
||||
expect(mentions[0].label).toBe("Engineering");
|
||||
});
|
||||
});
|
||||
|
||||
describe("2-segment format (new)", () => {
|
||||
it("should parse a user mention", () => {
|
||||
const result = md.parse(
|
||||
"@[John Doe](mention://user/f0e1d2c3-b4a5-6789-0abc-def123456789)",
|
||||
{}
|
||||
);
|
||||
const mentions = findMentionTokens(result);
|
||||
|
||||
expect(mentions).toHaveLength(1);
|
||||
expect(mentions[0].type).toBe("user");
|
||||
expect(mentions[0].modelId).toBe("f0e1d2c3-b4a5-6789-0abc-def123456789");
|
||||
expect(mentions[0].label).toBe("John Doe");
|
||||
// instanceId should be auto-generated
|
||||
expect(mentions[0].id).toBeTruthy();
|
||||
expect(mentions[0].id).toMatch(
|
||||
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/
|
||||
);
|
||||
});
|
||||
|
||||
it("should parse a group mention", () => {
|
||||
const result = md.parse("@[Engineering](mention://group/abc123)", {});
|
||||
const mentions = findMentionTokens(result);
|
||||
|
||||
expect(mentions).toHaveLength(1);
|
||||
expect(mentions[0].type).toBe("group");
|
||||
expect(mentions[0].modelId).toBe("abc123");
|
||||
expect(mentions[0].label).toBe("Engineering");
|
||||
});
|
||||
|
||||
it("should parse mention with single-word name", () => {
|
||||
const result = md.parse("@[Alice](mention://user/abc123)", {});
|
||||
const mentions = findMentionTokens(result);
|
||||
|
||||
expect(mentions).toHaveLength(1);
|
||||
expect(mentions[0].label).toBe("Alice");
|
||||
});
|
||||
});
|
||||
|
||||
describe("mixed content", () => {
|
||||
it("should parse mention within text", () => {
|
||||
const result = md.parse(
|
||||
"Hello @[John Doe](mention://user/abc123) please review",
|
||||
{}
|
||||
);
|
||||
const mentions = findMentionTokens(result);
|
||||
|
||||
expect(mentions).toHaveLength(1);
|
||||
expect(mentions[0].label).toBe("John Doe");
|
||||
});
|
||||
|
||||
it("should parse multiple mentions", () => {
|
||||
const result = md.parse(
|
||||
"@[Alice](mention://user/id1) and @[Bob](mention://user/id2)",
|
||||
{}
|
||||
);
|
||||
const mentions = findMentionTokens(result);
|
||||
|
||||
expect(mentions).toHaveLength(2);
|
||||
expect(mentions[0].label).toBe("Alice");
|
||||
expect(mentions[1].label).toBe("Bob");
|
||||
});
|
||||
|
||||
it("should parse mix of 2-segment and 3-segment mentions", () => {
|
||||
const result = md.parse(
|
||||
"@[Alice](mention://user/id1) and @[Bob](mention://inst-id/user/id2)",
|
||||
{}
|
||||
);
|
||||
const mentions = findMentionTokens(result);
|
||||
|
||||
expect(mentions).toHaveLength(2);
|
||||
expect(mentions[0].label).toBe("Alice");
|
||||
expect(mentions[0].id).toBeTruthy(); // auto-generated
|
||||
expect(mentions[1].label).toBe("Bob");
|
||||
expect(mentions[1].id).toBe("inst-id");
|
||||
});
|
||||
});
|
||||
|
||||
describe("non-mentions", () => {
|
||||
it("should not parse regular links as mentions", () => {
|
||||
const result = md.parse("[John Doe](https://example.com)", {});
|
||||
const mentions = findMentionTokens(result);
|
||||
|
||||
expect(mentions).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("should not parse links without @ prefix as mentions", () => {
|
||||
const result = md.parse("[John Doe](mention://user/abc123)", {});
|
||||
const mentions = findMentionTokens(result);
|
||||
|
||||
expect(mentions).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,40 @@
|
||||
import type { Token, StateCore } from "markdown-it";
|
||||
import type MarkdownIt from "markdown-it";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import parseMentionUrl from "@shared/utils/parseMentionUrl";
|
||||
|
||||
/**
|
||||
* Check whether a URL is a valid mention:// href.
|
||||
*
|
||||
* @param href the URL string to test.
|
||||
* @returns true when the href is a recognised mention URL.
|
||||
*/
|
||||
function isMentionHref(href: string) {
|
||||
const { mentionType, modelId } = parseMentionUrl(href);
|
||||
return mentionType !== undefined && modelId !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a mention:// href into the id, type and modelId needed by the editor.
|
||||
* For 2-segment URLs (no instance id) a fresh UUID is generated.
|
||||
*
|
||||
* @param href the mention URL to parse.
|
||||
* @returns the parsed components.
|
||||
* @throws when the href is not a valid mention URL.
|
||||
*/
|
||||
function parseMentionHref(href: string): {
|
||||
id: string;
|
||||
type: string;
|
||||
modelId: string;
|
||||
} {
|
||||
const { id, mentionType, modelId } = parseMentionUrl(href);
|
||||
|
||||
if (!mentionType || !modelId) {
|
||||
throw new Error(`Invalid mention href: ${href}`);
|
||||
}
|
||||
|
||||
return { id: id ?? uuidv4(), type: mentionType, modelId };
|
||||
}
|
||||
|
||||
function renderMention(tokens: Token[], idx: number) {
|
||||
const id = tokens[idx].attrGet("id");
|
||||
@@ -11,8 +46,6 @@ function renderMention(tokens: Token[], idx: number) {
|
||||
}
|
||||
|
||||
function parseMentions(state: StateCore) {
|
||||
const hrefRE = /^mention:\/\/([a-z0-9-]+)\/([a-z]+)\/([a-z0-9-]+)$/;
|
||||
|
||||
for (let i = 0; i < state.tokens.length; i++) {
|
||||
const tok = state.tokens[i];
|
||||
if (!(tok.type === "inline" && tok.children)) {
|
||||
@@ -43,7 +76,7 @@ function parseMentions(state: StateCore) {
|
||||
|
||||
// "link_open" token should have valid href
|
||||
const attr = openToken.attrs?.[0];
|
||||
if (!(attr && attr[0] === "href" && hrefRE.test(attr[1]))) {
|
||||
if (!(attr && attr[0] === "href" && isMentionHref(attr[1]))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -57,11 +90,10 @@ function parseMentions(state: StateCore) {
|
||||
// remove "@" from preceding token
|
||||
precToken.content = precToken.content.slice(0, -1);
|
||||
|
||||
// href must be present, otherwise the hrefRE test in canChunkComposeMentionToken would've failed
|
||||
// href must be present, otherwise the isMentionHref test would've failed
|
||||
// oxlint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const href = openToken.attrs![0][1];
|
||||
const matches = href.match(hrefRE);
|
||||
const [id, mType, mId] = matches!.slice(1);
|
||||
const { id, type: mType, modelId: mId } = parseMentionHref(href);
|
||||
|
||||
const mentionToken = new state.Token("mention", "", 0);
|
||||
mentionToken.attrSet("id", id);
|
||||
|
||||
@@ -71,7 +71,9 @@ const buildBaseTheme = (input: Partial<Colors>) => {
|
||||
selected: colors.accent,
|
||||
textHighlight: "#FDEA9B",
|
||||
textHighlightForeground: colors.almostBlack,
|
||||
commentMarkBackground: transparentize(0.5, "#2BC2FF"),
|
||||
commentMarkBackground: transparentize(0.5, colors.brand.marine),
|
||||
commentedImageOutlineDark: colors.brand.marine,
|
||||
commentedImageOutlineLight: transparentize(0.7, colors.brand.marine),
|
||||
code: colors.lightBlack,
|
||||
codeComment: "#008000",
|
||||
codePunctuation: "#393a34",
|
||||
|
||||
@@ -32,6 +32,13 @@ export enum DirectionFilter {
|
||||
DESC = "DESC",
|
||||
}
|
||||
|
||||
/** Model types that support search indexing. */
|
||||
export enum SearchableModel {
|
||||
Document = "document",
|
||||
Collection = "collection",
|
||||
Comment = "comment",
|
||||
}
|
||||
|
||||
export enum CollectionStatusFilter {
|
||||
Archived = "archived",
|
||||
}
|
||||
|
||||
@@ -234,4 +234,148 @@ describe("ProsemirrorHelper", () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("removeMarks", () => {
|
||||
it("should remove specified mark types from text nodes", () => {
|
||||
const doc: ProsemirrorData = {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "hello",
|
||||
marks: [
|
||||
{ type: "comment", attrs: { id: "c1" } },
|
||||
{ type: "bold" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = ProsemirrorHelper.removeMarks(doc, ["comment"]);
|
||||
expect(result.content![0].content![0].marks).toEqual([{ type: "bold" }]);
|
||||
});
|
||||
|
||||
it("should remove marks from nested content", () => {
|
||||
const doc: ProsemirrorData = {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "blockquote",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "nested",
|
||||
marks: [{ type: "comment", attrs: { id: "c1" } }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = ProsemirrorHelper.removeMarks(doc, ["comment"]);
|
||||
expect(result.content![0].content![0].content![0].marks).toEqual([]);
|
||||
});
|
||||
|
||||
it("should remove marks from node attrs.marks", () => {
|
||||
const doc: ProsemirrorData = {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "image",
|
||||
attrs: {
|
||||
src: "test.png",
|
||||
marks: [
|
||||
{ type: "comment", attrs: { id: "c1" } },
|
||||
{ type: "link", attrs: { href: "url" } },
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = ProsemirrorHelper.removeMarks(doc, ["comment"]);
|
||||
expect(result.content![0].attrs!.marks).toEqual([
|
||||
{ type: "link", attrs: { href: "url" } },
|
||||
]);
|
||||
});
|
||||
|
||||
it("should remove multiple mark types at once", () => {
|
||||
const doc: ProsemirrorData = {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "hello",
|
||||
marks: [
|
||||
{ type: "comment", attrs: { id: "c1" } },
|
||||
{ type: "bold" },
|
||||
{ type: "highlight" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = ProsemirrorHelper.removeMarks(doc, [
|
||||
"comment",
|
||||
"highlight",
|
||||
]);
|
||||
expect(result.content![0].content![0].marks).toEqual([{ type: "bold" }]);
|
||||
});
|
||||
|
||||
it("should leave nodes unchanged when no marks match", () => {
|
||||
const doc: ProsemirrorData = {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "hello",
|
||||
marks: [{ type: "bold" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = ProsemirrorHelper.removeMarks(doc, ["comment"]);
|
||||
expect(result.content![0].content![0].marks).toEqual([{ type: "bold" }]);
|
||||
});
|
||||
|
||||
it("should handle nodes with no marks", () => {
|
||||
const doc: ProsemirrorData = {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "plain",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = ProsemirrorHelper.removeMarks(doc, ["comment"]);
|
||||
expect(result.content![0].content![0].marks).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -48,10 +48,38 @@ export const attachmentPublicRegex =
|
||||
/public\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/gi;
|
||||
|
||||
export class ProsemirrorHelper {
|
||||
/**
|
||||
* Remove specific mark types from all nodes in the document.
|
||||
*
|
||||
* @param doc the prosemirror document or JSON data.
|
||||
* @param marks the mark type names to remove.
|
||||
* @returns the document data with specified marks removed.
|
||||
*/
|
||||
static removeMarks(doc: Node | ProsemirrorData, marks: string[]) {
|
||||
const json = "toJSON" in doc ? (doc.toJSON() as ProsemirrorData) : doc;
|
||||
const markSet = new Set(marks);
|
||||
|
||||
function removeMarksInner(node: ProsemirrorData) {
|
||||
if (node.marks) {
|
||||
node.marks = node.marks.filter((mark) => !markSet.has(mark.type));
|
||||
}
|
||||
if (node.attrs?.marks) {
|
||||
node.attrs.marks = (node.attrs.marks as { type: string }[])?.filter(
|
||||
(mark) => !markSet.has(mark.type)
|
||||
);
|
||||
}
|
||||
if (node.content) {
|
||||
node.content.forEach(removeMarksInner);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
return removeMarksInner(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new empty document.
|
||||
*
|
||||
* @returns A new empty document as JSON.
|
||||
* @returns a new empty document as JSON.
|
||||
*/
|
||||
static getEmptyDocument(): ProsemirrorData {
|
||||
return {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { NavigationNode } from "../types";
|
||||
import shallowEqual from "./shallowEqual";
|
||||
import naturalSort from "./naturalSort";
|
||||
|
||||
type Sort = {
|
||||
@@ -21,12 +22,23 @@ export const sortNavigationNodes = (
|
||||
direction: sort.direction,
|
||||
});
|
||||
|
||||
return orderedDocs.map((node) => ({
|
||||
...node,
|
||||
children: sortChildren
|
||||
? sortNavigationNodes(node.children, sort, sortChildren)
|
||||
: node.children,
|
||||
}));
|
||||
if (!sortChildren) {
|
||||
return orderedDocs;
|
||||
}
|
||||
|
||||
return orderedDocs.map((node) => {
|
||||
const sortedChildren = sortNavigationNodes(
|
||||
node.children,
|
||||
sort,
|
||||
sortChildren
|
||||
);
|
||||
// Preserve the original node reference if children order didn't change.
|
||||
// This allows React.memo to skip re-renders of unchanged tree nodes.
|
||||
if (shallowEqual(sortedChildren, node.children)) {
|
||||
return node;
|
||||
}
|
||||
return { ...node, children: sortedChildren };
|
||||
});
|
||||
};
|
||||
|
||||
export const colorPalette = [
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import parseMentionUrl from "./parseMentionUrl";
|
||||
|
||||
describe("parseMentionUrl", () => {
|
||||
it("should parse 3-segment mention URL", () => {
|
||||
expect(
|
||||
parseMentionUrl(
|
||||
"mention://9a17c1c8-d178-4350-9001-203a73070fcb/user/abc123def456"
|
||||
)
|
||||
).toEqual({
|
||||
id: "9a17c1c8-d178-4350-9001-203a73070fcb",
|
||||
mentionType: "user",
|
||||
modelId: "abc123def456",
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse 2-segment mention URL", () => {
|
||||
expect(parseMentionUrl("mention://user/abc123def456")).toEqual({
|
||||
mentionType: "user",
|
||||
modelId: "abc123def456",
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse 2-segment mention URL with UUID modelId", () => {
|
||||
expect(
|
||||
parseMentionUrl("mention://user/9a17c1c8-d178-4350-9001-203a73070fcb")
|
||||
).toEqual({
|
||||
mentionType: "user",
|
||||
modelId: "9a17c1c8-d178-4350-9001-203a73070fcb",
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse group mention type", () => {
|
||||
expect(parseMentionUrl("mention://group/abc123")).toEqual({
|
||||
mentionType: "group",
|
||||
modelId: "abc123",
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse pull_request mention type with underscore", () => {
|
||||
expect(
|
||||
parseMentionUrl(
|
||||
"mention://9a17c1c8-d178-4350-9001-203a73070fcb/pull_request/abc123"
|
||||
)
|
||||
).toEqual({
|
||||
id: "9a17c1c8-d178-4350-9001-203a73070fcb",
|
||||
mentionType: "pull_request",
|
||||
modelId: "abc123",
|
||||
});
|
||||
});
|
||||
|
||||
it("should return empty object for invalid URL", () => {
|
||||
expect(parseMentionUrl("https://example.com")).toEqual({});
|
||||
});
|
||||
|
||||
it("should return empty object for empty string", () => {
|
||||
expect(parseMentionUrl("")).toEqual({});
|
||||
});
|
||||
});
|
||||
@@ -1,12 +1,30 @@
|
||||
const parseMentionUrl = (url: string) => {
|
||||
const matches = url.match(
|
||||
/^mention:\/\/([a-z0-9-]+)\/([a-z]+)\/([a-z0-9-]+)$/
|
||||
/**
|
||||
* Parse a mention:// URL into its components.
|
||||
*
|
||||
* Supports both the 3-segment format (mention://id/type/modelId) and the
|
||||
* 2-segment format (mention://type/modelId).
|
||||
*
|
||||
* @param url the mention URL to parse.
|
||||
* @returns the parsed components, or an empty object if the URL is invalid.
|
||||
*/
|
||||
const parseMentionUrl = (
|
||||
url: string
|
||||
): { id?: string; mentionType?: string; modelId?: string } => {
|
||||
const match3 = url.match(
|
||||
/^mention:\/\/([a-z0-9-]+)\/([a-z_]+)\/([a-z0-9-]+)$/
|
||||
);
|
||||
if (!matches) {
|
||||
return {};
|
||||
if (match3) {
|
||||
const [id, mentionType, modelId] = match3.slice(1);
|
||||
return { id, mentionType, modelId };
|
||||
}
|
||||
const [id, mentionType, modelId] = matches.slice(1);
|
||||
return { id, mentionType, modelId };
|
||||
|
||||
const match2 = url.match(/^mention:\/\/([a-z_]+)\/([a-z0-9-]+)$/);
|
||||
if (match2) {
|
||||
const [mentionType, modelId] = match2.slice(1);
|
||||
return { mentionType, modelId };
|
||||
}
|
||||
|
||||
return {};
|
||||
};
|
||||
|
||||
export default parseMentionUrl;
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Check if two arrays have the same elements in the same order by reference.
|
||||
* Uses strict equality (===) rather than deep comparison, so object identity
|
||||
* is preserved — important for React.memo optimizations.
|
||||
*
|
||||
* @param a first array.
|
||||
* @param b second array.
|
||||
* @returns true if the arrays are shallowly equal.
|
||||
*/
|
||||
export default function shallowEqual<T>(a: T[], b: T[]): boolean {
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { hashString } from "./string";
|
||||
|
||||
describe("hashString", () => {
|
||||
it("returns a hex string", () => {
|
||||
expect(hashString("hello")).toMatch(/^[0-9a-f]+$/);
|
||||
});
|
||||
|
||||
it("returns consistent results for the same input", () => {
|
||||
expect(hashString("test")).toBe(hashString("test"));
|
||||
});
|
||||
|
||||
it("returns different hashes for different inputs", () => {
|
||||
expect(hashString("abc")).not.toBe(hashString("def"));
|
||||
});
|
||||
|
||||
it("handles empty string", () => {
|
||||
expect(hashString("")).toMatch(/^[0-9a-f]+$/);
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,17 @@
|
||||
/**
|
||||
* Simple string hash using the djb2 algorithm, returns a hex string.
|
||||
*
|
||||
* @param str the string to hash.
|
||||
* @returns a hex-encoded 32-bit hash.
|
||||
*/
|
||||
export function hashString(str: string): string {
|
||||
let hash = 5381;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
hash = ((hash << 5) + hash + str.charCodeAt(i)) | 0;
|
||||
}
|
||||
return (hash >>> 0).toString(16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first occurrence of a substring in a string that matches a regular expression.
|
||||
*
|
||||
|
||||
@@ -2897,45 +2897,45 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@chevrotain/cst-dts-gen@npm:11.0.3":
|
||||
version: 11.0.3
|
||||
resolution: "@chevrotain/cst-dts-gen@npm:11.0.3"
|
||||
"@chevrotain/cst-dts-gen@npm:11.1.2":
|
||||
version: 11.1.2
|
||||
resolution: "@chevrotain/cst-dts-gen@npm:11.1.2"
|
||||
dependencies:
|
||||
"@chevrotain/gast": "npm:11.0.3"
|
||||
"@chevrotain/types": "npm:11.0.3"
|
||||
lodash-es: "npm:4.17.21"
|
||||
checksum: 10c0/9e945a0611386e4e08af34c2d0b3af36c1af08f726b58145f11310f2aeafcb2d65264c06ec65a32df6b6a65771e6a55be70580c853afe3ceb51487e506967104
|
||||
"@chevrotain/gast": "npm:11.1.2"
|
||||
"@chevrotain/types": "npm:11.1.2"
|
||||
lodash-es: "npm:4.17.23"
|
||||
checksum: 10c0/372a9573a404a1d717c92875024588a53d1eb078f12d2cd1d79d9c2c888c9b429eb62bbc85501b8ff168c14b22a675da99d97bb39b0a774e9fee000dc60fd8ff
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@chevrotain/gast@npm:11.0.3":
|
||||
version: 11.0.3
|
||||
resolution: "@chevrotain/gast@npm:11.0.3"
|
||||
"@chevrotain/gast@npm:11.1.2":
|
||||
version: 11.1.2
|
||||
resolution: "@chevrotain/gast@npm:11.1.2"
|
||||
dependencies:
|
||||
"@chevrotain/types": "npm:11.0.3"
|
||||
lodash-es: "npm:4.17.21"
|
||||
checksum: 10c0/54fc44d7b4a7b0323f49d957dd88ad44504922d30cb226d93b430b0e09925efe44e0726068581d777f423fabfb878a2238ed2c87b690c0c0014ebd12b6968354
|
||||
"@chevrotain/types": "npm:11.1.2"
|
||||
lodash-es: "npm:4.17.23"
|
||||
checksum: 10c0/540bfc9270d752f398b29efe9c89bb907d2984a47db4308a943e50c1cbd261ee13ecbef15c0e07808cf476d835bc36e65854db0bd214c277296cc14013eca8f4
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@chevrotain/regexp-to-ast@npm:11.0.3":
|
||||
version: 11.0.3
|
||||
resolution: "@chevrotain/regexp-to-ast@npm:11.0.3"
|
||||
checksum: 10c0/6939c5c94fbfb8c559a4a37a283af5ded8e6147b184a7d7bcf5ad1404d9d663c78d81602bd8ea8458ec497358a9e1671541099c511835d0be2cad46f00c62b3f
|
||||
"@chevrotain/regexp-to-ast@npm:11.1.2":
|
||||
version: 11.1.2
|
||||
resolution: "@chevrotain/regexp-to-ast@npm:11.1.2"
|
||||
checksum: 10c0/645f02ac94cb33e04c10547b197762c6936c7b7668966240684795ce131cb515a76b63e0cc500e787d669f1a36bd2f902ec518f27843ec857ecf9043c717527e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@chevrotain/types@npm:11.0.3":
|
||||
version: 11.0.3
|
||||
resolution: "@chevrotain/types@npm:11.0.3"
|
||||
checksum: 10c0/72fe8f0010ebef848e47faea14a88c6fdc3cdbafaef6b13df4a18c7d33249b1b675e37b05cb90a421700c7016dae7cd4187ab6b549e176a81cea434f69cd2503
|
||||
"@chevrotain/types@npm:11.1.2":
|
||||
version: 11.1.2
|
||||
resolution: "@chevrotain/types@npm:11.1.2"
|
||||
checksum: 10c0/c0c4679a3d407df34e18d5adfa7ac599b4a2bfddbf68da6e43678b9b3e16ab911de7766b37b9fc466261c3dead3db1b620e2e344f800fa9f0f381720475eda8f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@chevrotain/utils@npm:11.0.3":
|
||||
version: 11.0.3
|
||||
resolution: "@chevrotain/utils@npm:11.0.3"
|
||||
checksum: 10c0/b31972d1b2d444eef1499cf9b7576fc1793e8544910de33a3c18e07c270cfad88067f175d0ee63e7bc604713ebed647f8190db45cc8311852cd2d4fe2ef14068
|
||||
"@chevrotain/utils@npm:11.1.2":
|
||||
version: 11.1.2
|
||||
resolution: "@chevrotain/utils@npm:11.1.2"
|
||||
checksum: 10c0/72989e7051781b9084252486712844c55e3b454318c7da4a5f6ded28dcd3947ba2882773a6bf09b7e744599e8c8025df8d3de0d487121734e6edb66999450438
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -3666,7 +3666,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@iconify/utils@npm:^3.0.1":
|
||||
"@iconify/utils@npm:^3.0.2":
|
||||
version: 3.1.0
|
||||
resolution: "@iconify/utils@npm:3.1.0"
|
||||
dependencies:
|
||||
@@ -4389,12 +4389,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@mermaid-js/parser@npm:^0.6.3":
|
||||
version: 0.6.3
|
||||
resolution: "@mermaid-js/parser@npm:0.6.3"
|
||||
"@mermaid-js/parser@npm:^1.0.1":
|
||||
version: 1.0.1
|
||||
resolution: "@mermaid-js/parser@npm:1.0.1"
|
||||
dependencies:
|
||||
langium: "npm:3.3.1"
|
||||
checksum: 10c0/9711174ff31f32d93c8da03ed6b1a1380f5ccfb27ffcdfaf42236da4b381aa0602752b3afc7893582d5ccdfc79b0465c69afe963b825328049575831f4ddd28e
|
||||
langium: "npm:^4.0.0"
|
||||
checksum: 10c0/34231cb63412ddbb3c8c6dba6366b958f98b66293b2e5748d3bd6c286acde47862a6ac86b2f6a33e7b5dee6a1895035af06ee48863c787bc20415b89fe77d705
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -9039,6 +9039,21 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@upsetjs/venn.js@npm:^2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "@upsetjs/venn.js@npm:2.0.0"
|
||||
dependencies:
|
||||
d3-selection: "npm:^3.0.0"
|
||||
d3-transition: "npm:^3.0.1"
|
||||
dependenciesMeta:
|
||||
d3-selection:
|
||||
optional: true
|
||||
d3-transition:
|
||||
optional: true
|
||||
checksum: 10c0/b12014d94708ab4df7f5a4b6205c6f23ff235cca2ffe91df3314862b109b826e52f9020c2a2f7527d3712d21c578d6db9cdb60ce46a528739cc18e58d111f724
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitejs/plugin-react-oxc@npm:^0.2.3":
|
||||
version: 0.2.3
|
||||
resolution: "@vitejs/plugin-react-oxc@npm:0.2.3"
|
||||
@@ -10288,7 +10303,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"chevrotain-allstar@npm:~0.3.0":
|
||||
"chevrotain-allstar@npm:~0.3.1":
|
||||
version: 0.3.1
|
||||
resolution: "chevrotain-allstar@npm:0.3.1"
|
||||
dependencies:
|
||||
@@ -10299,17 +10314,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"chevrotain@npm:~11.0.3":
|
||||
version: 11.0.3
|
||||
resolution: "chevrotain@npm:11.0.3"
|
||||
"chevrotain@npm:~11.1.1":
|
||||
version: 11.1.2
|
||||
resolution: "chevrotain@npm:11.1.2"
|
||||
dependencies:
|
||||
"@chevrotain/cst-dts-gen": "npm:11.0.3"
|
||||
"@chevrotain/gast": "npm:11.0.3"
|
||||
"@chevrotain/regexp-to-ast": "npm:11.0.3"
|
||||
"@chevrotain/types": "npm:11.0.3"
|
||||
"@chevrotain/utils": "npm:11.0.3"
|
||||
lodash-es: "npm:4.17.21"
|
||||
checksum: 10c0/ffd425fa321e3f17e9833d7f44cd39f2743f066e92ca74b226176080ca5d455f853fe9091cdfd86354bd899d85c08b3bdc3f55b267e7d07124b048a88349765f
|
||||
"@chevrotain/cst-dts-gen": "npm:11.1.2"
|
||||
"@chevrotain/gast": "npm:11.1.2"
|
||||
"@chevrotain/regexp-to-ast": "npm:11.1.2"
|
||||
"@chevrotain/types": "npm:11.1.2"
|
||||
"@chevrotain/utils": "npm:11.1.2"
|
||||
lodash-es: "npm:4.17.23"
|
||||
checksum: 10c0/7f0b5780035c582d4c620c81e1fbb58c9f41a69f1c7efdae96819c7bc0928ddb4f046bb8239e71539f383b3b8ce460bd11f44b5fb5107e1d45a0cc91bd6a4198
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -11074,7 +11089,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"cytoscape@npm:^3.29.3":
|
||||
"cytoscape@npm:^3.33.1":
|
||||
version: 3.33.1
|
||||
resolution: "cytoscape@npm:3.33.1"
|
||||
checksum: 10c0/dffcf5f74df4d91517c4faf394df880d8283ce76edef19edba0c762941cf4f18daf7c4c955ec50c794f476ace39ad4394f8c98483222bd2682e1fd206e976411
|
||||
@@ -11318,7 +11333,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"d3-selection@npm:2 - 3, d3-selection@npm:3":
|
||||
"d3-selection@npm:2 - 3, d3-selection@npm:3, d3-selection@npm:^3.0.0":
|
||||
version: 3.0.0
|
||||
resolution: "d3-selection@npm:3.0.0"
|
||||
checksum: 10c0/e59096bbe8f0cb0daa1001d9bdd6dbc93a688019abc97d1d8b37f85cd3c286a6875b22adea0931b0c88410d025563e1643019161a883c516acf50c190a11b56b
|
||||
@@ -11368,7 +11383,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"d3-transition@npm:2 - 3, d3-transition@npm:3":
|
||||
"d3-transition@npm:2 - 3, d3-transition@npm:3, d3-transition@npm:^3.0.1":
|
||||
version: 3.0.1
|
||||
resolution: "d3-transition@npm:3.0.1"
|
||||
dependencies:
|
||||
@@ -11434,13 +11449,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"dagre-d3-es@npm:7.0.13":
|
||||
version: 7.0.13
|
||||
resolution: "dagre-d3-es@npm:7.0.13"
|
||||
"dagre-d3-es@npm:7.0.14":
|
||||
version: 7.0.14
|
||||
resolution: "dagre-d3-es@npm:7.0.14"
|
||||
dependencies:
|
||||
d3: "npm:^7.9.0"
|
||||
lodash-es: "npm:^4.17.21"
|
||||
checksum: 10c0/4eca80dbbad4075311e3853930f99486024785b54210541796d4216140d91744738ee51125e2692c3532af148fbc2e690171750583916ed2ad553150abb198c7
|
||||
checksum: 10c0/0dc91fc79300eb0a4eab5a48a76c2baf3ce439c389d19e2f015729bb57dafd75e1e9a4c2880daf016e81ee45caca7b21745c13b23b6cd2a786ce84767e88323e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -11515,10 +11530,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"dayjs@npm:^1.11.18":
|
||||
version: 1.11.19
|
||||
resolution: "dayjs@npm:1.11.19"
|
||||
checksum: 10c0/7d8a6074a343f821f81ea284d700bd34ea6c7abbe8d93bce7aba818948957c1b7f56131702e5e890a5622cdfc05dcebe8aed0b8313bdc6838a594d7846b0b000
|
||||
"dayjs@npm:^1.11.19":
|
||||
version: 1.11.20
|
||||
resolution: "dayjs@npm:1.11.20"
|
||||
checksum: 10c0/8af525e2aa100c8db9923d706c42b2b2d30579faf89456619413a5c10916efc92c2b166e193c27c02eb3174b30aa440ee1e7b72b0a2876b3da651d204db848a0
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -11833,15 +11848,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"dompurify@npm:^3.2.5":
|
||||
version: 3.3.1
|
||||
resolution: "dompurify@npm:3.3.1"
|
||||
"dompurify@npm:^3.3.1":
|
||||
version: 3.3.3
|
||||
resolution: "dompurify@npm:3.3.3"
|
||||
dependencies:
|
||||
"@types/trusted-types": "npm:^2.0.7"
|
||||
dependenciesMeta:
|
||||
"@types/trusted-types":
|
||||
optional: true
|
||||
checksum: 10c0/fa0a8c55a436ba0d54389195e3d2337e311f56de709a2fc9efc98dbbc7746fa53bb4b74b6ac043b77a279a8f2ebd8685f0ebaa6e58c9e32e92051d529bc0baf8
|
||||
checksum: 10c0/097c14a21a3f6cb95beded9ecd255f7c3512c42767b048390c747b0fe35736f6a71e02320fc50a9ac2be645834b463e4760915d595d502a56452daf339d0ea9c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -15645,7 +15660,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"katex@npm:^0.16.22, katex@npm:^0.16.25":
|
||||
"katex@npm:^0.16.25":
|
||||
version: 0.16.27
|
||||
resolution: "katex@npm:0.16.27"
|
||||
dependencies:
|
||||
@@ -15889,16 +15904,16 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"langium@npm:3.3.1":
|
||||
version: 3.3.1
|
||||
resolution: "langium@npm:3.3.1"
|
||||
"langium@npm:^4.0.0":
|
||||
version: 4.2.1
|
||||
resolution: "langium@npm:4.2.1"
|
||||
dependencies:
|
||||
chevrotain: "npm:~11.0.3"
|
||||
chevrotain-allstar: "npm:~0.3.0"
|
||||
chevrotain: "npm:~11.1.1"
|
||||
chevrotain-allstar: "npm:~0.3.1"
|
||||
vscode-languageserver: "npm:~9.0.1"
|
||||
vscode-languageserver-textdocument: "npm:~1.0.11"
|
||||
vscode-uri: "npm:~3.0.8"
|
||||
checksum: 10c0/0c54803068addb0f7c16a57fdb2db2e5d4d9a21259d477c3c7d0587c2c2f65a313f9eeef3c95ac1c2e41cd11d4f2eaf620d2c03fe839a3350ffee59d2b4c7647
|
||||
vscode-uri: "npm:~3.1.0"
|
||||
checksum: 10c0/19ddf79cc3c435ec70f8eb50de255571711db7cea89d171cf80bc97e7ed73d4d0bb6b4215899df8369fa6d0e17f442f30af4ec2e9657041bf2f93be1310ba50a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -16225,10 +16240,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"lodash-es@npm:4.17.21, lodash-es@npm:^4.17.21":
|
||||
version: 4.17.21
|
||||
resolution: "lodash-es@npm:4.17.21"
|
||||
checksum: 10c0/fb407355f7e6cd523a9383e76e6b455321f0f153a6c9625e21a8827d10c54c2a2341bd2ae8d034358b60e07325e1330c14c224ff582d04612a46a4f0479ff2f2
|
||||
"lodash-es@npm:4.17.23, lodash-es@npm:^4.17.21, lodash-es@npm:^4.17.23":
|
||||
version: 4.17.23
|
||||
resolution: "lodash-es@npm:4.17.23"
|
||||
checksum: 10c0/3150fb6660c14c7a6b5f23bd11597d884b140c0e862a17fdb415aaa5ef7741523182904a6b7929f04e5f60a11edb5a79499eb448734381c99ffb3c4734beeddd
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -16598,7 +16613,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"marked@npm:^16.2.1":
|
||||
"marked@npm:^16.3.0":
|
||||
version: 16.4.2
|
||||
resolution: "marked@npm:16.4.2"
|
||||
bin:
|
||||
@@ -16673,31 +16688,32 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"mermaid@npm:11.12.1":
|
||||
version: 11.12.1
|
||||
resolution: "mermaid@npm:11.12.1"
|
||||
"mermaid@npm:11.13.0":
|
||||
version: 11.13.0
|
||||
resolution: "mermaid@npm:11.13.0"
|
||||
dependencies:
|
||||
"@braintree/sanitize-url": "npm:^7.1.1"
|
||||
"@iconify/utils": "npm:^3.0.1"
|
||||
"@mermaid-js/parser": "npm:^0.6.3"
|
||||
"@iconify/utils": "npm:^3.0.2"
|
||||
"@mermaid-js/parser": "npm:^1.0.1"
|
||||
"@types/d3": "npm:^7.4.3"
|
||||
cytoscape: "npm:^3.29.3"
|
||||
"@upsetjs/venn.js": "npm:^2.0.0"
|
||||
cytoscape: "npm:^3.33.1"
|
||||
cytoscape-cose-bilkent: "npm:^4.1.0"
|
||||
cytoscape-fcose: "npm:^2.2.0"
|
||||
d3: "npm:^7.9.0"
|
||||
d3-sankey: "npm:^0.12.3"
|
||||
dagre-d3-es: "npm:7.0.13"
|
||||
dayjs: "npm:^1.11.18"
|
||||
dompurify: "npm:^3.2.5"
|
||||
katex: "npm:^0.16.22"
|
||||
dagre-d3-es: "npm:7.0.14"
|
||||
dayjs: "npm:^1.11.19"
|
||||
dompurify: "npm:^3.3.1"
|
||||
katex: "npm:^0.16.25"
|
||||
khroma: "npm:^2.1.0"
|
||||
lodash-es: "npm:^4.17.21"
|
||||
marked: "npm:^16.2.1"
|
||||
lodash-es: "npm:^4.17.23"
|
||||
marked: "npm:^16.3.0"
|
||||
roughjs: "npm:^4.6.6"
|
||||
stylis: "npm:^4.3.6"
|
||||
ts-dedent: "npm:^2.2.0"
|
||||
uuid: "npm:^11.1.0"
|
||||
checksum: 10c0/0dd07a5986bb25ca038f68f7a187a0b6ccf5fa8c738603c3145bd4b6289d50312053818f52617cf575a6652e6c57809ae115c016725f7ce446496be5971a150a
|
||||
checksum: 10c0/9d908314d26cdb23d8fbb6a1183f3dc48440efa2cf25f31fd5f75ef3f72e973ef7c3b77768eb8399898035366d2b4a3a2bf0a0de9e35757848754935bf1288c0
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -17734,7 +17750,7 @@ __metadata:
|
||||
markdown-it: "npm:^14.1.0"
|
||||
markdown-it-container: "npm:^3.0.0"
|
||||
markdown-it-emoji: "npm:^3.0.0"
|
||||
mermaid: "npm:11.12.1"
|
||||
mermaid: "npm:11.13.0"
|
||||
mime-types: "npm:^3.0.1"
|
||||
mobx: "npm:^4.15.4"
|
||||
mobx-react: "npm:^6.3.1"
|
||||
@@ -22534,10 +22550,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"vscode-uri@npm:~3.0.8":
|
||||
version: 3.0.8
|
||||
resolution: "vscode-uri@npm:3.0.8"
|
||||
checksum: 10c0/f7f217f526bf109589969fe6e66b71e70b937de1385a1d7bb577ca3ee7c5e820d3856a86e9ff2fa9b7a0bc56a3dd8c3a9a557d3fedd7df414bc618d5e6b567f9
|
||||
"vscode-uri@npm:~3.1.0":
|
||||
version: 3.1.0
|
||||
resolution: "vscode-uri@npm:3.1.0"
|
||||
checksum: 10c0/5f6c9c10fd9b1664d71fab4e9fbbae6be93c7f75bb3a1d9d74399a88ab8649e99691223fd7cef4644376cac6e94fa2c086d802521b9a8e31c5af3e60f0f35624
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in new issue
Block a user