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

Function pluginBlobStore

packages/core/sdk/src/blob.ts:78–123  ·  view source on GitHub ↗
(
  store: BlobStore,
  partitions: OwnerPartitions,
  pluginId: string,
)

Source from the content-addressed store, hash-verified

76 * executor to build the `blobs` field handed to each plugin's `storage` factory.
77 */
78export const pluginBlobStore = (
79 store: BlobStore,
80 partitions: OwnerPartitions,
81 pluginId: string,
82): PluginBlobStore => {
83 const readNamespaces = (): readonly string[] =>
84 (partitions.user == null ? [partitions.org] : [partitions.user, partitions.org]).map((p) =>
85 nsFor(p, pluginId),
86 );
87
88 const partitionFor = (owner: Owner): Effect.Effect<string, StorageError> => {
89 if (owner === "org") return Effect.succeed(partitions.org);
90 if (partitions.user == null) {
91 return Effect.fail(
92 new StorageError({
93 message: 'Blob write targets owner "user" but the executor has no subject.',
94 cause: undefined,
95 }),
96 );
97 }
98 return Effect.succeed(partitions.user);
99 };
100
101 return {
102 get: (key) =>
103 Effect.gen(function* () {
104 const namespaces = readNamespaces();
105 const hits = yield* store.getMany(namespaces, key);
106 if (hits.size === 0) return null;
107 for (const ns of namespaces) {
108 const v = hits.get(ns);
109 if (v !== undefined) return v;
110 }
111 return null;
112 }),
113 put: (key, value, options) =>
114 Effect.flatMap(partitionFor(options.owner), (partition) =>
115 store.put(nsFor(partition, pluginId), key, value),
116 ),
117 delete: (key, options) =>
118 Effect.flatMap(partitionFor(options.owner), (partition) =>
119 store.delete(nsFor(partition, pluginId), key),
120 ),
121 has: (key) => store.getMany(readNamespaces(), key).pipe(Effect.map((hits) => hits.size > 0)),
122 };
123};
124
125/**
126 * Minimal in-memory BlobStore — good for tests and trivial hosts. Real

Callers 4

createExecutorFunction · 0.90
blob.test.tsFile · 0.90
blob-store.test.tsFile · 0.90
store.test.tsFile · 0.90

Calls 6

readNamespacesFunction · 0.85
partitionForFunction · 0.85
nsForFunction · 0.85
getMethod · 0.65
putMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected