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

Function putImpl

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

Source from the content-addressed store, hash-verified

1564 .pipe(Effect.map((row) => (row ? pluginStorageEntryFromRow<T>(row) : null)));
1565
1566 const putImpl = <T>(owner: Owner, collection: string, key: string, data: unknown) =>
1567 Effect.gen(function* () {
1568 const os = ownerSubject(owner);
1569 if (!os) {
1570 return yield* new StorageError({
1571 message: `Cannot write plugin storage for owner "user": executor has no subject.`,
1572 cause: undefined,
1573 });
1574 }
1575 const existing = yield* input.core.findFirst("plugin_storage", {
1576 where: whereOwner(owner, collection, key),
1577 });
1578 const now = new Date();
1579 if (existing) {
1580 yield* input.core.updateMany("plugin_storage", {
1581 where: whereOwner(owner, collection, key),
1582 set: { data, updated_at: now },
1583 });
1584 return pluginStorageEntryFromRow<T>({
1585 ...existing,
1586 data,
1587 updated_at: now,
1588 });
1589 }
1590 const created = yield* input.core.create("plugin_storage", {
1591 tenant,
1592 owner: os.owner,
1593 subject: os.subject,
1594 plugin_id: input.pluginId,
1595 collection,
1596 key,
1597 data,
1598 created_at: now,
1599 updated_at: now,
1600 });
1601 return pluginStorageEntryFromRow<T>(created);
1602 });
1603
1604 const removeImpl = (owner: Owner, collection: string, key: string) =>
1605 Effect.gen(function* () {

Callers 1

makePluginStorageFacadeFunction · 0.85

Calls 3

whereOwnerFunction · 0.85
ownerSubjectFunction · 0.70

Tested by

no test coverage detected