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