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

Function putManyImpl

packages/core/sdk/src/executor.ts:1661–1708  ·  view source on GitHub ↗
(
    owner: Owner,
    entries: readonly {
      readonly collection: string;
      readonly key: string;
      readonly data: unknown;
    }[],
  )

Source from the content-addressed store, hash-verified

1659 });
1660
1661 const putManyImpl = (
1662 owner: Owner,
1663 entries: readonly {
1664 readonly collection: string;
1665 readonly key: string;
1666 readonly data: unknown;
1667 }[],
1668 ) =>
1669 input.core.transaction(
1670 Effect.gen(function* () {
1671 const os = ownerSubject(owner);
1672 if (!os) {
1673 return yield* new StorageError({
1674 message: `Cannot write plugin storage for owner "user": executor has no subject.`,
1675 cause: undefined,
1676 });
1677 }
1678 const entriesById = new Map(
1679 entries.map((entry) => [
1680 pluginStorageId({
1681 pluginId: input.pluginId,
1682 collection: entry.collection,
1683 key: entry.key,
1684 }),
1685 entry,
1686 ]),
1687 );
1688 const uniqueEntries = [...entriesById.values()];
1689 if (uniqueEntries.length === 0) return;
1690
1691 const now = new Date();
1692 yield* input.core.upsertMany("plugin_storage", {
1693 target: ["tenant", "owner", "subject", "plugin_id", "collection", "key"],
1694 update: ["data", "updated_at"],
1695 values: uniqueEntries.map((entry) => ({
1696 tenant,
1697 owner: os.owner,
1698 subject: os.subject,
1699 plugin_id: input.pluginId,
1700 collection: entry.collection,
1701 key: entry.key,
1702 data: entry.data,
1703 created_at: now,
1704 updated_at: now,
1705 })),
1706 });
1707 }),
1708 );
1709
1710 const removeManyImpl = (
1711 owner: Owner,

Callers 1

makePluginStorageFacadeFunction · 0.85

Calls 4

pluginStorageIdFunction · 0.90
valuesMethod · 0.80
ownerSubjectFunction · 0.70
transactionMethod · 0.65

Tested by

no test coverage detected