( tableName: string, patch: Record<string, unknown> | undefined, context: ExecutorOwnerPolicyContext | undefined, )
| 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. */ |
| 179 | export 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 | |
| 197 | export const hasExecutorOwnerPolicy = (table: AnyTable): boolean => |
| 198 | table.policies.some((policy) => policy.name === executorOwnerPolicyName); |
no test coverage detected