(owner: Owner, collection: string, key: string, data: unknown)
| 1359 | .pipe(Effect.map((row) => (row ? pluginStorageEntryFromRow<T>(row) : null))); |
| 1360 | |
| 1361 | const putImpl = <T>(owner: Owner, collection: string, key: string, data: unknown) => |
| 1362 | Effect.gen(function* () { |
| 1363 | const os = ownerSubject(owner); |
| 1364 | if (!os) { |
| 1365 | return yield* new StorageError({ |
| 1366 | message: `Cannot write plugin storage for owner "user": executor has no subject.`, |
| 1367 | cause: undefined, |
| 1368 | }); |
| 1369 | } |
| 1370 | const existing = yield* input.core.findFirst("plugin_storage", { |
| 1371 | where: whereOwner(owner, collection, key), |
| 1372 | }); |
| 1373 | const now = new Date(); |
| 1374 | if (existing) { |
| 1375 | yield* input.core.updateMany("plugin_storage", { |
| 1376 | where: whereOwner(owner, collection, key), |
| 1377 | set: { data, updated_at: now }, |
| 1378 | }); |
| 1379 | return pluginStorageEntryFromRow<T>({ |
| 1380 | ...existing, |
| 1381 | data, |
| 1382 | updated_at: now, |
| 1383 | }); |
| 1384 | } |
| 1385 | const created = yield* input.core.create("plugin_storage", { |
| 1386 | tenant, |
| 1387 | owner: os.owner, |
| 1388 | subject: os.subject, |
| 1389 | plugin_id: input.pluginId, |
| 1390 | collection, |
| 1391 | key, |
| 1392 | data, |
| 1393 | created_at: now, |
| 1394 | updated_at: now, |
| 1395 | }); |
| 1396 | return pluginStorageEntryFromRow<T>(created); |
| 1397 | }); |
| 1398 | |
| 1399 | const removeImpl = (owner: Owner, collection: string, key: string) => |
| 1400 | Effect.gen(function* () { |
no test coverage detected