(owner: Owner, collection: string, key: string, data: unknown)
| 1484 | .pipe(Effect.map((row) => (row ? pluginStorageEntryFromRow<T>(row) : null))); |
| 1485 | |
| 1486 | const putImpl = <T>(owner: Owner, collection: string, key: string, data: unknown) => |
| 1487 | Effect.gen(function* () { |
| 1488 | const os = ownerSubject(owner); |
| 1489 | if (!os) { |
| 1490 | return yield* new StorageError({ |
| 1491 | message: `Cannot write plugin storage for owner "user": executor has no subject.`, |
| 1492 | cause: undefined, |
| 1493 | }); |
| 1494 | } |
| 1495 | const existing = yield* input.core.findFirst("plugin_storage", { |
| 1496 | where: whereOwner(owner, collection, key), |
| 1497 | }); |
| 1498 | const now = new Date(); |
| 1499 | if (existing) { |
| 1500 | yield* input.core.updateMany("plugin_storage", { |
| 1501 | where: whereOwner(owner, collection, key), |
| 1502 | set: { data, updated_at: now }, |
| 1503 | }); |
| 1504 | return pluginStorageEntryFromRow<T>({ |
| 1505 | ...existing, |
| 1506 | data, |
| 1507 | updated_at: now, |
| 1508 | }); |
| 1509 | } |
| 1510 | const created = yield* input.core.create("plugin_storage", { |
| 1511 | tenant, |
| 1512 | owner: os.owner, |
| 1513 | subject: os.subject, |
| 1514 | plugin_id: input.pluginId, |
| 1515 | collection, |
| 1516 | key, |
| 1517 | data, |
| 1518 | created_at: now, |
| 1519 | updated_at: now, |
| 1520 | }); |
| 1521 | return pluginStorageEntryFromRow<T>(created); |
| 1522 | }); |
| 1523 | |
| 1524 | const removeImpl = (owner: Owner, collection: string, key: string) => |
| 1525 | Effect.gen(function* () { |
no test coverage detected