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