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

Function putManyImpl

packages/core/sdk/src/executor.ts:1675–1722  ·  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

1673 });
1674
1675 const putManyImpl = (
1676 owner: Owner,
1677 entries: readonly {
1678 readonly collection: string;
1679 readonly key: string;
1680 readonly data: unknown;
1681 }[],
1682 ) =>
1683 input.core.transaction(
1684 Effect.gen(function* () {
1685 const os = ownerSubject(owner);
1686 if (!os) {
1687 return yield* new StorageError({
1688 message: `Cannot write plugin storage for owner "user": executor has no subject.`,
1689 cause: undefined,
1690 });
1691 }
1692 const entriesById = new Map(
1693 entries.map((entry) => [
1694 pluginStorageId({
1695 pluginId: input.pluginId,
1696 collection: entry.collection,
1697 key: entry.key,
1698 }),
1699 entry,
1700 ]),
1701 );
1702 const uniqueEntries = [...entriesById.values()];
1703 if (uniqueEntries.length === 0) return;
1704
1705 const now = new Date();
1706 yield* input.core.upsertMany("plugin_storage", {
1707 target: ["tenant", "owner", "subject", "plugin_id", "collection", "key"],
1708 update: ["data", "updated_at"],
1709 values: uniqueEntries.map((entry) => ({
1710 tenant,
1711 owner: os.owner,
1712 subject: os.subject,
1713 plugin_id: input.pluginId,
1714 collection: entry.collection,
1715 key: entry.key,
1716 data: entry.data,
1717 created_at: now,
1718 updated_at: now,
1719 })),
1720 });
1721 }),
1722 );
1723
1724 const removeManyImpl = (
1725 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