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

Function putManyImpl

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

1454 });
1455
1456 const putManyImpl = (
1457 owner: Owner,
1458 entries: readonly {
1459 readonly collection: string;
1460 readonly key: string;
1461 readonly data: unknown;
1462 }[],
1463 ) =>
1464 input.core.transaction(
1465 Effect.gen(function* () {
1466 const os = ownerSubject(owner);
1467 if (!os) {
1468 return yield* new StorageError({
1469 message: `Cannot write plugin storage for owner "user": executor has no subject.`,
1470 cause: undefined,
1471 });
1472 }
1473 const entriesById = new Map(
1474 entries.map((entry) => [
1475 pluginStorageId({
1476 pluginId: input.pluginId,
1477 collection: entry.collection,
1478 key: entry.key,
1479 }),
1480 entry,
1481 ]),
1482 );
1483 const uniqueEntries = [...entriesById.values()];
1484 if (uniqueEntries.length === 0) return;
1485
1486 const now = new Date();
1487 yield* input.core.upsertMany("plugin_storage", {
1488 target: ["tenant", "owner", "subject", "plugin_id", "collection", "key"],
1489 update: ["data", "updated_at"],
1490 values: uniqueEntries.map((entry) => ({
1491 tenant,
1492 owner: os.owner,
1493 subject: os.subject,
1494 plugin_id: input.pluginId,
1495 collection: entry.collection,
1496 key: entry.key,
1497 data: entry.data,
1498 created_at: now,
1499 updated_at: now,
1500 })),
1501 });
1502 }),
1503 );
1504
1505 const removeManyImpl = (
1506 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