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

Function putManyImpl

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

1292 });
1293
1294 const putManyImpl = (
1295 owner: Owner,
1296 entries: readonly {
1297 readonly collection: string;
1298 readonly key: string;
1299 readonly data: unknown;
1300 }[],
1301 ) =>
1302 Effect.gen(function* () {
1303 const os = ownerSubject(owner);
1304 if (!os) {
1305 return yield* new StorageError({
1306 message: `Cannot write plugin storage for owner "user": executor has no subject.`,
1307 cause: undefined,
1308 });
1309 }
1310 const entriesById = new Map(
1311 entries.map((entry) => [
1312 pluginStorageId({
1313 pluginId: input.pluginId,
1314 collection: entry.collection,
1315 key: entry.key,
1316 }),
1317 entry,
1318 ]),
1319 );
1320 const uniqueEntries = [...entriesById.values()];
1321 if (uniqueEntries.length === 0) return;
1322
1323 yield* deleteManyImpl(owner, os.subject, uniqueEntries);
1324
1325 const now = new Date();
1326 for (
1327 let offset = 0;
1328 offset < uniqueEntries.length;
1329 offset += PLUGIN_STORAGE_CREATE_ROW_BATCH_SIZE
1330 ) {
1331 const batchEntries = uniqueEntries.slice(
1332 offset,
1333 offset + PLUGIN_STORAGE_CREATE_ROW_BATCH_SIZE,
1334 );
1335 yield* input.core.createMany(
1336 "plugin_storage",
1337 batchEntries.map((entry) => ({
1338 tenant,
1339 owner: os.owner,
1340 subject: os.subject,
1341 plugin_id: input.pluginId,
1342 collection: entry.collection,
1343 key: entry.key,
1344 data: entry.data,
1345 created_at: now,
1346 updated_at: now,
1347 })),
1348 );
1349 }
1350 });
1351

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