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

Function putManyImpl

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

1331 });
1332
1333 const putManyImpl = (
1334 owner: Owner,
1335 entries: readonly {
1336 readonly collection: string;
1337 readonly key: string;
1338 readonly data: unknown;
1339 }[],
1340 ) =>
1341 Effect.gen(function* () {
1342 const os = ownerSubject(owner);
1343 if (!os) {
1344 return yield* new StorageError({
1345 message: `Cannot write plugin storage for owner "user": executor has no subject.`,
1346 cause: undefined,
1347 });
1348 }
1349 const entriesById = new Map(
1350 entries.map((entry) => [
1351 pluginStorageId({
1352 pluginId: input.pluginId,
1353 collection: entry.collection,
1354 key: entry.key,
1355 }),
1356 entry,
1357 ]),
1358 );
1359 const uniqueEntries = [...entriesById.values()];
1360 if (uniqueEntries.length === 0) return;
1361
1362 yield* deleteManyImpl(owner, os.subject, uniqueEntries);
1363
1364 const now = new Date();
1365 for (
1366 let offset = 0;
1367 offset < uniqueEntries.length;
1368 offset += PLUGIN_STORAGE_CREATE_ROW_BATCH_SIZE
1369 ) {
1370 const batchEntries = uniqueEntries.slice(
1371 offset,
1372 offset + PLUGIN_STORAGE_CREATE_ROW_BATCH_SIZE,
1373 );
1374 yield* input.core.createMany(
1375 "plugin_storage",
1376 batchEntries.map((entry) => ({
1377 tenant,
1378 owner: os.owner,
1379 subject: os.subject,
1380 plugin_id: input.pluginId,
1381 collection: entry.collection,
1382 key: entry.key,
1383 data: entry.data,
1384 created_at: now,
1385 updated_at: now,
1386 })),
1387 );
1388 }
1389 });
1390

Callers 1

makePluginStorageFacadeFunction · 0.85

Calls 4

pluginStorageIdFunction · 0.90
deleteManyImplFunction · 0.85
valuesMethod · 0.80
ownerSubjectFunction · 0.70

Tested by

no test coverage detected