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