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

Function putImpl

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

Source from the content-addressed store, hash-verified

1545 .pipe(Effect.map((row) => (row ? pluginStorageEntryFromRow<T>(row) : null)));
1546
1547 const putImpl = <T>(owner: Owner, collection: string, key: string, data: unknown) =>
1548 Effect.gen(function* () {
1549 const os = ownerSubject(owner);
1550 if (!os) {
1551 return yield* new StorageError({
1552 message: `Cannot write plugin storage for owner "user": executor has no subject.`,
1553 cause: undefined,
1554 });
1555 }
1556 const existing = yield* input.core.findFirst("plugin_storage", {
1557 where: whereOwner(owner, collection, key),
1558 });
1559 const now = new Date();
1560 if (existing) {
1561 yield* input.core.updateMany("plugin_storage", {
1562 where: whereOwner(owner, collection, key),
1563 set: { data, updated_at: now },
1564 });
1565 return pluginStorageEntryFromRow<T>({
1566 ...existing,
1567 data,
1568 updated_at: now,
1569 });
1570 }
1571 const created = yield* input.core.create("plugin_storage", {
1572 tenant,
1573 owner: os.owner,
1574 subject: os.subject,
1575 plugin_id: input.pluginId,
1576 collection,
1577 key,
1578 data,
1579 created_at: now,
1580 updated_at: now,
1581 });
1582 return pluginStorageEntryFromRow<T>(created);
1583 });
1584
1585 const removeImpl = (owner: Owner, collection: string, key: string) =>
1586 Effect.gen(function* () {

Callers 1

makePluginStorageFacadeFunction · 0.85

Calls 3

whereOwnerFunction · 0.85
ownerSubjectFunction · 0.70

Tested by

no test coverage detected