MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / putImpl

Function putImpl

packages/core/sdk/src/executor.ts:961–997  ·  view source on GitHub ↗
(owner: Owner, collection: string, key: string, data: unknown)

Source from the content-addressed store, hash-verified

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* () {

Callers 1

makePluginStorageFacadeFunction · 0.85

Calls 3

whereOwnerFunction · 0.85
ownerSubjectFunction · 0.70

Tested by

no test coverage detected