MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / setup

Function setup

packages/typesense/src/setup.ts:17–87  ·  view source on GitHub ↗
({
  accountId,
  logger,
}: {
  accountId: string;
  logger: Logger;
})

Source from the content-addressed store, hash-verified

15import { env } from './utils/env';
16
17export async function setup({
18 accountId,
19 logger,
20}: {
21 accountId: string;
22 logger: Logger;
23}) {
24 const account = await prisma.accounts.findUnique({
25 where: {
26 id: accountId,
27 },
28 });
29
30 if (!account) {
31 throw new Error(`account not found: ${accountId}`);
32 }
33
34 const isPublic = account.type === 'PUBLIC';
35
36 const key = isPublic
37 ? createAccountKey({
38 keyWithSearchPermissions: env.TYPESENSE_SEARCH_ONLY,
39 accountId: account.id,
40 })
41 : undefined;
42
43 const searchSettings: SerializedSearchSettings = {
44 engine: 'typesense',
45 scope: isPublic ? 'public' : 'private',
46 apiKey: key?.value || 'private',
47 apiKeyExpiresAt: key?.expires_at,
48 };
49
50 let cursor = 0;
51 do {
52 const threads = await queryThreads({
53 where: {
54 ...threadsWhere({ accountId }),
55 incrementId: { gt: cursor },
56 },
57 orderBy: { incrementId: 'asc' },
58 take: 50,
59 });
60
61 if (!threads.length) {
62 break;
63 }
64
65 cursor = threads.at(threads.length - 1)?.incrementId!;
66
67 await pushToTypesense({
68 threads,
69 is_restrict: searchSettings.scope === 'private',
70 logger,
71 anonymize: account.anonymizeUsers
72 ? (account.anonymize as AnonymizeType)
73 : undefined,
74 });

Calls 6

createAccountKeyFunction · 0.90
queryThreadsFunction · 0.90
threadsWhereFunction · 0.90
pushToTypesenseFunction · 0.90
persistEndFlagFunction · 0.90
createUserKeyAndPersistFunction · 0.90

Tested by

no test coverage detected