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

Function putManyImpl

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

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

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