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

Function putImpl

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

Source from the content-addressed store, hash-verified

1484 .pipe(Effect.map((row) => (row ? pluginStorageEntryFromRow<T>(row) : null)));
1485
1486 const putImpl = <T>(owner: Owner, collection: string, key: string, data: unknown) =>
1487 Effect.gen(function* () {
1488 const os = ownerSubject(owner);
1489 if (!os) {
1490 return yield* new StorageError({
1491 message: `Cannot write plugin storage for owner "user": executor has no subject.`,
1492 cause: undefined,
1493 });
1494 }
1495 const existing = yield* input.core.findFirst("plugin_storage", {
1496 where: whereOwner(owner, collection, key),
1497 });
1498 const now = new Date();
1499 if (existing) {
1500 yield* input.core.updateMany("plugin_storage", {
1501 where: whereOwner(owner, collection, key),
1502 set: { data, updated_at: now },
1503 });
1504 return pluginStorageEntryFromRow<T>({
1505 ...existing,
1506 data,
1507 updated_at: now,
1508 });
1509 }
1510 const created = yield* input.core.create("plugin_storage", {
1511 tenant,
1512 owner: os.owner,
1513 subject: os.subject,
1514 plugin_id: input.pluginId,
1515 collection,
1516 key,
1517 data,
1518 created_at: now,
1519 updated_at: now,
1520 });
1521 return pluginStorageEntryFromRow<T>(created);
1522 });
1523
1524 const removeImpl = (owner: Owner, collection: string, key: string) =>
1525 Effect.gen(function* () {

Callers 1

makePluginStorageFacadeFunction · 0.85

Calls 3

whereOwnerFunction · 0.85
ownerSubjectFunction · 0.70

Tested by

no test coverage detected