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

Function putImpl

packages/core/sdk/src/executor.ts:1186–1222  ·  view source on GitHub ↗
(owner: Owner, collection: string, key: string, data: unknown)

Source from the content-addressed store, hash-verified

1184 .pipe(Effect.map((row) => (row ? pluginStorageEntryFromRow<T>(row) : null)));
1185
1186 const putImpl = <T>(owner: Owner, collection: string, key: string, data: unknown) =>
1187 Effect.gen(function* () {
1188 const os = ownerSubject(owner);
1189 if (!os) {
1190 return yield* new StorageError({
1191 message: `Cannot write plugin storage for owner "user": executor has no subject.`,
1192 cause: undefined,
1193 });
1194 }
1195 const existing = yield* input.core.findFirst("plugin_storage", {
1196 where: whereOwner(owner, collection, key),
1197 });
1198 const now = new Date();
1199 if (existing) {
1200 yield* input.core.updateMany("plugin_storage", {
1201 where: whereOwner(owner, collection, key),
1202 set: { data, updated_at: now },
1203 });
1204 return pluginStorageEntryFromRow<T>({
1205 ...existing,
1206 data,
1207 updated_at: now,
1208 });
1209 }
1210 const created = yield* input.core.create("plugin_storage", {
1211 tenant,
1212 owner: os.owner,
1213 subject: os.subject,
1214 plugin_id: input.pluginId,
1215 collection,
1216 key,
1217 data,
1218 created_at: now,
1219 updated_at: now,
1220 });
1221 return pluginStorageEntryFromRow<T>(created);
1222 });
1223
1224 const removeImpl = (owner: Owner, collection: string, key: string) =>
1225 Effect.gen(function* () {

Callers 1

makePluginStorageFacadeFunction · 0.85

Calls 3

whereOwnerFunction · 0.85
ownerSubjectFunction · 0.70

Tested by

no test coverage detected