(owner: Owner, collection: string, key: string, data: unknown)
| 1197 | .pipe(Effect.map((row) => (row ? pluginStorageEntryFromRow<T>(row) : null))); |
| 1198 | |
| 1199 | const putImpl = <T>(owner: Owner, collection: string, key: string, data: unknown) => |
| 1200 | Effect.gen(function* () { |
| 1201 | const os = ownerSubject(owner); |
| 1202 | if (!os) { |
| 1203 | return yield* new StorageError({ |
| 1204 | message: `Cannot write plugin storage for owner "user": executor has no subject.`, |
| 1205 | cause: undefined, |
| 1206 | }); |
| 1207 | } |
| 1208 | const existing = yield* input.core.findFirst("plugin_storage", { |
| 1209 | where: whereOwner(owner, collection, key), |
| 1210 | }); |
| 1211 | const now = new Date(); |
| 1212 | if (existing) { |
| 1213 | yield* input.core.updateMany("plugin_storage", { |
| 1214 | where: whereOwner(owner, collection, key), |
| 1215 | set: { data, updated_at: now }, |
| 1216 | }); |
| 1217 | return pluginStorageEntryFromRow<T>({ |
| 1218 | ...existing, |
| 1219 | data, |
| 1220 | updated_at: now, |
| 1221 | }); |
| 1222 | } |
| 1223 | const created = yield* input.core.create("plugin_storage", { |
| 1224 | tenant, |
| 1225 | owner: os.owner, |
| 1226 | subject: os.subject, |
| 1227 | plugin_id: input.pluginId, |
| 1228 | collection, |
| 1229 | key, |
| 1230 | data, |
| 1231 | created_at: now, |
| 1232 | updated_at: now, |
| 1233 | }); |
| 1234 | return pluginStorageEntryFromRow<T>(created); |
| 1235 | }); |
| 1236 | |
| 1237 | const removeImpl = (owner: Owner, collection: string, key: string) => |
| 1238 | Effect.gen(function* () { |
no test coverage detected