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

Function putManyImpl

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

1579 });
1580
1581 const putManyImpl = (
1582 owner: Owner,
1583 entries: readonly {
1584 readonly collection: string;
1585 readonly key: string;
1586 readonly data: unknown;
1587 }[],
1588 ) =>
1589 input.core.transaction(
1590 Effect.gen(function* () {
1591 const os = ownerSubject(owner);
1592 if (!os) {
1593 return yield* new StorageError({
1594 message: `Cannot write plugin storage for owner "user": executor has no subject.`,
1595 cause: undefined,
1596 });
1597 }
1598 const entriesById = new Map(
1599 entries.map((entry) => [
1600 pluginStorageId({
1601 pluginId: input.pluginId,
1602 collection: entry.collection,
1603 key: entry.key,
1604 }),
1605 entry,
1606 ]),
1607 );
1608 const uniqueEntries = [...entriesById.values()];
1609 if (uniqueEntries.length === 0) return;
1610
1611 const now = new Date();
1612 yield* input.core.upsertMany("plugin_storage", {
1613 target: ["tenant", "owner", "subject", "plugin_id", "collection", "key"],
1614 update: ["data", "updated_at"],
1615 values: uniqueEntries.map((entry) => ({
1616 tenant,
1617 owner: os.owner,
1618 subject: os.subject,
1619 plugin_id: input.pluginId,
1620 collection: entry.collection,
1621 key: entry.key,
1622 data: entry.data,
1623 created_at: now,
1624 updated_at: now,
1625 })),
1626 });
1627 }),
1628 );
1629
1630 const removeManyImpl = (
1631 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