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

Function putManyImpl

packages/core/sdk/src/executor.ts:1057–1113  ·  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

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

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