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

Function putImpl

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

Source from the content-addressed store, hash-verified

1198 .pipe(Effect.map((row) => (row ? pluginStorageEntryFromRow<T>(row) : null)));
1199
1200 const putImpl = <T>(owner: Owner, collection: string, key: string, data: unknown) =>
1201 Effect.gen(function* () {
1202 const os = ownerSubject(owner);
1203 if (!os) {
1204 return yield* new StorageError({
1205 message: `Cannot write plugin storage for owner "user": executor has no subject.`,
1206 cause: undefined,
1207 });
1208 }
1209 const existing = yield* input.core.findFirst("plugin_storage", {
1210 where: whereOwner(owner, collection, key),
1211 });
1212 const now = new Date();
1213 if (existing) {
1214 yield* input.core.updateMany("plugin_storage", {
1215 where: whereOwner(owner, collection, key),
1216 set: { data, updated_at: now },
1217 });
1218 return pluginStorageEntryFromRow<T>({
1219 ...existing,
1220 data,
1221 updated_at: now,
1222 });
1223 }
1224 const created = yield* input.core.create("plugin_storage", {
1225 tenant,
1226 owner: os.owner,
1227 subject: os.subject,
1228 plugin_id: input.pluginId,
1229 collection,
1230 key,
1231 data,
1232 created_at: now,
1233 updated_at: now,
1234 });
1235 return pluginStorageEntryFromRow<T>(created);
1236 });
1237
1238 const removeImpl = (owner: Owner, collection: string, key: string) =>
1239 Effect.gen(function* () {

Callers 1

makePluginStorageFacadeFunction · 0.85

Calls 3

whereOwnerFunction · 0.85
ownerSubjectFunction · 0.70

Tested by

no test coverage detected