(owner: Owner, collection: string, key: string, data: unknown)
| 959 | .pipe(Effect.map((row) => (row ? pluginStorageEntryFromRow<T>(row) : null))); |
| 960 | |
| 961 | const putImpl = <T>(owner: Owner, collection: string, key: string, data: unknown) => |
| 962 | Effect.gen(function* () { |
| 963 | const os = ownerSubject(owner); |
| 964 | if (!os) { |
| 965 | return yield* new StorageError({ |
| 966 | message: `Cannot write plugin storage for owner "user": executor has no subject.`, |
| 967 | cause: undefined, |
| 968 | }); |
| 969 | } |
| 970 | const existing = yield* input.core.findFirst("plugin_storage", { |
| 971 | where: whereOwner(owner, collection, key), |
| 972 | }); |
| 973 | const now = new Date(); |
| 974 | if (existing) { |
| 975 | yield* input.core.updateMany("plugin_storage", { |
| 976 | where: whereOwner(owner, collection, key), |
| 977 | set: { data, updated_at: now }, |
| 978 | }); |
| 979 | return pluginStorageEntryFromRow<T>({ |
| 980 | ...existing, |
| 981 | data, |
| 982 | updated_at: now, |
| 983 | }); |
| 984 | } |
| 985 | const created = yield* input.core.create("plugin_storage", { |
| 986 | tenant, |
| 987 | owner: os.owner, |
| 988 | subject: os.subject, |
| 989 | plugin_id: input.pluginId, |
| 990 | collection, |
| 991 | key, |
| 992 | data, |
| 993 | created_at: now, |
| 994 | updated_at: now, |
| 995 | }); |
| 996 | return pluginStorageEntryFromRow<T>(created); |
| 997 | }); |
| 998 | |
| 999 | const removeImpl = (owner: Owner, collection: string, key: string) => |
| 1000 | Effect.gen(function* () { |
no test coverage detected