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

Function makeToolkitsExtension

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

Source from the content-addressed store, hash-verified

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

Callers 1

server.tsFile · 0.85

Calls 2

listPoliciesFunction · 0.85
listConnectionsFunction · 0.85

Tested by

no test coverage detected