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

Function pushToTypesense

packages/typesense/src/utils/shared.ts:108–162  ·  view source on GitHub ↗
({
  threads,
  is_restrict,
  logger,
  anonymize,
}: {
  threads: (threads & {
    messages: (messages & {
      author: users | null;
      reactions: messageReactions[];
      attachments: messageAttachments[];
      mentions: (mentions & {
        users: users | null;
      })[];
    })[];
    channel: channels & {
      memberships: {
        usersId: string;
        user: {
          authsId: string | null;
        };
      }[];
    };
  })[];
  is_restrict: boolean;
  logger: Logger;
  anonymize?: AnonymizeType;
})

Source from the content-addressed store, hash-verified

106}
107
108export async function pushToTypesense({
109 threads,
110 is_restrict,
111 logger,
112 anonymize,
113}: {
114 threads: (threads & {
115 messages: (messages & {
116 author: users | null;
117 reactions: messageReactions[];
118 attachments: messageAttachments[];
119 mentions: (mentions & {
120 users: users | null;
121 })[];
122 })[];
123 channel: channels & {
124 memberships: {
125 usersId: string;
126 user: {
127 authsId: string | null;
128 };
129 }[];
130 };
131 })[];
132 is_restrict: boolean;
133 logger: Logger;
134 anonymize?: AnonymizeType;
135}) {
136 const documents = threads
137 .map((t) =>
138 serializer({
139 thread: serializeThread(
140 anonymize ? anonymizeMessages(t, anonymize) : t
141 ),
142 is_public: t.channel.type === 'PUBLIC',
143 is_restrict,
144 accessible_to: t.channel.memberships
145 .filter((m) => !!m.user.authsId)
146 .map((m) => m.usersId),
147 })
148 )
149 .filter((t) => !!t.body);
150
151 await client
152 .collections(collectionSchema.name)
153 .documents()
154 .import(documents, { action: 'upsert' })
155 .catch((error: any) => {
156 logger.error(
157 error.importResults
158 ?.filter((result: any) => !result.success)
159 ?.map((result: any) => result.error) || error
160 );
161 });
162}
163
164export async function createUserKeyAndPersist({
165 account,

Callers 6

handleDeletionFunction · 0.90
processQueryFunction · 0.90
handleMessageCreationFunction · 0.90
syncUpdatedThreadsFunction · 0.90
setupFunction · 0.90
handleChannelNameUpdateFunction · 0.90

Calls 5

serializerFunction · 0.90
serializeThreadFunction · 0.90
anonymizeMessagesFunction · 0.90
mapMethod · 0.80
errorMethod · 0.65

Tested by

no test coverage detected