(owner: Owner, collection: string, key: string, data: unknown)
| 1578 | .pipe(Effect.map((row) => (row ? pluginStorageEntryFromRow<T>(row) : null))); |
| 1579 | |
| 1580 | const putImpl = <T>(owner: Owner, collection: string, key: string, data: unknown) => |
| 1581 | Effect.gen(function* () { |
| 1582 | const os = ownerSubject(owner); |
| 1583 | if (!os) { |
| 1584 | return yield* new StorageError({ |
| 1585 | message: `Cannot write plugin storage for owner "user": executor has no subject.`, |
| 1586 | cause: undefined, |
| 1587 | }); |
| 1588 | } |
| 1589 | const existing = yield* input.core.findFirst("plugin_storage", { |
| 1590 | where: whereOwner(owner, collection, key), |
| 1591 | }); |
| 1592 | const now = new Date(); |
| 1593 | if (existing) { |
| 1594 | yield* input.core.updateMany("plugin_storage", { |
| 1595 | where: whereOwner(owner, collection, key), |
| 1596 | set: { data, updated_at: now }, |
| 1597 | }); |
| 1598 | return pluginStorageEntryFromRow<T>({ |
| 1599 | ...existing, |
| 1600 | data, |
| 1601 | updated_at: now, |
| 1602 | }); |
| 1603 | } |
| 1604 | const created = yield* input.core.create("plugin_storage", { |
| 1605 | tenant, |
| 1606 | owner: os.owner, |
| 1607 | subject: os.subject, |
| 1608 | plugin_id: input.pluginId, |
| 1609 | collection, |
| 1610 | key, |
| 1611 | data, |
| 1612 | created_at: now, |
| 1613 | updated_at: now, |
| 1614 | }); |
| 1615 | return pluginStorageEntryFromRow<T>(created); |
| 1616 | }); |
| 1617 | |
| 1618 | const removeImpl = (owner: Owner, collection: string, key: string) => |
| 1619 | Effect.gen(function* () { |
no test coverage detected