(owner: Owner, collection: string, key: string, data: unknown)
| 1236 | .pipe(Effect.map((row) => (row ? pluginStorageEntryFromRow<T>(row) : null))); |
| 1237 | |
| 1238 | const putImpl = <T>(owner: Owner, collection: string, key: string, data: unknown) => |
| 1239 | Effect.gen(function* () { |
| 1240 | const os = ownerSubject(owner); |
| 1241 | if (!os) { |
| 1242 | return yield* new StorageError({ |
| 1243 | message: `Cannot write plugin storage for owner "user": executor has no subject.`, |
| 1244 | cause: undefined, |
| 1245 | }); |
| 1246 | } |
| 1247 | const existing = yield* input.core.findFirst("plugin_storage", { |
| 1248 | where: whereOwner(owner, collection, key), |
| 1249 | }); |
| 1250 | const now = new Date(); |
| 1251 | if (existing) { |
| 1252 | yield* input.core.updateMany("plugin_storage", { |
| 1253 | where: whereOwner(owner, collection, key), |
| 1254 | set: { data, updated_at: now }, |
| 1255 | }); |
| 1256 | return pluginStorageEntryFromRow<T>({ |
| 1257 | ...existing, |
| 1258 | data, |
| 1259 | updated_at: now, |
| 1260 | }); |
| 1261 | } |
| 1262 | const created = yield* input.core.create("plugin_storage", { |
| 1263 | tenant, |
| 1264 | owner: os.owner, |
| 1265 | subject: os.subject, |
| 1266 | plugin_id: input.pluginId, |
| 1267 | collection, |
| 1268 | key, |
| 1269 | data, |
| 1270 | created_at: now, |
| 1271 | updated_at: now, |
| 1272 | }); |
| 1273 | return pluginStorageEntryFromRow<T>(created); |
| 1274 | }); |
| 1275 | |
| 1276 | const removeImpl = (owner: Owner, collection: string, key: string) => |
| 1277 | Effect.gen(function* () { |
no test coverage detected