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

Function putManyImpl

packages/core/sdk/src/executor.ts:1056–1112  ·  view source on GitHub ↗
(
    owner: Owner,
    entries: readonly {
      readonly collection: string;
      readonly key: string;
      readonly data: unknown;
    }[],
  )

Source from the content-addressed store, hash-verified

1054 });
1055
1056 const putManyImpl = (
1057 owner: Owner,
1058 entries: readonly {
1059 readonly collection: string;
1060 readonly key: string;
1061 readonly data: unknown;
1062 }[],
1063 ) =>
1064 Effect.gen(function* () {
1065 const os = ownerSubject(owner);
1066 if (!os) {
1067 return yield* new StorageError({
1068 message: `Cannot write plugin storage for owner "user": executor has no subject.`,
1069 cause: undefined,
1070 });
1071 }
1072 const entriesById = new Map(
1073 entries.map((entry) => [
1074 pluginStorageId({
1075 pluginId: input.pluginId,
1076 collection: entry.collection,
1077 key: entry.key,
1078 }),
1079 entry,
1080 ]),
1081 );
1082 const uniqueEntries = [...entriesById.values()];
1083 if (uniqueEntries.length === 0) return;
1084
1085 yield* deleteManyImpl(owner, os.subject, uniqueEntries);
1086
1087 const now = new Date();
1088 for (
1089 let offset = 0;
1090 offset < uniqueEntries.length;
1091 offset += PLUGIN_STORAGE_CREATE_ROW_BATCH_SIZE
1092 ) {
1093 const batchEntries = uniqueEntries.slice(
1094 offset,
1095 offset + PLUGIN_STORAGE_CREATE_ROW_BATCH_SIZE,
1096 );
1097 yield* input.core.createMany(
1098 "plugin_storage",
1099 batchEntries.map((entry) => ({
1100 tenant,
1101 owner: os.owner,
1102 subject: os.subject,
1103 plugin_id: input.pluginId,
1104 collection: entry.collection,
1105 key: entry.key,
1106 data: entry.data,
1107 created_at: now,
1108 updated_at: now,
1109 })),
1110 );
1111 }
1112 });
1113

Callers 1

makePluginStorageFacadeFunction · 0.85

Calls 4

pluginStorageIdFunction · 0.90
deleteManyImplFunction · 0.85
valuesMethod · 0.80
ownerSubjectFunction · 0.70

Tested by

no test coverage detected