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

Function putManyImpl

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

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

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