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

Function assertOwnerPatch

packages/core/sdk/src/owner-policy.ts:179–195  ·  view source on GitHub ↗
(
  tableName: string,
  patch: Record<string, unknown> | undefined,
  context: ExecutorOwnerPolicyContext | undefined,
)

Source from the content-addressed store, hash-verified

177/** Assert a patch (`set`) doesn't move a row out of the bound partition. Only
178 * validates the partition columns that are actually being written. */
179export const assertOwnerPatch = (
180 tableName: string,
181 patch: Record<string, unknown> | undefined,
182 context: ExecutorOwnerPolicyContext | undefined,
183): void => {
184 const ctx = requireContext(tableName, "write", context);
185 assertReachReadOnly(tableName, "write", ctx);
186 if (!patch) return;
187 if (patch.tenant !== undefined && patch.tenant !== ctx.tenant) {
188 policyViolation(`Storage write on table "${tableName}" cannot move a row across tenants.`);
189 }
190 if (patch.owner === "user" && (ctx.subject == null || patch.subject !== ctx.subject)) {
191 policyViolation(
192 `Storage write on table "${tableName}" cannot move a row outside the bound subject.`,
193 );
194 }
195};
196
197export const hasExecutorOwnerPolicy = (table: AnyTable): boolean =>
198 table.policies.some((policy) => policy.name === executorOwnerPolicyName);

Callers 1

ownedExecutorTableFunction · 0.90

Calls 3

requireContextFunction · 0.85
assertReachReadOnlyFunction · 0.85
policyViolationFunction · 0.85

Tested by

no test coverage detected