MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / makeToolkitsExtension

Function makeToolkitsExtension

packages/plugins/toolkits/src/server.ts:231–565  ·  view source on GitHub ↗
(ctx: PluginCtx<ToolkitStorage>)

Source from the content-addressed store, hash-verified

229});
230
231const makeToolkitsExtension = (ctx: PluginCtx<ToolkitStorage>) => {
232 const storage = ctx.storage;
233
234 const list = () =>
235 storage.toolkits
236 .query({ orderBy: [{ field: "name" }] })
237 .pipe(
238 Effect.map((entries) =>
239 entries
240 .map(toolkitToResponse)
241 .sort(
242 (a, b) =>
243 (a.owner === b.owner ? 0 : a.owner === "org" ? -1 : 1) ||
244 a.name.localeCompare(b.name) ||
245 a.slug.localeCompare(b.slug),
246 ),
247 ),
248 );
249
250 const getEntry = (toolkitId: string) => storage.toolkits.get({ key: toolkitId });
251
252 const getBySlugEntry = (slug: string) =>
253 storage.toolkits
254 .query({ where: { slug } })
255 .pipe(
256 Effect.map(
257 (entries) => entries.find((entry) => entry.owner === "org") ?? entries[0] ?? null,
258 ),
259 );
260
261 const requireToolkit = (toolkitId: string) =>
262 getEntry(toolkitId).pipe(
263 Effect.flatMap((entry) => (entry ? Effect.succeed(entry) : fail("Toolkit not found."))),
264 );
265
266 const assertSlugAvailable = (slug: string, ignoreToolkitId?: string) =>
267 storage.toolkits.query({ where: { slug } }).pipe(
268 Effect.flatMap((entries) => {
269 const collision = entries.find((entry) => entry.data.id !== ignoreToolkitId);
270 return collision ? fail(`Toolkit slug "${slug}" is already in use.`) : Effect.void;
271 }),
272 );
273
274 const listPoliciesForRecord = (toolkitId: string) =>
275 storage.policies
276 .query({ where: { toolkitId } })
277 .pipe(Effect.map((entries) => entries.map((entry) => entry.data).sort(comparePositioned)));
278
279 const listConnectionsForRecord = (toolkitId: string) =>
280 storage.connections
281 .query({ where: { toolkitId } })
282 .pipe(Effect.map((entries) => entries.map((entry) => entry.data).sort(comparePositioned)));
283
284 const requirePolicy = (toolkitId: string, policyId: string, owner: Owner) =>
285 storage.policies
286 .getForOwner({ owner, key: policyId })
287 .pipe(
288 Effect.flatMap((entry) =>

Callers 1

server.tsFile · 0.85

Calls 2

listPoliciesFunction · 0.85
listConnectionsFunction · 0.85

Tested by

no test coverage detected